infra: code freeze workflow #1
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: Code Freeze | |
on: | |
pull_request: | |
branches: | |
- main | |
env: | |
FROZEN: "false" # Set to "true" to freeze branches, "false" otherwise | |
FEATURE_NAME: "" # Set your feature prefix here (leave empty to allow all feature branches) | |
jobs: | |
check-branch-name-and-title: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Fetch PR title and check conditions | |
if: env.FROZEN == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
PR_DATA=$(curl -s \ | |
-H "Authorization: Bearer $GITHUB_TOKEN" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}) | |
BRANCH_NAME=$(echo $PR_DATA | jq .head.ref -r) | |
PR_TITLE=$(echo $PR_DATA | jq .title -r) | |
echo $BRANCH_NAME | |
echo $PR_TITLE | |
if [[ "$BRANCH_NAME" != feature/$FEATURE_NAME* ]] && | |
[[ "$PR_TITLE" != fix:* && "$PR_TITLE" != *"[critical]"* ]]; then | |
echo "Error: You can only merge from branches that start with 'feature/$FEATURE_NAME', or PRs titled with 'fix: ' and containing '[critical]'." | |
exit 1 | |
fi |