Skip to content

Commit

Permalink
Merge pull request #25 from bnb-chain/cicd
Browse files Browse the repository at this point in the history
chore: Get pr env
  • Loading branch information
wenty22 authored Oct 21, 2024
2 parents b3eb43b + c29d19f commit 9ed45e5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
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

0 comments on commit 9ed45e5

Please sign in to comment.