-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (78 loc) · 2.85 KB
/
pr-checks.yml
File metadata and controls
95 lines (78 loc) · 2.85 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: PR Checks
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
jobs:
pr-validation:
name: PR Validation
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate PR title
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
# Check if PR title is not empty
if [ -z "$PR_TITLE" ]; then
echo "❌ PR title cannot be empty"
exit 1
fi
# Check minimum length
if [ ${#PR_TITLE} -lt 10 ]; then
echo "❌ PR title is too short (minimum 10 characters)"
exit 1
fi
echo "✅ PR title is valid"
- name: Check PR description
run: |
# Use heredoc to safely capture PR body without shell interpretation
PR_BODY=$(cat << 'EOF'
${{ github.event.pull_request.body }}
EOF
)
if [ -z "$PR_BODY" ] || [ "$PR_BODY" == "null" ]; then
echo "⚠️ PR description is empty. Consider adding a description."
echo "description=empty" >> $GITHUB_OUTPUT
else
echo "✅ PR has a description"
echo "description=present" >> $GITHUB_OUTPUT
fi
- name: Check for linked issues
run: |
# Use heredoc to safely capture PR body without shell interpretation
PR_BODY=$(cat << 'EOF'
${{ github.event.pull_request.body }}
EOF
)
if echo "${PR_BODY}" | grep -iE "(closes|fixes|resolves) #[0-9]+"; then
echo "✅ PR links to an issue"
else
echo "ℹ️ No linked issues found. Consider linking related issues."
fi
- name: Verify base branch
run: |
BASE_BRANCH="${{ github.event.pull_request.base.ref }}"
if [ "$BASE_BRANCH" != "main" ]; then
echo "⚠️ PR is targeting '$BASE_BRANCH' instead of 'main'"
else
echo "✅ PR is targeting main branch"
fi
- name: Check for merge conflicts
run: |
if [ "${{ github.event.pull_request.mergeable }}" == "false" ]; then
echo "❌ PR has merge conflicts that need to be resolved"
exit 1
else
echo "✅ No merge conflicts detected"
fi
prevent-force-push:
name: Prevent Force Push to Main
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Check for force push
run: |
echo "This workflow helps prevent direct pushes to main"
echo "All changes must go through PRs"
echo "✅ PR process is being followed"