Logo update #178
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto-format with Prettier | |
| on: | |
| pull_request: | |
| permissions: | |
| contents: write | |
| jobs: | |
| prettier: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # important so git diff works | |
| - uses: actions/setup-node@v4 | |
| - name: Install deps | |
| run: yarn | |
| - name: Run prettier on changed files | |
| run: | | |
| CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD \ | |
| | grep -E '\.(ts|tsx|js|jsx|json|md|yaml|yml|css|scss)$' || true) | |
| if [ -n "$CHANGED_FILES" ]; then | |
| FILES_TO_FORMAT="" | |
| while IFS= read -r file; do | |
| if [ -f "$file" ]; then | |
| FILES_TO_FORMAT="$FILES_TO_FORMAT\n$file" | |
| else | |
| echo "Skipping missing file: $file" | |
| fi | |
| done <<< "$CHANGED_FILES" | |
| if [ -n "$FILES_TO_FORMAT" ]; then | |
| printf "%b\n" "$FILES_TO_FORMAT" | sed '/^$/d' | xargs yarn prettier --write | |
| else | |
| echo "No existing files to format" | |
| fi | |
| else | |
| echo "No files to format" | |
| fi | |
| - name: Commit formatted changes | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| if [ -n "$(git status --porcelain)" ]; then | |
| # Check out the PR branch to avoid detached HEAD | |
| git checkout ${{ github.head_ref }} | |
| git add --all | |
| git commit -m "chore: Apply Prettier formatting" | |
| git push origin ${{ github.head_ref }} | |
| else | |
| echo "No formatting changes to commit" | |
| fi |