-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a workflow that runs Prettier and auto-fixes any issues
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 |