1- name : EditorConfig Check [Report-Only ]
1+ name : EditorConfig Check (EC) [Reports + Summary ]
22
33on :
44 push :
@@ -38,77 +38,92 @@ permissions:
3838
3939jobs :
4040 editorconfig-check :
41- name : 🔍 EditorConfig Lint (Report-Only )
41+ name : 🔍 EditorConfig Lint (Reports First )
4242 runs-on : ubuntu-latest
4343 timeout-minutes : 15
4444
4545 env :
46- # REPORT-ONLY: never fail the workflow (even if violations exist)
47- REPORT_ONLY : " true"
48-
49- # Pin for deterministic installs
5046 EC_VERSION : " 3.0.3"
5147
52- # Output
5348 OUT_DIR : " editorconfig-reports"
54- EC_OUTPUT : " ec-output.txt"
55- EC_SUMMARY : " ec-summary.md"
49+ OUT_TXT : " ec-output.txt"
50+ OUT_MD : " ec-report.md"
51+
52+ # Enterprise compromise:
53+ # - true => fail ONLY on push to main (after publishing reports)
54+ # - false => never fail (pure report-only)
55+ ENFORCE_ON_MAIN : " false"
56+
57+ # How much to show inline in View Runs
58+ SUMMARY_LINES : " 160"
5659
5760 steps :
58- - name : 📦 Checkout Repository
61+ - name : 📦 Checkout
5962 uses : actions/checkout@v4
6063
61- - name : 📁 Ensure output folder exists
64+ - name : 📁 Prepare output directory
65+ if : always()
6266 shell : bash
6367 run : |
6468 set -euo pipefail
6569 mkdir -p "${OUT_DIR}"
6670
6771 - name : 📥 Install EditorConfig Checker (pinned)
72+ if : always()
6873 shell : bash
6974 run : |
7075 set -euo pipefail
7176
7277 URL="https://github.com/editorconfig-checker/editorconfig-checker/releases/download/v${EC_VERSION}/ec-linux-amd64.tar.gz"
7378 TMPDIR="$(mktemp -d)"
74- curl -fsSL "${URL}" -o "${TMPDIR}/ec.tar.gz"
7579
80+ curl -fsSL "${URL}" -o "${TMPDIR}/ec.tar.gz"
7681 mkdir -p "${TMPDIR}/ec"
7782 tar -xzf "${TMPDIR}/ec.tar.gz" -C "${TMPDIR}/ec"
7883
7984 BIN="$(find "${TMPDIR}/ec" -maxdepth 6 -type f \( -name 'ec-linux-amd64' -o -name 'ec' \) | head -n 1 || true)"
8085 if [[ -z "${BIN:-}" ]]; then
81- echo "❌ Error: 'ec' binary not found after extraction ."
86+ echo "❌ ec binary not found."
8287 find "${TMPDIR}/ec" -maxdepth 6 -print
83- exit 1
88+ # Mark tool install as failed but do not crash the whole job here; summary will show it.
89+ exit 2
8490 fi
8591
8692 sudo install -m 0755 "${BIN}" /usr/local/bin/ec
8793 /usr/local/bin/ec --version
8894
89- - name : ▶️ Run EditorConfig Checker (capture output + exit code)
90- id : ec
95+ - name : ▶️ Run EC (capture full output + exit code)
96+ id : run
97+ if : always()
9198 shell : bash
9299 run : |
93100 set -euo pipefail
94101
95- OUT_TXT ="${OUT_DIR}/${EC_OUTPUT }"
102+ TXT ="${OUT_DIR}/${OUT_TXT }"
96103
97104 set +e
98- /usr/local/bin/ec . 2>&1 | tee "${OUT_TXT }"
105+ /usr/local/bin/ec . 2>&1 | tee "${TXT }"
99106 EC_EXIT="${PIPESTATUS[0]}"
100107 set -e
101108
109+ # If the binary isn't present (install step failed), set an explicit tool failure code.
110+ if [[ ! -x "/usr/local/bin/ec" ]]; then
111+ EC_EXIT="2"
112+ echo "ec binary missing; forcing tool failure code 2" | tee -a "${TXT}"
113+ fi
114+
102115 echo "exit_code=${EC_EXIT}" >> "${GITHUB_OUTPUT}"
103116 echo "EditorConfig Checker exit code: ${EC_EXIT}"
104117
105- - name : 🧾 Classify result (clean / violations / tool failure)
106- id : policy
118+ - name : 🧾 Classify result (clean / violations / tool_failure)
119+ id : classify
120+ if : always()
107121 shell : bash
108122 run : |
109123 set -euo pipefail
110124
111- EC_EXIT="${{ steps.ec.outputs.exit_code }}"
125+ EC_EXIT="${{ steps.run.outputs.exit_code }}"
126+
112127 if [[ "${EC_EXIT}" == "0" ]]; then
113128 echo "status=clean" >> "${GITHUB_OUTPUT}"
114129 elif [[ "${EC_EXIT}" == "1" ]]; then
@@ -117,20 +132,20 @@ jobs:
117132 echo "status=tool_failure" >> "${GITHUB_OUTPUT}"
118133 fi
119134
120- - name : 📋 Publish Run Summary (View Runs )
135+ - name : 📝 Build Markdown report file (full context )
121136 if : always()
122137 shell : bash
123138 run : |
124139 set -euo pipefail
125140
126- OUT_TXT ="${OUT_DIR}/${EC_OUTPUT }"
127- OUT_MD ="${OUT_DIR}/${EC_SUMMARY }"
141+ TXT ="${OUT_DIR}/${OUT_TXT }"
142+ MD ="${OUT_DIR}/${OUT_MD }"
128143
129- STATUS="${{ steps.policy .outputs.status }}"
130- EXIT_CODE="${{ steps.ec .outputs.exit_code }}"
144+ STATUS="${{ steps.classify .outputs.status }}"
145+ EXIT_CODE="${{ steps.run .outputs.exit_code }}"
131146
132147 {
133- echo "## 🔍 EditorConfig Check ( Report-Only) "
148+ echo "# 🔍 EditorConfig Report"
134149 echo
135150 echo "- **Workflow:** \`${{ github.workflow }}\`"
136151 echo "- **Event:** \`${{ github.event_name }}\`"
@@ -139,42 +154,53 @@ jobs:
139154 echo "- **EC version:** \`${EC_VERSION}\`"
140155 echo "- **Exit code:** \`${EXIT_CODE}\`"
141156 echo "- **Status:** \`${STATUS}\`"
142- echo "- **REPORT_ONLY:** \`${REPORT_ONLY}\`"
143157 echo
158+ echo "## Output (full log)"
159+ echo
160+ echo '```text'
161+ cat "${TXT}" 2>/dev/null || echo "(no output file found)"
162+ echo '```'
163+ } > "${MD}"
144164
145- if [[ "${STATUS}" == "tool_failure" ]]; then
146- echo "❌ **Tool failure** — EditorConfig Checker did not run successfully."
147- echo
148- echo "**Output (top 120 lines):**"
149- echo
150- echo '```text'
151- head -n 120 "${OUT_TXT}" || true
152- echo '```'
153- echo
154- echo "_Fix the workflow/tool invocation; results are not trustworthy._"
165+ - name : 📌 Publish Run Summary (View Runs)
166+ if : always()
167+ shell : bash
168+ run : |
169+ set -euo pipefail
155170
156- elif [[ "${STATUS}" == "violations" ]]; then
157- echo "⚠️ **Violations detected** (report-only — workflow does not fail)"
158- echo
159- echo "**Output (top 120 lines):**"
160- echo
161- echo '```text'
162- head -n 120 "${OUT_TXT}" || true
163- echo '```'
164- echo
165- echo "_Output truncated. Download artifacts for full details._"
171+ TXT="${OUT_DIR}/${OUT_TXT}"
172+ STATUS="${{ steps.classify.outputs.status }}"
173+ EXIT_CODE="${{ steps.run.outputs.exit_code }}"
174+ LINES="${SUMMARY_LINES}"
166175
176+ {
177+ echo "## 🔍 EditorConfig Check"
178+ echo
179+ echo "- **Status:** \`${STATUS}\`"
180+ echo "- **Exit code:** \`${EXIT_CODE}\`"
181+ echo "- **Ref:** \`${{ github.ref }}\`"
182+ echo "- **Commit:** \`${{ github.sha }}\`"
183+ echo
184+ if [[ "${STATUS}" == "tool_failure" ]]; then
185+ echo "❌ **Tool failure** — EC did not run cleanly. Output below:"
186+ elif [[ "${STATUS}" == "violations" ]]; then
187+ echo "⚠️ **Violations detected** — reporting continues and artifacts are uploaded."
167188 else
168189 echo "✅ **No violations detected.**"
169190 fi
170-
191+ echo
192+ echo "**Output (top ${LINES} lines):**"
193+ echo
194+ echo '```text'
195+ head -n "${LINES}" "${TXT}" 2>/dev/null || echo "(no output file found)"
196+ echo '```'
171197 echo
172198 echo "### 📦 Artifacts"
173- echo "- \`${OUT_DIR}/${EC_OUTPUT }\`"
174- echo "- \`${OUT_DIR}/${EC_SUMMARY }\`"
175- } | tee "${OUT_MD}" >> "${ GITHUB_STEP_SUMMARY} "
199+ echo "- \`${OUT_DIR}/${OUT_TXT }\`"
200+ echo "- \`${OUT_DIR}/${OUT_MD }\`"
201+ } >> "$GITHUB_STEP_SUMMARY"
176202
177- - name : 📦 Upload Artifacts (output + summary )
203+ - name : 📦 Upload artifacts (always )
178204 if : always()
179205 uses : actions/upload-artifact@v4
180206 with :
@@ -183,10 +209,40 @@ jobs:
183209 if-no-files-found : warn
184210 retention-days : 30
185211
186- - name : ✅ Finalize (report-only mode never fails )
212+ - name : 🚫 Optional enforcement (AFTER reporting only )
187213 if : always()
188214 shell : bash
189215 run : |
190216 set -euo pipefail
191- echo "Report-only workflow: always passing regardless of violations."
192- exit 0
217+
218+ STATUS="${{ steps.classify.outputs.status }}"
219+
220+ # Never block PRs; enforcement is only meaningful on main pushes.
221+ if [[ "${{ github.event_name }}" == "pull_request" ]]; then
222+ echo "PR run -> never fail. Reports already published."
223+ exit 0
224+ fi
225+
226+ # If enforcement is disabled, always pass.
227+ if [[ "${ENFORCE_ON_MAIN}" != "true" ]]; then
228+ echo "ENFORCE_ON_MAIN!=true -> report-only mode. Passing."
229+ exit 0
230+ fi
231+
232+ # Enforce only on main.
233+ if [[ "${{ github.ref }}" != "refs/heads/main" ]]; then
234+ echo "Not main -> report-only mode. Passing."
235+ exit 0
236+ fi
237+
238+ if [[ "${STATUS}" == "tool_failure" ]]; then
239+ echo "❌ Tool failure. Failing on main."
240+ exit 1
241+ fi
242+
243+ if [[ "${STATUS}" == "violations" ]]; then
244+ echo "❌ Violations detected. Failing on main."
245+ exit 1
246+ fi
247+
248+ echo "✅ Clean. Passing."
0 commit comments