Branch Naming Policy #35
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 Naming Policy | |
on: | |
create: | |
pull_request: | |
branches: | |
- master | |
types: | |
- opened | |
- reopened | |
jobs: | |
branch-naming-policy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Extract branch name | |
shell: bash | |
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | |
id: extract_branch | |
- name: Branch naming policy check | |
run: | | |
echo "${{ steps.extract_branch.outputs.branch }}" | |
[[ "${{ steps.extract_branch.outputs.branch }}" =~ ^[a-z0-9_]{5,50}$ ]] || exit 1 | |
- name: Close pull request and delete branch | |
if: failure() | |
env: | |
PR_NUMBER: ${{ github.event.number }} | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
gh pr close "$PR_NUMBER" -c "Pull request has been closed due the breach of branch naming policy" -d |