Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Prettier

on:
pull_request:
permissions:
contents: write
jobs:
prettier:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0 # Needed to compare with origin/main

- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: 24
cache: npm

- name: Install dependencies
run: npm ci

- name: Get changed files and run Prettier
id: run_prettier
run: |
# Compare with the previous commit to find changed files
changed_files=$(git diff --name-only HEAD~1 HEAD | grep -E '\.(js|mjs|cjs|json|css|html|md|yml)$' || true)

if [[ -n "$changed_files" ]]; then
echo "Found changed files to format:"
echo "$changed_files"

# Run prettier on the changed files
echo "$changed_files" | xargs npx --no-install prettier --write

# Check if prettier actually made any changes
if git diff --quiet && git diff --cached --quiet; then
echo "No formatting changes were made by Prettier"
echo "prettier_changes=false" >> "$GITHUB_OUTPUT"
else
echo "Prettier made formatting changes"
echo "prettier_changes=true" >> "$GITHUB_OUTPUT"
fi

echo "prose_changes=true" >> "$GITHUB_OUTPUT"
else
echo "No relevant files were changed in this commit."
echo "prose_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi

- name: Commit and push changes
if: steps.run_prettier.outputs.prettier_changes == 'true'
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add .
git commit -m "Chore: Format files with Prettier"
git push origin HEAD:${{ github.head_ref }}
echo "Changes committed and pushed successfully"
Loading