Update branch-restriction.yaml #4
Workflow file for this run
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
name: Branch Restriction | |
on: | |
create: | |
branches: | |
- '*' | |
push: | |
branches: | |
- '*' | |
jobs: | |
restrict-branch-creation: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check branch creation | |
env: | |
BRANCH_NAME: ${{ github.ref_name }} | |
SOURCE_BRANCH: ${{ github.event.before }} | |
run: | | |
ALLOWED_BRANCHES=("main" "develop") | |
for branch in "${ALLOWED_BRANCHES[@]}"; do | |
if [[ "$SOURCE_BRANCH" == *"$branch" ]]; then | |
exit 0 | |
fi | |
done | |
echo "Branch creation from $SOURCE_BRANCH is not allowed." | |
echo "Allowed branches are: ${ALLOWED_BRANCHES[@]}" | |
echo "Branch name: $BRANCH_NAME" | |
exit 1 |