Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions .github/workflows/branch-protection-warning.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
name: "Check if merging to 'main' from 'release' branch"

on:
pull_request:
branches: # These should be primary branch names.
- main
- master
workflow_call:
inputs:
primary_branch:
description: 'The name of the primary branch this workflow will run on.'
required: false
type: string
default: 'main'

permissions:
contents: read

jobs:
protect-primary-branch:
runs-on: ubuntu-latest
protect-primary-branch:
runs-on: ubuntu-latest

# To prevent a merge on failure, branch protection must be enabled in GitHub. If branch
# protection is disabled, this will fail with a red X but nothing prevents you from merging
# anyway.
steps:
- name: Check merge branch
if: github.event.pull_request.base.ref == 'main'
run: |
if [ "${{ github.event.pull_request.head.ref }}" != "release" ]; then
echo "Merges to 'main' are only allowed from the 'release' branch."
exit 1
fi
# To prevent a merge on failure, branch protection must be enabled in GitHub. If branch
# protection is disabled, this will fail with a red X but nothing prevents you from merging
# anyway.
steps:
- name: Check merge branch
if: github.event.pull_request.base.ref == ${{ inputs.primary_branch }}
run: |
if [ "${{ github.event.pull_request.head.ref }}" != "release" ]; then
echo "Merges to '${{ inputs.primary_branch }}' are only allowed from the 'release' branch."
exit 1
fi
echo "Success!"