-
Notifications
You must be signed in to change notification settings - Fork 2
74 lines (61 loc) · 2.47 KB
/
Copy pathpr-validation-workflow.yaml
File metadata and controls
74 lines (61 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Pull Request Validations
on:
pull_request:
types: [opened, edited, synchronize, reopened, ready_for_review]
branches: [main, dev]
permissions:
pull-requests: read
contents: read
jobs:
validate-merge-permissions:
if: github.event.pull_request.base.ref == 'main'
runs-on: ubuntu-latest
name: Validate Merge Permissions
steps:
- name: Verify Authorized User
run: |
TARGET_BRANCH="${{ github.event.pull_request.base.ref }}"
PR_AUTHOR="${{ github.actor }}"
ALLOWED_USER="AhmedSobhy01"
if [ "$PR_AUTHOR" != "$ALLOWED_USER" ] && [ "$TARGET_BRANCH" = "main" ]; then
echo "Unauthorized PR to main by $PR_AUTHOR, only $ALLOWED_USER is allowed."
exit 1
fi
echo "Authorized PR to main branch."
branch-name-validation:
if: github.event.pull_request.base.ref == 'dev'
name: Validate branch naming convention
runs-on: ubuntu-latest
steps:
- name: Enforce kebab-case branch name
env:
BRANCH_NAME: ${{ github.head_ref }}
BRANCH_PATTERN: '^(feat|fix|build|chore|refactor|docs|perf|test)/[a-z0-9]+(-[a-z0-9]+)*$'
run: |
echo "Checking branch: $BRANCH_NAME"
if ! echo "$BRANCH_NAME" | grep -Eq "$BRANCH_PATTERN"; then
echo "Branch name doesn't match the required pattern. Please setup your git hooks locally to avoid this error."
exit 1
fi
echo "Branch name passed."
validate-pr-title:
name: Validate PR title format
runs-on: ubuntu-latest
steps:
- name: Check PR title format
env:
PR_TITLE: ${{github.event.pull_request.title}}
PREFIX_PATTERN: '^(feat|fix|build|chore|refactor|docs|perf|test)(\(.+\))?: .+'
POSTFIX_PATTERN: " - \\[CU-[a-zA-Z0-9]+\\]$"
run: |
CLEAN_TITLE=$(echo "$PR_TITLE" | tr -d '\r' | sed 's/[[:space:]]\+/ /g' | sed 's/^ *//;s/ *$//') # Normalize spaces
echo "Checking PR title: $CLEAN_TITLE"
if ! echo "$CLEAN_TITLE" | grep -Eq "$PREFIX_PATTERN"; then
echo "PR title must start with a valid prefix (feat, fix, build, chore, refactor, docs, perf, test) followed by a colon and a space."
exit 1
fi
if ! echo "$CLEAN_TITLE" | grep -Eq "$POSTFIX_PATTERN"; then
echo "PR title must end with a valid Clickup PR ticket. (e.g., ' - [CU-1234]')"
exit 1
fi
echo "PR title passed."