Skip to content

Instantly share code, notes, and snippets.

@ChrisMBarr
Last active February 21, 2024 16:45
Show Gist options
  • Save ChrisMBarr/dcdbc18812964efb1db5c342c0fbaea1 to your computer and use it in GitHub Desktop.
Save ChrisMBarr/dcdbc18812964efb1db5c342c0fbaea1 to your computer and use it in GitHub Desktop.
Check Pull Request
name: Pull Request Branch Naming Conventions
on:
pull_request:
jobs:
check-branch-name:
runs-on: ubuntu-latest
steps:
- name: Check if Pull Request branch name is formatted correctly
run: |
pr_branch_name=${GITHUB_HEAD_REF}
base_branch_name=${GITHUB_BASE_REF}
line="-----------------------------------------------------"
dev_regex="^(bug|feature|code-cleanup)/(DTD|DDTT)-[0-9]+-.+$"
qa_regex="^kickback/(DTD|DDTT)-[0-9]+-.+$"
prod_regex="^hotfix/(DTD|DDTT)-[0-9]+-.+$"
echo $line
echo "PR branch name: $pr_branch_name"
echo "Base branch: $base_branch_name"
echo $line
if [[ "$pr_branch_name" =~ $prod_regex ]]; then
if [[ "$base_branch_name" != "prod" ]]; then
#Make sure a hotfix is only applied to the prod branch
echo "Branch is named as a HOTFIX but the PR is not based against the 'prod' branch!"
echo $line
exit 1
fi
echo "Your branch is properly named, well done!"
echo $line
elif [[ "$pr_branch_name" =~ $qa_regex ]]; then
if [[ "$base_branch_name" != "qa" ]]; then
#Make sure a kickback is only applied to the QA branch
echo "Branch is named as a KICKBACK but the PR is not based against the 'qa' branch!"
echo $line
exit 1
fi
echo "Your branch is properly named, well done!"
echo $line
elif [[ "$pr_branch_name" =~ $dev_regex ]]; then
if [[ "$base_branch_name" != "dev" ]]; then
#Make sure a development thing is only applied to the dev branch
echo "Branch is named as if it is mean for development but the PR is not based against the 'dev' branch!"
echo $line
exit 1
fi
echo "Your branch is properly named, well done!"
echo $line
else
echo "Branch name does not match any known pattern!"
echo "Allowed patterns are as follows:"
echo " - For the 'dev' branch: $dev_regex"
echo " - For the 'qa' branch: $qa_regex"
echo " - For the 'prod' branch: $prod_regex"
echo $line
exit 1
fi
shell: bash
name: Pull Request Sanity Check
on:
pull_request:
paths-ignore: [".vscode/**", "README.md", ".*"]
permissions:
contents: write
jobs:
pr-sanity-check:
concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
runs-on: ubuntu-latest
steps:
- name: Checkout ⏬
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Node.js version 💻
uses: actions/setup-node@v3
with:
node-version: "20.x"
- name: Install Packages 📦
run: npm ci
- name: Build 🛠️
run: npm run build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment