Skip to content

Commit

Permalink
Added and testing Actions workflow to only accept PR from staging branch
Browse files Browse the repository at this point in the history
Added and testing Actions workflow to only accept PR from staging branch
  • Loading branch information
AlisterBaroi authored Dec 20, 2023
2 parents 78ffb3b + 3c2bdcf commit b40771d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Enforce Pull Request Source Branch

on:
pull_request:
branches:
- main

jobs:
enforce-branch-protection:
runs-on: ubuntu-latest

steps:
- name: Check branch source
if: github.event_name == 'pull_request'
run: |
FROM_BRANCH=$(jq -r '.pull_request.base.ref' "$GITHUB_EVENT_PATH")
SOURCE_BRANCH=$(jq -r '.pull_request.head.ref' "$GITHUB_EVENT_PATH")
if [ "$FROM_BRANCH" != "main" ] || [ "$SOURCE_BRANCH" != "staging" ]; then
echo "Pull requests to 'main' must come from 'staging'."
exit 1
fi
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Create new branch from `main` branch, work on the code, and PR to `staging` bran
B[new-branch] -- 2. PR to staging --> C[staging];
```

asd

0 comments on commit b40771d

Please sign in to comment.