-
Notifications
You must be signed in to change notification settings - Fork 1
35 lines (29 loc) · 1.38 KB
/
branch.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 `main` branch instead of `dev`
on:
pull_request_target:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check PRs
if: github.repository == 'phac-nml/profile_dists'
run: |
{ [[ ${{github.event.pull_request.head.repo.full_name }} == phac-nml/profile_dists]] && [[ $GITHUB_HEAD_REF == "dev" ]]; } || [[ $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@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2
with:
message: |
## This PR is against the `main` branch :x:
* Do not close this PR
* Click _Edit_ and change the `base` to `dev`
* This CI test will remain failed until you push a new commit
---
Hello @${{ github.event.pull_request.user.login }}, This pull request is being made against the main branch, Please change your PR to be to the dev branch.
repo-token: ${{ secrets.GITHUB_TOKEN }}
allow-repeats: false