-
-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (119 loc) · 4.53 KB
/
Copy pathproof-html-js-css.yml
File metadata and controls
140 lines (119 loc) · 4.53 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
138
139
140
# .github/workflows/proof-html-js-css.yml
name: Proof HTML, Lint JS & CSS
on:
push:
branches:
- main
- master
- develop
pull_request:
branches:
- main
- master
- develop
workflow_dispatch:
jobs:
################################################################
# JOB 1: LINTER & PROOFER (The "Enforcer")
# This job runs on EVERY push and pull request.
# Its only job is to CHECK for errors and fail if it finds any.
################################################################
lint:
name: Lint & Proof Frontend Assets
runs-on: ubuntu-latest
permissions:
contents: read # This job only needs to read files.
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320
# uses: pnpm/action-setup@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Lint JavaScript (Check only)
# We run WITHOUT --fix here. The goal is to report errors, not hide them.
# ESLINT_USE_FLAT_CONFIG=false is required because the repo uses .eslintrc.json (ESLint v8 format).
env:
ESLINT_USE_FLAT_CONFIG: "false"
run: pnpm exec eslint "src/js/**/*.js"
- name: Lint CSS (Check only)
# We run WITHOUT --fix here.
run: pnpm exec stylelint "src/css/**/*.css"
- name: Proof HTML files
uses: anishathalye/proof-html@a76b66427e600c6992e8937a741afffd2264a613
# uses: anishathalye/proof-html@v2
with:
directory: "./src/templates"
################################################################
# JOB 2: AUTO-FIXER (The "Helper Bot")
# This job runs ONLY on pull requests.
# Its job is to fix simple errors and push them back to the PR branch.
################################################################
auto-fix:
name: Auto-fix JS & CSS
runs-on: ubuntu-latest
# CRITICAL: This condition ensures the job only runs for pull requests.
if: github.event_name == 'pull_request'
permissions:
contents: write # This job needs permission to push code.
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Setup pnpm
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320
# uses: pnpm/action-setup@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Fix JavaScript and CSS issues
env:
ESLINT_USE_FLAT_CONFIG: "false"
run: |
pnpm exec eslint "src/js/**/*.js" --fix || true
pnpm exec stylelint "src/css/**/*.css" --fix || true
- name: Check for auto-fixable changes
id: check-changes
run: |
if git diff --quiet; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "📝 No auto-fixable changes detected"
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "📝 Auto-fixable changes detected:"
git diff --stat
fi
- name: Commit and push fixes (PR only)
uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9
# uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore: auto-fix JS/CSS lint issues"
branch: ${{ github.head_ref }}
file_pattern: "src/js/**/*.js src/css/**/*.css"
if: github.event_name == 'pull_request' && steps.check-changes.outputs.changed == 'true'
- name: Upload fixes as artifact (protected branch)
if: github.event_name != 'pull_request' && steps.check-changes.outputs.changed == 'true'
uses: actions/upload-artifact@v4
with:
name: auto-fixes
path: |
src/js/**/*.js
src/css/**/*.css
retention-days: 7
- name: Branch protection notice
if: github.event_name != 'pull_request' && steps.check-changes.outputs.changed == 'true'
run: |
echo "⚠️ Auto-fixes available but cannot commit to protected branch"
echo "📦 Fixed files uploaded as workflow artifact"
echo "📝 Download artifact or run 'npm run fix' locally and commit manually"