Skip to content

Commit 517d12a

Browse files
Editorial: If no prose changes prettier workflow should not fail (#2641)
1 parent 6928130 commit 517d12a

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

.github/workflows/prettier.yaml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,30 @@ jobs:
3131
changed_files=$(git diff --name-only HEAD~1 HEAD | grep -E '\.(js|json|css|html)$' || true)
3232
3333
if [[ -n "$changed_files" ]]; then
34+
echo "Found changed files to format:"
35+
echo "$changed_files"
36+
37+
# Run prettier on the changed files
3438
echo "$changed_files" | xargs prettier --write --print-width 200
35-
36-
echo "changed=true" >> "$GITHUB_OUTPUT"
39+
40+
# Check if prettier actually made any changes
41+
if git diff --quiet && git diff --cached --quiet; then
42+
echo "No formatting changes were made by Prettier"
43+
echo "prettier_changes=false" >> "$GITHUB_OUTPUT"
44+
else
45+
echo "Prettier made formatting changes"
46+
echo "prettier_changes=true" >> "$GITHUB_OUTPUT"
47+
fi
48+
49+
echo "prose_changes=true" >> "$GITHUB_OUTPUT"
3750
else
38-
echo "changed=false" >> "$GITHUB_OUTPUT"
51+
echo "No JavaScript, JSON, CSS, or HTML files were changed in this commit."
52+
echo "prose_changes=false" >> "$GITHUB_OUTPUT"
53+
exit 0
3954
fi
4055
4156
- name: Commit and push changes
42-
if: steps.run_prettier.outputs.changed == 'true'
57+
if: steps.run_prettier.outputs.prettier_changes == 'true'
4358
run: |
4459
git config --local user.name "github-actions[bot]"
4560
git config --local user.email "github-actions[bot]@users.noreply.github.com"
@@ -49,7 +64,4 @@ jobs:
4964
5065
# Push to the main branch using PAT
5166
git push origin HEAD:${{ github.ref_name }}
52-
53-
- name: No changes to commit
54-
if: steps.run_prettier.outputs.changed == 'false'
55-
run: echo "No changes to commit."
67+
echo "Changes committed and pushed successfully"

0 commit comments

Comments
 (0)