-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
33 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 |
---|---|---|
@@ -1,12 +1,6 @@ | ||
name: Prettier | ||
name: Prettier Check and Format | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
prettier: | ||
|
@@ -17,36 +11,23 @@ jobs: | |
uses: actions/checkout@v2 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "18" | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
node_modules | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
node-${{ runner.os }}- | ||
node-version: '18' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run Prettier | ||
run: npx prettier --write . | ||
- name: Check for unformatted code | ||
run: npx prettier --check .' | ||
|
||
- name: Format code | ||
run: npx prettier --write .' | ||
|
||
- name: Check for changes | ||
- name: Commit and push changes | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git pull | ||
git config user.name "GitHub Actions" | ||
git config user.email "[email protected]" | ||
git add . | ||
git diff --exit-code --quiet || git commit -m "Run Prettier" | ||
- name: Push changes | ||
if: github.event_name == 'push' | ||
uses: ad-m/[email protected] | ||
with: | ||
branch: main | ||
github_token: ${{ secrets.PUSH_TOKEN }} | ||
git commit -m "Format code with Prettier" | ||
git push |