Skip to content

Commit 2476cfd

Browse files
Update prettier-code-format-check.yml
Signed-off-by: LUIZ HAMILTON ROBERTO DA SILVA <[email protected]>
1 parent 4ef99da commit 2476cfd

1 file changed

Lines changed: 26 additions & 31 deletions

File tree

.github/workflows/prettier-code-format-check.yml

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ permissions:
5050

5151
jobs:
5252
prettier:
53-
name: 💅 Prettier Code Format Validation
53+
name: "💅 Prettier Code Format Validation"
5454
runs-on: ubuntu-latest
5555
timeout-minutes: 15
5656

@@ -68,10 +68,10 @@ jobs:
6868
NPM_DEBUG_LOG: "npm-debug.log"
6969

7070
steps:
71-
- name: 📦 Checkout Repository
71+
- name: "📦 Checkout Repository"
7272
uses: actions/checkout@v4
7373

74-
- name: 🧾 Detect Package Manager + Tooling
74+
- name: "🧾 Detect Package Manager + Tooling"
7575
id: pm
7676
shell: bash
7777
run: |
@@ -93,15 +93,15 @@ jobs:
9393
echo "has_package_json=false" >> "$GITHUB_OUTPUT"
9494
fi
9595
96-
- name: ⚙️ Setup Node.js (LTS) + Cache
96+
- name: "⚙️ Setup Node.js (LTS) + Cache"
9797
uses: actions/setup-node@v4
9898
with:
9999
node-version: "20"
100-
cache: ${{ steps.pm.outputs.manager }}
100+
cache: "${{ steps.pm.outputs.manager }}"
101101

102-
- name: 📥 Install Dependencies (only if package.json exists)
102+
- name: "📥 Install Dependencies (only if package.json exists)"
103103
id: install
104-
if: ${{ steps.pm.outputs.has_package_json == 'true' }}
104+
if: "${{ steps.pm.outputs.has_package_json == 'true' }}"
105105
shell: bash
106106
run: |
107107
set -euo pipefail
@@ -114,6 +114,7 @@ jobs:
114114
elif [[ "$mgr" == "yarn" ]]; then
115115
corepack enable
116116
yarn --version
117+
# Yarn Berry uses --immutable; Yarn classic ignores it but won't break
117118
yarn install --immutable || yarn install
118119
else
119120
if [[ -f package-lock.json ]]; then
@@ -124,7 +125,7 @@ jobs:
124125
fi
125126
fi
126127
127-
- name: 🧰 Ensure Prettier Available
128+
- name: "🧰 Ensure Prettier Available"
128129
id: ensure_prettier
129130
shell: bash
130131
run: |
@@ -143,6 +144,7 @@ jobs:
143144
fi
144145
145146
echo "::notice::Prettier not found in node_modules. Bootstrapping Prettier v${PRETTIER_VERSION} for CI-only run."
147+
# CI-only install (runner workspace only; no commits)
146148
npm install --no-save "prettier@${PRETTIER_VERSION}"
147149
148150
if [[ -x "node_modules/.bin/prettier" ]]; then
@@ -153,32 +155,28 @@ jobs:
153155
echo "prettier_source=bootstrap-failed" >> "$GITHUB_OUTPUT"
154156
fi
155157
156-
- name: 🧾 Build file list (tracked files only)
158+
- name: "🧾 Build file list (tracked files only)"
157159
id: files
158160
shell: bash
159161
run: |
160162
set -euo pipefail
161163
162-
# Only tracked files; avoids scanning node_modules or generated artifacts.
163-
# Keep in sync with your "paths" filters.
164164
git ls-files -z \
165165
'*.js' '*.ts' '*.jsx' '*.tsx' \
166166
'*.css' '*.json' '*.md' \
167167
'*.yml' '*.yaml' \
168168
> prettier-files.txt || true
169169
170-
count="$(python3 - <<'PY'
171-
import os
172-
p='prettier-files.txt'
173-
if not os.path.exists(p):
174-
print(0); raise SystemExit
175-
data=open(p,'rb').read()
176-
print(0 if not data else data.count(b'\x00'))
177-
PY
178-
)"
170+
if [[ ! -s prettier-files.txt ]]; then
171+
echo "count=0" >> "$GITHUB_OUTPUT"
172+
exit 0
173+
fi
174+
175+
# Count NUL-separated entries safely
176+
count="$(tr -cd '\0' < prettier-files.txt | wc -c | tr -d ' ')"
179177
echo "count=${count}" >> "$GITHUB_OUTPUT"
180178
181-
- name: 🔍 Run Prettier Check (tracked files)
179+
- name: "🔍 Run Prettier Check (tracked files)"
182180
id: run_prettier
183181
shell: bash
184182
run: |
@@ -202,17 +200,16 @@ PY
202200
exit 0
203201
fi
204202
203+
# Run local prettier directly (avoid npx ambiguity)
205204
set +e
206-
# Use --ignore-unknown to avoid errors on edge cases if file list expands later.
207-
# Use xargs -0 to preserve spaces/newlines in paths.
208205
cat prettier-files.txt | xargs -0 node_modules/.bin/prettier --ignore-unknown --check > "$report" 2>&1
209206
ec="$?"
210207
set -e
211208
212209
echo "exit_code=$ec" >> "$GITHUB_OUTPUT"
213210
echo "Prettier exit code: $ec"
214211
215-
- name: 🧾 Capture npm debug log (if any)
212+
- name: "🧾 Capture npm debug log (if any)"
216213
if: always()
217214
shell: bash
218215
run: |
@@ -224,7 +221,7 @@ PY
224221
echo "No npm debug log found." > "${NPM_DEBUG_LOG}"
225222
fi
226223
227-
- name: 📄 Generate Job Summary
224+
- name: "📄 Generate Job Summary"
228225
if: always()
229226
shell: bash
230227
run: |
@@ -237,12 +234,11 @@ PY
237234
has_pkg="${{ steps.pm.outputs.has_package_json }}"
238235
files_count="${{ steps.files.outputs.count }}"
239236
240-
# Approx count of reported issues/files from report (best-effort).
241-
findings="$(grep -E '^\[warn\]|^\[error\]' "${PRETTIER_REPORT}" 2>/dev/null | wc -l | tr -d ' ' || echo 0)"
242-
243237
{
244238
echo "### 💅 Prettier Format Summary"
245239
echo
240+
echo "- **Workflow:** \`${GITHUB_WORKFLOW}\`"
241+
echo "- **Event:** \`${GITHUB_EVENT_NAME}\`"
246242
echo "- **Ref:** \`${GITHUB_REF}\`"
247243
echo "- **Commit:** \`${GITHUB_SHA}\`"
248244
echo "- **Package manager:** \`${mgr}\`"
@@ -252,7 +248,6 @@ PY
252248
echo "- **ALLOW_WARNINGS:** \`${ALLOW_WARNINGS}\`"
253249
echo "- **Prettier available:** \`${prettier_present}\`"
254250
echo "- **Prettier source:** \`${prettier_source}\`"
255-
echo "- **Reported lines (warn/error):** \`${findings}\`"
256251
echo
257252
258253
if [[ "${prettier_present}" != "true" ]]; then
@@ -284,7 +279,7 @@ PY
284279
fi
285280
} | tee "${PRETTIER_SUMMARY}" >> "$GITHUB_STEP_SUMMARY"
286281
287-
- name: 📦 Upload Artifacts
282+
- name: "📦 Upload Artifacts"
288283
if: always()
289284
uses: actions/upload-artifact@v4
290285
with:
@@ -296,7 +291,7 @@ PY
296291
prettier-files.txt
297292
retention-days: 30
298293

299-
- name: ✅ Policy Gate
294+
- name: "✅ Policy Gate"
300295
if: always()
301296
shell: bash
302297
run: |

0 commit comments

Comments
 (0)