forked from telekom-mms/eth-valctl
-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (113 loc) · 4.67 KB
/
Copy pathpre-commit.yaml
File metadata and controls
121 lines (113 loc) · 4.67 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
---
name: "Pre-commit Validation"
# yamllint disable-line rule:truthy
on:
push:
branches:
- "develop"
- "feature/*"
- "hotfix/*"
pull_request:
branches:
- "main"
jobs:
validate-pre-commit:
name: "Run pre-commit hooks"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout"
uses: "actions/checkout@v6"
with:
fetch-depth: 0
- name: "Setup Python"
uses: "actions/setup-python@v6"
with:
python-version: "3.13"
- name: "Cache pre-commit environments"
uses: "actions/cache@v5"
with:
path: "~/.cache/pre-commit"
key: "pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}"
restore-keys: |
pre-commit-
- name: "Install pre-commit"
run: "pip install pre-commit"
- name: "Validate pre-commit configuration"
run: |
echo "🔍 Validating pre-commit configuration..."
pre-commit validate-config
echo "✅ Pre-commit configuration is valid"
- name: "Run pre-commit validation"
run: |
if [ "${{ github.event_name }}" = "push" ]; then
echo "🔍 Validating pushed commits..."
BEFORE_SHA="${{ github.event.before }}"
if [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
echo "New branch detected, validating latest commit"
pre-commit run \
--config .pre-commit/.pre-commit-config.yaml \
--from-ref HEAD~1 --to-ref HEAD --show-diff-on-failure
elif ! git cat-file -e "$BEFORE_SHA" 2>/dev/null; then
echo "⚠️ Previous commit $BEFORE_SHA not found (force push detected)"
echo "Falling back to validating latest commit only"
pre-commit run \
--config .pre-commit/.pre-commit-config.yaml \
--from-ref HEAD~1 --to-ref HEAD --show-diff-on-failure
else
echo "Validating commits: $BEFORE_SHA..${{ github.event.after }}"
pre-commit run \
--config .pre-commit/.pre-commit-config.yaml \
--from-ref "$BEFORE_SHA" \
--to-ref ${{ github.event.after }} \
--show-diff-on-failure
fi
else
echo "🔍 Validating PR commits to main..."
echo "Validating PR commits: \
${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}"
pre-commit run \
--config .pre-commit/.pre-commit-config.yaml \
--from-ref ${{ github.event.pull_request.base.sha }} \
--to-ref ${{ github.event.pull_request.head.sha }} \
--show-diff-on-failure
fi
- name: "Show validation help on failure"
if: "failure()"
run: |
echo "❌ Pre-commit validation failed!"
echo ""
if [ "${{ github.event_name }}" = "push" ]; then
echo "🚨 Push to develop failed validation!"
echo "This prevents properly formatted commits from being cherry-picked to releases."
echo ""
echo "🔧 To fix the squashed commit to develop:"
echo " 1. Check the validation errors above"
echo " 2. Use 'git commit --amend' to fix the commit message"
echo " 3. Force push: 'git push --force-with-lease'"
echo ""
echo "⚠️ Note: Since this is develop, semantic-release won't run"
echo " But these commits will be cherry-picked to release branches!"
else
echo "🚨 Release PR validation failed!"
echo "This blocks semantic-release from running and creating releases."
echo ""
echo "🔧 To fix the release PR:"
echo " 1. Check the validation errors above"
echo " 2. Fix commit messages in the release branch"
echo " 3. Push updates to the release branch"
echo ""
echo "⚠️ Semantic-release will NOT run until validation passes!"
fi
echo ""
echo "📝 Required format: <type>(<scope>): <description>"
echo "Valid types: feat, fix, docs, style, refactor, perf, test, build, ci, chore"
echo ""
echo "Examples:"
echo " feat(auth): add user authentication system"
echo " fix(docker): resolve container startup issue"
echo " ci(release): add automated release workflow"
echo ""
echo "💡 Set up local pre-commit hooks for immediate feedback:"
echo " pip install pre-commit && pre-commit install"
exit 1
...