Skip to content

Commit

Permalink
Add a workflow that runs Prettier and auto-fixes any issues
Browse files Browse the repository at this point in the history
  • Loading branch information
j-f1 committed Oct 2, 2022
1 parent 4485d5a commit 56874e0
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Run Prettier

permissions:
contents: write

on:
push:
branches: [main]

jobs:
check:
runs-on: ubuntu-20.04
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v2
with:
node-version-file: .node-version

- name: Install Prettier
run: |
PRETTIER_VERSION="$(node -p "require('./package.json').devDependencies.prettier")"
npm install --global "prettier@$PRETTIER_VERSION"
- name: Check Formatting
id: check
run: prettier --check .

- name: Reformat & Commit
if: ${{ failure() && steps.check.conclusion == 'failure' }}
run: |
prettier --list-different --write .
prettier --check .
if [[ $? -eq 0 ]]; then
echo "Looks good, pushing changes..."
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "GitHub Actions"
git add .
git commit -m "Reformat using Prettier"
git push
else
echo "Prettier failed to produce stable output, skipping!"
exit 1
fi

0 comments on commit 56874e0

Please sign in to comment.