From 5a6955a04af05dbb60ed8aad2f4935f89ff55b06 Mon Sep 17 00:00:00 2001 From: wenty22 Date: Mon, 21 Oct 2024 15:36:49 +0800 Subject: [PATCH] chore: Get pr env --- .github/actions/get-pr-env/action.yaml | 40 ++++++++++++++++++++++++++ .github/workflows/gh-pages-cicd.yaml | 10 +++++-- 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 .github/actions/get-pr-env/action.yaml diff --git a/.github/actions/get-pr-env/action.yaml b/.github/actions/get-pr-env/action.yaml new file mode 100644 index 00000000..dffb14a6 --- /dev/null +++ b/.github/actions/get-pr-env/action.yaml @@ -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 diff --git a/.github/workflows/gh-pages-cicd.yaml b/.github/workflows/gh-pages-cicd.yaml index df2520a1..6d749c7b 100644 --- a/.github/workflows/gh-pages-cicd.yaml +++ b/.github/workflows/gh-pages-cicd.yaml @@ -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.sha }} + 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: |