I have a GitHub repository with a branch named feature1 that contains 10 commits. A pull request (PR) has been raised to merge feature1 into the stage branch. Once the PR is merged, I want a GitHub Actions pipeline to run and list all commit hashes that were present in the feature1 branch.
I attempted to use the following code to achieve this, but it is displaying incorrect commit hashes, which do not match those in the feature1 branch
Could someone help me correct this approach? How can I accurately retrieve all commit hashes from feature1 after the PR has been merged to stage?
name: stage deployment Workflow
on:
push:
branches:
- stage
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: List commits in PR
id: list-commits
env:
GH_TOKEN: ${{ secrets.TOKEN_GITHUB }}
run: |
pr_number=${{ github.event.pull_request.number }}
commits=$(gh pr view $pr_number --json commits --jq '.commits[].oid')
echo "Commit hashes from stage branch:"
echo "$commits"
echo "$commits" > commit-hashes.txt
- name: Save commits to artifact
uses: actions/upload-artifact@v4
with:
name: commit-hashes
path: commit-hashes.txt