I am using [github-actions]. I have two worksflows:
- triggered on
pull_request
- triggered on
push
on:
workflow_dispatch:
pull_request:
branches:
- master
on:
workflow_dispatch:
push:
branches:
- master
The pull_request
workflow generates assets that need be used in push
workflow. I need some sort of an identifier that would allow me to connect the two workflows, ideally SHA of git merge commit. However, I was not able to identify a reliable reference to use.
At the moment I am using ${{ github.event.pull_request.head.sha }}
in pull_request
workflow, and in push
workflow I am using:
- name: Setup repository
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Set CI_COMMIT_SHORT_SHA env property
shell: bash
run: echo "CI_COMMIT_SHORT_SHA=$(git rev-parse --short=8 HEAD^2)" >> $GITHUB_ENV
This works most of the time but breaks when commits are force pushed to the PR branch before it is merged.
What is a reliable git reference to associate pull_request
with push
workflows?
CodePudding user response:
If you're looking to trigger the second workflow only on a PR merge to master, you could use the pull_request.closed
event. From within that workflow, $GITHUB_REF
should get you the reference to the PR merge branch (refs/pull/:prNumber/merge). Would that work for you to tie the two workflows together?
on:
pull_request:
branches:
- master
types: [closed]
Also, note that to ignore closed PRs that weren't merged, you'll need to add a condition in your job to skip it in that case: if: github.event.pull_request.merged == true