-
-
Notifications
You must be signed in to change notification settings - Fork 3
248 lines (209 loc) · 7.35 KB
/
editorconfig-check.yml
File metadata and controls
248 lines (209 loc) · 7.35 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
name: EditorConfig Check (EC) [Reports + Summary]
on:
push:
branches: [main, develop]
paths:
- ".editorconfig"
- "**/.editorconfig"
- "**/*.ps1"
- "**/*.psm1"
- "**/*.psd1"
- "**/*.md"
- "**/*.yml"
- "**/*.yaml"
- "**/*.json"
- "**/*.xml"
pull_request:
branches: [main, develop]
paths:
- ".editorconfig"
- "**/.editorconfig"
- "**/*.ps1"
- "**/*.psm1"
- "**/*.psd1"
- "**/*.md"
- "**/*.yml"
- "**/*.yaml"
- "**/*.json"
- "**/*.xml"
workflow_dispatch:
concurrency:
group: editorconfig-check-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
editorconfig-check:
name: 🔍 EditorConfig Lint (Reports First)
runs-on: ubuntu-latest
timeout-minutes: 15
env:
EC_VERSION: "3.0.3"
OUT_DIR: "editorconfig-reports"
OUT_TXT: "ec-output.txt"
OUT_MD: "ec-report.md"
# Enterprise compromise:
# - true => fail ONLY on push to main (after publishing reports)
# - false => never fail (pure report-only)
ENFORCE_ON_MAIN: "false"
# How much to show inline in View Runs
SUMMARY_LINES: "160"
steps:
- name: 📦 Checkout
uses: actions/checkout@v4
- name: 📁 Prepare output directory
if: always()
shell: bash
run: |
set -euo pipefail
mkdir -p "${OUT_DIR}"
- name: 📥 Install EditorConfig Checker (pinned)
if: always()
shell: bash
run: |
set -euo pipefail
URL="https://github.com/editorconfig-checker/editorconfig-checker/releases/download/v${EC_VERSION}/ec-linux-amd64.tar.gz"
TMPDIR="$(mktemp -d)"
curl -fsSL "${URL}" -o "${TMPDIR}/ec.tar.gz"
mkdir -p "${TMPDIR}/ec"
tar -xzf "${TMPDIR}/ec.tar.gz" -C "${TMPDIR}/ec"
BIN="$(find "${TMPDIR}/ec" -maxdepth 6 -type f \( -name 'ec-linux-amd64' -o -name 'ec' \) | head -n 1 || true)"
if [[ -z "${BIN:-}" ]]; then
echo "❌ ec binary not found."
find "${TMPDIR}/ec" -maxdepth 6 -print
# Mark tool install as failed but do not crash the whole job here; summary will show it.
exit 2
fi
sudo install -m 0755 "${BIN}" /usr/local/bin/ec
/usr/local/bin/ec --version
- name: ▶️ Run EC (capture full output + exit code)
id: run
if: always()
shell: bash
run: |
set -euo pipefail
TXT="${OUT_DIR}/${OUT_TXT}"
set +e
/usr/local/bin/ec . 2>&1 | tee "${TXT}"
EC_EXIT="${PIPESTATUS[0]}"
set -e
# If the binary isn't present (install step failed), set an explicit tool failure code.
if [[ ! -x "/usr/local/bin/ec" ]]; then
EC_EXIT="2"
echo "ec binary missing; forcing tool failure code 2" | tee -a "${TXT}"
fi
echo "exit_code=${EC_EXIT}" >> "${GITHUB_OUTPUT}"
echo "EditorConfig Checker exit code: ${EC_EXIT}"
- name: 🧾 Classify result (clean / violations / tool_failure)
id: classify
if: always()
shell: bash
run: |
set -euo pipefail
EC_EXIT="${{ steps.run.outputs.exit_code }}"
if [[ "${EC_EXIT}" == "0" ]]; then
echo "status=clean" >> "${GITHUB_OUTPUT}"
elif [[ "${EC_EXIT}" == "1" ]]; then
echo "status=violations" >> "${GITHUB_OUTPUT}"
else
echo "status=tool_failure" >> "${GITHUB_OUTPUT}"
fi
- name: 📝 Build Markdown report file (full context)
if: always()
shell: bash
run: |
set -euo pipefail
TXT="${OUT_DIR}/${OUT_TXT}"
MD="${OUT_DIR}/${OUT_MD}"
STATUS="${{ steps.classify.outputs.status }}"
EXIT_CODE="${{ steps.run.outputs.exit_code }}"
{
echo "# 🔍 EditorConfig Report"
echo
echo "- **Workflow:** \`${{ github.workflow }}\`"
echo "- **Event:** \`${{ github.event_name }}\`"
echo "- **Ref:** \`${{ github.ref }}\`"
echo "- **Commit:** \`${{ github.sha }}\`"
echo "- **EC version:** \`${EC_VERSION}\`"
echo "- **Exit code:** \`${EXIT_CODE}\`"
echo "- **Status:** \`${STATUS}\`"
echo
echo "## Output (full log)"
echo
echo '```text'
cat "${TXT}" 2>/dev/null || echo "(no output file found)"
echo '```'
} > "${MD}"
- name: 📌 Publish Run Summary (View Runs)
if: always()
shell: bash
run: |
set -euo pipefail
TXT="${OUT_DIR}/${OUT_TXT}"
STATUS="${{ steps.classify.outputs.status }}"
EXIT_CODE="${{ steps.run.outputs.exit_code }}"
LINES="${SUMMARY_LINES}"
{
echo "## 🔍 EditorConfig Check"
echo
echo "- **Status:** \`${STATUS}\`"
echo "- **Exit code:** \`${EXIT_CODE}\`"
echo "- **Ref:** \`${{ github.ref }}\`"
echo "- **Commit:** \`${{ github.sha }}\`"
echo
if [[ "${STATUS}" == "tool_failure" ]]; then
echo "❌ **Tool failure** — EC did not run cleanly. Output below:"
elif [[ "${STATUS}" == "violations" ]]; then
echo "⚠️ **Violations detected** — reporting continues and artifacts are uploaded."
else
echo "✅ **No violations detected.**"
fi
echo
echo "**Output (top ${LINES} lines):**"
echo
echo '```text'
head -n "${LINES}" "${TXT}" 2>/dev/null || echo "(no output file found)"
echo '```'
echo
echo "### 📦 Artifacts"
echo "- \`${OUT_DIR}/${OUT_TXT}\`"
echo "- \`${OUT_DIR}/${OUT_MD}\`"
} >> "$GITHUB_STEP_SUMMARY"
- name: 📦 Upload artifacts (always)
if: always()
uses: actions/upload-artifact@v4
with:
name: editorconfig-check
path: ${{ env.OUT_DIR }}/**
if-no-files-found: warn
retention-days: 30
- name: 🚫 Optional enforcement (AFTER reporting only)
if: always()
shell: bash
run: |
set -euo pipefail
STATUS="${{ steps.classify.outputs.status }}"
# Never block PRs; enforcement is only meaningful on main pushes.
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "PR run -> never fail. Reports already published."
exit 0
fi
# If enforcement is disabled, always pass.
if [[ "${ENFORCE_ON_MAIN}" != "true" ]]; then
echo "ENFORCE_ON_MAIN!=true -> report-only mode. Passing."
exit 0
fi
# Enforce only on main.
if [[ "${{ github.ref }}" != "refs/heads/main" ]]; then
echo "Not main -> report-only mode. Passing."
exit 0
fi
if [[ "${STATUS}" == "tool_failure" ]]; then
echo "❌ Tool failure. Failing on main."
exit 1
fi
if [[ "${STATUS}" == "violations" ]]; then
echo "❌ Violations detected. Failing on main."
exit 1
fi
echo "✅ Clean. Passing."