-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: branch protection | ||
# This workflow is triggered on PRs to master branch on the repository | ||
# It fails when someone tries to make a PR against the `master` branch instead of `dev` | ||
on: | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# PRs to the repo master branch are only ok if coming from the repo `dev` or any `patch` branches | ||
- name: Check PRs | ||
if: github.repository == 'phac-nml/biohansel' | ||
run: | | ||
{ [[ ${{github.event.pull_request.head.repo.full_name}} == phac-nml/biohansel ]] && [[ $GITHUB_HEAD_REF = "development" ]]; } || [[ $GITHUB_HEAD_REF == "patch" ]] | ||
# If the above check failed, post a comment on the PR explaining the failure | ||
# NOTE - this doesn't currently work if the PR is coming from a fork, due to limitations in GitHub actions secrets | ||
- name: Post PR comment | ||
if: failure() | ||
uses: mshick/add-pr-comment@v1 | ||
with: | ||
message: | | ||
Hi @${{ github.event.pull_request.user.login }}, | ||
It looks like this pull-request is has been made against the ${{github.event.pull_request.head.repo.full_name}} `master` branch. | ||
The `master` branch on repositories should always contain code from the latest release. | ||
Because of this, PRs to `master` are only allowed if they come from the ${{github.event.pull_request.head.repo.full_name}} `development` branch. | ||
You do not need to close this PR, you can change the target branch to `development` by clicking the _"Edit"_ button at the top of this page. | ||
Thanks again for your contribution! | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
allow-repeats: false |