import issue fix #97
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 and PR Name Validation | |
on: | |
push: | |
branches: | |
- master | |
- develop | |
- console | |
pull_request: | |
branches: | |
- master | |
- develop | |
- console | |
jobs: | |
validate-names: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Validate branch name | |
if: ${{ github.event_name != 'pull_request' }} # Skip for PR validation | |
run: | | |
# Define constants | |
PREFIXES="FEATURE|BUGFIX|RELEASE" | |
SYSTEMS="HCMPRE|DPG|SN" | |
TICKET_PATTERN="[0-9]{1,5}" | |
BRANCH_PATTERN="^($PREFIXES)\/($SYSTEMS)-$TICKET_PATTERN$" | |
# Determine the branch name | |
branch_name="${GITHUB_REF#refs/heads/}" | |
# Validate the branch name | |
if [[ ! "$branch_name" =~ $BRANCH_PATTERN ]]; then | |
echo "Branch name '$branch_name' does not follow the correct pattern: $PREFIXES/$SYSTEMS-<TICKET_NO> where <TICKET_NO> is $TICKET_PATTERN" | |
exit 1 | |
fi | |
- name: Validate PR title | |
if: ${{ github.event_name == 'pull_request' }} # Only for PR validation | |
run: | | |
# Define constants | |
PREFIXES="FEATURE|BUGFIX|RELEASE" | |
SYSTEMS="HCMPRE|DPG|SN" | |
TICKET_PATTERN="[0-9]{1,5}" | |
TITLE_PATTERN="^($PREFIXES)\/($SYSTEMS)-$TICKET_PATTERN: .+$" | |
# Get the PR title | |
pr_title="${{ github.event.pull_request.title }}" | |
# Validate the PR title | |
if [[ ! "$pr_title" =~ $TITLE_PATTERN ]]; then | |
echo "PR title '$pr_title' does not follow the correct pattern: $PREFIXES/$SYSTEMS-<TICKET_NO>: <Description> where <TICKET_NO> is $TICKET_PATTERN" | |
exit 1 | |
fi |