Skip to content

Commit

Permalink
Fix wrong branch checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
Bassem Dghaidi committed Dec 4, 2021
1 parent 32fb7c3 commit 8f48be0
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,44 @@ jobs:

steps:

# ======================================================
# Checkout the repository
# ======================================================
- uses: actions/checkout@v2
name: 'Checkout repository'

# ======================================================
# It's important to check that the PR number
# provided as input is valid and belongs to
# the repository.
#
# This will also return the PR's branch as an output
# which can be fetched in next steps via:
# ${{ steps.verify_pr_number.outputs.result }}
# ======================================================
- name: Verify Pull Request Number
uses: actions/github-script@v5
id: verify_pr_number
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const response = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ github.event.inputs.PR_number }}
})
});
// Check if the pull request is open
if (response.data.number !== ${{ github.event.inputs.PR_number }}) {
throw new Error('Pull request is not open or number is not valid!')
throw new Error('Pull request is not open or number is not valid!');
} else {
console.log(\`PR ref: ${response.data.head.ref}\`);
return response.data.head.ref;
}
# ======================================================
# Checkout the repository
# ======================================================
- uses: actions/checkout@v2
name: 'Checkout repository'
with:
ref: ${{ steps.verify_pr_number.outputs.result }}

# ======================================================
# Terraform setup
#
Expand Down

0 comments on commit 8f48be0

Please sign in to comment.