-
Notifications
You must be signed in to change notification settings - Fork 2
137 lines (114 loc) · 4.44 KB
/
pre-commit.yaml
File metadata and controls
137 lines (114 loc) · 4.44 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Pre-Commit Checks
on:
push:
branches:
- main
- develop
- 'feat/**'
- 'feature/**'
- 'test/**'
- 'chore/**'
- 'fix/**'
- 'hotfix/**'
- 'docs/**'
pull_request:
types: [opened, synchronize, reopened]
jobs:
precommit:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: Install goimports
run: |
go install golang.org/x/tools/cmd/goimports@latest
echo "$HOME/go/bin" >> $GITHUB_PATH
- name: Add Go bin to PATH
run: echo "$HOME/go/bin" >> $GITHUB_PATH
- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports@latest
- name: Install golangci-lint v2.7.2
run: |
curl -sSL https://github.com/golangci/golangci-lint/releases/download/v2.7.2/golangci-lint-2.7.2-linux-amd64.tar.gz \
| tar -xz -C $HOME/go/bin --strip-components=1
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install pre-commit
run: |
python -m pip install --upgrade pip
pip install pre-commit
- name: Load Pre-commit Config
run: |
if [ ! -f ".pre-commit-config.yaml" ]; then
echo " No .pre-commit-config.yaml found — downloading BerryBytes global config..."
curl -sSL \
https://raw.githubusercontent.com/BerryBytes/precommit-util/main/global/precommitFile/.pre-commit-config.yaml \
-o .pre-commit-config.yaml
else
echo "✔ Using project's existing .pre-commit-config.yaml"
fi
- name: Inject temporary Stylelint config for CI
run: |
if [ ! -f ".stylelintrc.json" ]; then
echo " Creating temporary .stylelintrc.json for CI..."
cat <<EOF > .stylelintrc.json
{
"extends": "stylelint-config-standard",
"rules": {
"no-duplicate-selectors": true,
"color-hex-length": "short",
"selector-no-qualifying-type": true,
"selector-max-id": 0
}
}
EOF
else
echo "✔ .stylelintrc.json already exists — skipping"
fi
# --------------------------------------------------------------------
# STEP 1: Run pre-commit (capture full logs and exit code safely)
# --------------------------------------------------------------------
- name: Run pre-commit (full logs)
id: runprecommit
run: |
echo "🔍 Running full pre-commit checks..."
set +e # allow failure
pre-commit run --all-files --verbose --show-diff-on-failure --color never \
| tee full_precommit.log
exit_code=${PIPESTATUS[0]}
echo "Pre-commit exit code: $exit_code"
echo "$exit_code" > precommit_exit_code.txt
# --------------------------------------------------------------------
# STEP 2: Summary of FAILED hooks
# --------------------------------------------------------------------
- name: Pre-commit summary of failed hooks
run: |
echo "====================================================="
echo " PRE-COMMIT SUMMARY"
echo "====================================================="
exit_code=$(cat precommit_exit_code.txt)
if [ "$exit_code" = "0" ]; then
echo " All hooks passed!"
exit 0
fi
echo " Hooks failed — showing summary:"
echo ""
echo " FAILED HOOKS:"
grep -E "^\w.*\.{3,}Failed" full_precommit.log || echo " None"
echo "-----------------------------------------------------"
echo " FILES WITH ISSUES:"
grep -E "files were modified by this hook" -A3 full_precommit.log \
| sed 's/^/ - /' || echo " None"
echo "-----------------------------------------------------"
echo " ERROR DETAILS:"
grep -Ei "(error|failed|violation|missing|line too long|could not|warning)" full_precommit.log \
| grep -Ev "^(---|\+\+\+|@@|diff --git|index )" \
| sed 's/^/ • /' || echo " None"
echo "-----------------------------------------------------"
exit $exit_code