Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Get pr env #25

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/actions/get-pr-env/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 'get-pr'
description: Get the pr env variables

runs:
using: composite
outputs:
GIT_REPOSITORY: ${{ steps.get-pr-env.outputs.GIT_REPOSITORY }}
PR_NUMBER: ${{ steps.get-pr-env.outputs.PR_NUMBER }}
LATEST_COMMIT_SHA: ${{ steps.get-pr-env.outputs.LATEST_COMMIT_SHA }}
BRANCH_NAME: ${{ steps.get-pr-env.outputs.BRANCH_NAME }}
steps:
- uses: actions/github-script@v3
id: get-pr
with:
script: |
const request = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
}
core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`)
try {
const result = await github.pulls.get(request)
return result.data
} catch (err) {
core.setFailed(`Request failed with error ${err}`)
}

- name: get pr env
id: get-pr-env
run: |
GIT_REPOSITORY=${{ fromJSON(steps.get-pr.outputs.result).head.repo.full_name }}
PR_NUMBER=${{ fromJSON(steps.get-pr.outputs.result).number }}
LATEST_COMMIT_SHA=${{ fromJSON(steps.get-pr.outputs.result).head.sha }}
BRANCH_NAME=${{ fromJSON(steps.get-pr.outputs.result).head.ref }}

echo "GIT_REPOSITORY=${GIT_REPOSITORY}" >> $GITHUB_OUTPUT
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "LATEST_COMMIT_SHA=${LATEST_COMMIT_SHA}" >> $GITHUB_OUTPUT
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT
10 changes: 8 additions & 2 deletions .github/workflows/gh-pages-cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ jobs:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: ./.github/actions/get-pr-env
id: pr-env

- name: Checkout code repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
ref: ${{ steps.pr-env.outputs.BRANCH_NAME }}
token: ${{ secrets.GITHUB_TOKEN }}

- uses: ./.github/actions/setup

- name: Log
run: |
echo "${{steps.pr-env.outputs.BRANCH_NAME}}"

- name: Creating .env
shell: bash
run: |
Expand Down
Loading