Skip to content

Commit 2f871d1

Browse files
Update editorconfig-check.yml
Signed-off-by: LUIZ HAMILTON ROBERTO DA SILVA <[email protected]>
1 parent 4bc55e4 commit 2f871d1

1 file changed

Lines changed: 80 additions & 37 deletions

File tree

.github/workflows/editorconfig-check.yml

Lines changed: 80 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -43,139 +43,182 @@ jobs:
4343
timeout-minutes: 15
4444

4545
env:
46-
ALLOW_WARNINGS: "false"
46+
# Enterprise compromise:
47+
# - PRs: report-only (never fail)
48+
# - develop pushes: report-only (never fail)
49+
# - main pushes: enforce (fail on violations)
50+
ALLOW_WARNINGS: ${{ (github.event_name == 'pull_request' || github.ref == 'refs/heads/develop') && 'true' || 'false' }}
51+
52+
# Pin for deterministic installs
4753
EC_VERSION: "3.0.3"
54+
55+
# Output files
56+
OUT_DIR: "editorconfig-reports"
4857
EC_OUTPUT: "ec-output.txt"
4958
EC_SUMMARY: "ec-summary.md"
5059

5160
steps:
5261
- name: 📦 Checkout Repository
5362
uses: actions/checkout@v4
5463

64+
- name: 📁 Ensure output folder exists
65+
shell: bash
66+
run: |
67+
set -euo pipefail
68+
mkdir -p "${OUT_DIR}"
69+
5570
- name: 📥 Install EditorConfig Checker (pinned)
5671
shell: bash
5772
run: |
5873
set -euo pipefail
74+
5975
URL="https://github.com/editorconfig-checker/editorconfig-checker/releases/download/v${EC_VERSION}/ec-linux-amd64.tar.gz"
76+
echo "Downloading EditorConfig Checker v${EC_VERSION}..."
77+
echo "URL: ${URL}"
78+
6079
TMPDIR="$(mktemp -d)"
6180
curl -fsSL "${URL}" -o "${TMPDIR}/ec.tar.gz"
81+
6282
mkdir -p "${TMPDIR}/ec"
6383
tar -xzf "${TMPDIR}/ec.tar.gz" -C "${TMPDIR}/ec"
84+
6485
BIN="$(find "${TMPDIR}/ec" -maxdepth 6 -type f \( -name 'ec-linux-amd64' -o -name 'ec' \) | head -n 1 || true)"
6586
if [[ -z "${BIN:-}" ]]; then
6687
echo "❌ Error: 'ec' binary not found after extraction."
88+
echo "Extracted contents:"
6789
find "${TMPDIR}/ec" -maxdepth 6 -print
6890
exit 1
6991
fi
92+
7093
sudo install -m 0755 "${BIN}" /usr/local/bin/ec
94+
echo "Installed:"
7195
/usr/local/bin/ec --version
7296
7397
- name: ▶️ Run EditorConfig Checker (capture output + exit code)
7498
id: ec
7599
shell: bash
76100
run: |
77101
set -euo pipefail
102+
103+
OUT_TXT="${OUT_DIR}/${EC_OUTPUT}"
104+
78105
set +e
79-
# IMPORTANT: no invalid flags; let ec run normally
80-
/usr/local/bin/ec . 2>&1 | tee "${EC_OUTPUT}"
106+
/usr/local/bin/ec . 2>&1 | tee "${OUT_TXT}"
81107
EC_EXIT="${PIPESTATUS[0]}"
82108
set -e
109+
83110
echo "exit_code=${EC_EXIT}" >> "${GITHUB_OUTPUT}"
84111
echo "EditorConfig Checker exit code: ${EC_EXIT}"
85112
86-
- name: 🧾 Compute Violation + Tool Failure Signals
113+
- name: 🧾 Classify result (clean / violations / tool failure)
87114
id: policy
88115
shell: bash
89116
run: |
90117
set -euo pipefail
91118
92119
EC_EXIT="${{ steps.ec.outputs.exit_code }}"
93120
94-
# ec conventions (typical):
95-
# 0 = no violations
96-
# 1 = violations found
97-
# other = tool/runtime failure (bad args, crash, etc)
98-
if [[ "${EC_EXIT}" != "0" && "${EC_EXIT}" != "1" ]]; then
99-
echo "tool_failure=true" >> "${GITHUB_OUTPUT}"
100-
echo "violations=false" >> "${GITHUB_OUTPUT}"
121+
# Conventions:
122+
# 0 = clean
123+
# 1 = violations
124+
# other = tool/runtime failure
125+
if [[ "${EC_EXIT}" == "0" ]]; then
126+
echo "status=clean" >> "${GITHUB_OUTPUT}"
101127
exit 0
102128
fi
103129
104-
echo "tool_failure=false" >> "${GITHUB_OUTPUT}"
105130
if [[ "${EC_EXIT}" == "1" ]]; then
106-
echo "violations=true" >> "${GITHUB_OUTPUT}"
107-
else
108-
echo "violations=false" >> "${GITHUB_OUTPUT}"
131+
echo "status=violations" >> "${GITHUB_OUTPUT}"
132+
exit 0
109133
fi
110134
111-
- name: 📋 Generate Markdown Summary
135+
echo "status=tool_failure" >> "${GITHUB_OUTPUT}"
136+
137+
- name: 📋 Generate Markdown Summary (View Runs)
112138
if: always()
113139
shell: bash
114140
run: |
115141
set -euo pipefail
142+
143+
OUT_TXT="${OUT_DIR}/${EC_OUTPUT}"
144+
OUT_MD="${OUT_DIR}/${EC_SUMMARY}"
145+
146+
STATUS="${{ steps.policy.outputs.status }}"
147+
EXIT_CODE="${{ steps.ec.outputs.exit_code }}"
148+
116149
{
117-
echo "### 🔍 EditorConfig Check Summary"
150+
echo "## 🔍 EditorConfig Check"
118151
echo
119152
echo "- **Workflow:** \`${{ github.workflow }}\`"
153+
echo "- **Event:** \`${{ github.event_name }}\`"
120154
echo "- **Ref:** \`${{ github.ref }}\`"
121155
echo "- **Commit:** \`${{ github.sha }}\`"
122156
echo "- **EC version:** \`${EC_VERSION}\`"
123-
echo "- **Exit code:** \`${{ steps.ec.outputs.exit_code }}\`"
124-
echo "- **Tool failure:** \`${{ steps.policy.outputs.tool_failure }}\`"
125-
echo "- **Violations detected:** \`${{ steps.policy.outputs.violations }}\`"
126-
echo "- **ALLOW_WARNINGS:** \`${ALLOW_WARNINGS}\`"
157+
echo "- **Exit code:** \`${EXIT_CODE}\`"
158+
echo "- **Status:** \`${STATUS}\`"
159+
echo "- **Policy (ALLOW_WARNINGS):** \`${ALLOW_WARNINGS}\`"
127160
echo
128161
129-
if [[ "${{ steps.policy.outputs.tool_failure }}" == "true" ]]; then
130-
echo "❌ **EditorConfig Checker failed to run (invalid args or runtime error).**"
162+
if [[ "${STATUS}" == "tool_failure" ]]; then
163+
echo "❌ **Tool failure** — EditorConfig Checker did not run successfully."
131164
echo
132-
echo "**Output (top 60 lines):**"
165+
echo "**Output (top 80 lines):**"
133166
echo
134167
echo '```text'
135-
head -n 60 "${EC_OUTPUT}" || true
168+
head -n 80 "${OUT_TXT}" || true
136169
echo '```'
137170
echo
138171
echo "_Fix the workflow/tool invocation; results are not trustworthy._"
139-
elif [[ "${{ steps.policy.outputs.violations }}" == "true" ]]; then
140-
echo "**Violations found (top 40 lines):**"
172+
173+
elif [[ "${STATUS}" == "violations" ]]; then
174+
echo "⚠️ **Violations detected**"
175+
echo
176+
echo "**Output (top 80 lines):**"
141177
echo
142178
echo '```text'
143-
head -n 40 "${EC_OUTPUT}" || true
179+
head -n 80 "${OUT_TXT}" || true
144180
echo '```'
145181
echo
146-
echo "_Output truncated. Download artifact '${EC_OUTPUT}' for full details._"
182+
echo "_Output truncated. Download artifact '${OUT_DIR}' for full details._"
183+
147184
else
148-
echo "✅ No violations detected."
185+
echo "✅ **No violations detected.**"
149186
fi
150-
} | tee "${EC_SUMMARY}" >> "${GITHUB_STEP_SUMMARY}"
187+
188+
echo
189+
echo "### 📦 Artifacts"
190+
echo "- \`${OUT_DIR}/${EC_OUTPUT}\`"
191+
echo "- \`${OUT_DIR}/${EC_SUMMARY}\`"
192+
} | tee "${OUT_MD}" >> "${GITHUB_STEP_SUMMARY}"
151193
152194
- name: 📦 Upload Artifacts (output + summary)
153195
if: always()
154196
uses: actions/upload-artifact@v4
155197
with:
156198
name: editorconfig-check
157-
path: |
158-
${{ env.EC_OUTPUT }}
159-
${{ env.EC_SUMMARY }}
199+
path: ${{ env.OUT_DIR }}/**
200+
if-no-files-found: warn
160201
retention-days: 30
161202

162-
- name: 🚫 Enforce Policy
203+
- name: 🚫 Enforce Policy (never blocks PRs; enforce on main only)
163204
if: always()
164205
shell: bash
165206
run: |
166207
set -euo pipefail
167208
209+
STATUS="${{ steps.policy.outputs.status }}"
210+
168211
if [[ "${ALLOW_WARNINGS}" == "true" ]]; then
169212
echo "ALLOW_WARNINGS=true -> report-only mode. Passing."
170213
exit 0
171214
fi
172215
173-
if [[ "${{ steps.policy.outputs.tool_failure }}" == "true" ]]; then
216+
if [[ "${STATUS}" == "tool_failure" ]]; then
174217
echo "❌ Tool failure (workflow misconfig or runtime error). Failing."
175218
exit 1
176219
fi
177220
178-
if [[ "${{ steps.policy.outputs.violations }}" == "true" ]]; then
221+
if [[ "${STATUS}" == "violations" ]]; then
179222
echo "❌ EditorConfig violations detected. Failing."
180223
exit 1
181224
fi

0 commit comments

Comments
 (0)