I'm trying to run some code in a GitHub Action that depends on files that were merged in to our develop branch. I can't seem to find the right environment variables or event values to get the diff of the pull request after it has been merged. I have tried running this on push to the develop branch as well as on a pull request with type: closed and a conditional on whether the pull request was merged.
Here are two things I've tried:
closed pull request:
name: test_pr_action
on:
pull_request:
types:
- closed
jobs:
job1:
if: github.event.pull_request.merged == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: one step
run: |
git fetch origin $GITHUB_BASE_REF --depth=1
git diff --diff-filter=AM --name-only ${{ github.event.base.sha }} ${{ github.event.head.sha }}
For the pull request, the step runs but does not pick up the SHAs so does not output anything.
push:
name: test_pr_action
on:
push:
branches:
- main
jobs:
job1:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: one step
run: |
git fetch origin $GITHUB_BASE_REF --depth=1
git diff --diff-filter=AM --name-only ${{ github.event.before }} ${{ github.event.after }}
For the push, the step fails because it doesn't like the first SHA.
I already have actions that run on push and on pull request BEFORE merge, so I have used these values before, but can't get it to work for this case.
Any advice helps! Thanks!