Skip to content

Commit

Permalink
Add branch protection rule
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelirh committed Jun 6, 2024
1 parent b992438 commit 20a6057
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/protect-default-branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Validate PR head branch
on:
pull_request:
types:
- opened
branches:
- ros2

jobs:
check-head-branch:
runs-on: ubuntu-latest
steps:
- name: Check allowed branches
run: |
pattern="^[0-9]+\.[0-9]+\.[0-9]+-[0-9]{8}$" # This regex matches the X.X.X-YYYYMMDD pattern
if [[ "${{ github.head_ref }}" == *"hotfix"* ]]; then
echo "PR from a branch containing 'hotfix' is allowed."
exit 0
elif [[ "${{ github.head_ref }}" =~ $pattern ]]; then
echo "PR from a branch matching X.X.X-YYYYMMDD pattern is allowed."
exit 0
else
echo "PRs must come from branches containing 'hotfix' phrase or matching X.X.X-YYYYMMDD pattern."
exit 1
fi

0 comments on commit 20a6057

Please sign in to comment.