A GitHub action to check whether a merge group PR is up to date relative to its base branch
Often, GitHub workflows are configured to run the same jobs (e.g., tests) on both pull_request
and merge_group
events. But if a PR is based on the head of it base branch and the tests pass on the pull_request
event, there should be no need to rerun the tests on the merge_group
event.
This action can be used to determine whether a PR is based on the head of its base branch and thus whether expensive jobs can be skipped.
- Add a job like the following to your GitHub workflow:
check-up-to-dateness: outputs: is-up-to-date: ${{ steps.main.outputs.is-up-to-date }} runs-on: ubuntu-latest steps: - id: main uses: trailofbits/check-up-to-dateness@main
- For any job you want to skip when merging, add the following:
my-job: needs: [check-up-to-dateness] if: needs.check-up-to-dateness.outputs.is-up-to-date != 'true'
- Under "Settings" -> "Branches" -> "Branch protection rules" -> "Require status checks to pass before merging" -> "Status checks that are required", add the job that you created in step 1, e.g.:
This final step ensures that if an error occurs incheck-up-to-dateness
, it will not cause a PR to be merged.