Files
TSinjex/.github/workflows/ValidateBranchName.yml
Max P 7feb0fc694 Add manual trigger to ValidateBranchName workflow
- Included `workflow_dispatch` event in GitHub Actions
- Allows for manual execution of the ValidateBranchName workflow
2024-08-23 21:29:14 +02:00

41 lines
1.3 KiB
YAML

name: Validate Branch Name on Pull Request
on:
pull_request:
branches:
- main
workflow_dispatch: # Allows manual execution of the workflow.
jobs:
validate-branch-name-on-pull-request:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Read Config File
id: config
run: |
VALID_PREFIXES=$(grep 'valid_prefixes' .github/config.conf | cut -d '=' -f2 | tr -d ' ')
echo "VALID_PREFIXES=$VALID_PREFIXES" >> $GITHUB_ENV
- name: Validate Branch Name on Pull Request
run: |
BRANCH_NAME=${{ github.head_ref }}
VALID_PREFIXES_ARRAY=(${VALID_PREFIXES//,/ })
VALID=false
for PREFIX in "${VALID_PREFIXES_ARRAY[@]}"; do
if [[ "$BRANCH_NAME" =~ ^$PREFIX ]]; then
VALID=true
break
fi
done
if [ "$VALID" = false ]; then
echo "Invalid branch name: $BRANCH_NAME"
echo "Branch name must start with one of the following prefixes: $VALID_PREFIXES"
exit 1
fi