-
Notifications
You must be signed in to change notification settings - Fork 7
128 lines (110 loc) · 4.17 KB
/
pre-commit.yaml
File metadata and controls
128 lines (110 loc) · 4.17 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
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 Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Create and activate Python venv
run: |
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install pre-commit
shell: bash
# Optional: add venv to PATH for subsequent steps
- name: Add venv to PATH
run: echo "${{ github.workspace }}/.venv/bin" >> $GITHUB_PATH
- 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
shell: bash
- 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
shell: bash
# --------------------------------------------------------------------
# STEP 1: Run pre-commit (capture full logs and exit code safely)
# --------------------------------------------------------------------
- name: Run pre-commit (full logs)
id: runprecommit
run: |
source .venv/bin/activate
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
shell: bash
# --------------------------------------------------------------------
# STEP 2: Summary of FAILED hooks
# --------------------------------------------------------------------
- name: Pre-commit summary of failed hooks
run: |
source .venv/bin/activate
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
shell: bash