Compare commits

...

2 Commits

Author SHA1 Message Date
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
ea2383234f Add branch name validation configuration
- **Added** `.github/config.conf` for branch name prefixes configuration
- **Updated** `ValidateBranchName.yml` to read and utilize branch name prefixes from the config file
2024-08-23 21:28:22 +02:00
2 changed files with 22 additions and 3 deletions

2
.github/config.conf vendored Normal file
View File

@@ -0,0 +1,2 @@
[branch_validation]
valid_prefixes = feature/,fix/,refactoring/,testing/,dependabot/,gh-pages

View File

@@ -4,6 +4,7 @@ on:
pull_request: pull_request:
branches: branches:
- main - main
workflow_dispatch: # Allows manual execution of the workflow.
jobs: jobs:
validate-branch-name-on-pull-request: validate-branch-name-on-pull-request:
@@ -13,11 +14,27 @@ jobs:
- name: Check out repository - name: Check out repository
uses: actions/checkout@v2 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 - name: Validate Branch Name on Pull Request
run: | run: |
BRANCH_NAME=${GITHUB_HEAD_REF} BRANCH_NAME=${{ github.head_ref }}
if [[ ! "$BRANCH_NAME" =~ ^(feature\/|fix\/|refactoring\/|testing\/|dependabot\/|gh-pages) ]]; then 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 "Invalid branch name: $BRANCH_NAME"
echo "Branch name must start with 'feature/', 'fix/', 'refactoring/', 'testing/', dependabot/" or "gh-pages" echo "Branch name must start with one of the following prefixes: $VALID_PREFIXES"
exit 1 exit 1
fi fi