Skip to content

Commit

Permalink
ci: optimize prettier actions (#223)
Browse files Browse the repository at this point in the history
* Prevent GitHub actions running twice on same event
Fixes #221

* style: add new lines between actions steps for readability

* ci: upgrade node version

* ci: better branches syntax

* style: rm extra space in action step

* ci: skip installing dependencies

The package.json is anyway not in the root so it always failed.

It might be good to add it again after all source code is moved to the root. See #211

* ci: upgrade setup-node to v4

* ci: upgrade checkout to v4
  • Loading branch information
leeoocca authored Nov 21, 2024
1 parent 8c3ff16 commit e0a0033
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/prettier-format-check.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
name: Prettier Format Check

on: [push, pull_request]
on:
push:
branches:
- main
pull_request:

jobs:
prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '14'
- name: Install dependencies
run: npm install
node-version: "22"

- name: Run Prettier
id: prettier
run: npx prettier --config .prettierrc --check "**/*.{js,jsx,ts,tsx,html,css,scss}"

- name: Display Prettier Output
if: failure()
run: cat $GITHUB_WORKSPACE/.github/workflows/prettier.log
Expand Down
20 changes: 13 additions & 7 deletions .github/workflows/prettier-format-write.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,39 @@ jobs:
uses: xt0rted/pull-request-comment-branch@v2
if: github.event_name == 'issue_comment'
id: comment-branch

- name: Checkout Pull Request head ref
uses: actions/checkout@v3
uses: actions/checkout@v4
if: github.event_name == 'issue_comment'
with:
ref: ${{ steps.comment-branch.outputs.head_ref }}

- name: Checkout default head ref
uses: actions/checkout@v3
uses: actions/checkout@v4
if: github.event_name != 'issue_comment'

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '14'
- name: Install dependencies
run: npm install
node-version: "22"

- name: Configure GitHub Actions bot
run : |
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Run Prettier
id: prettier
run: npx prettier --config .prettierrc --write "**/*.{js,jsx,ts,tsx,html,css,scss}"

- name: Commit changes
run: |
git diff --exit-code || git commit -am "bot: apply Prettier formatting"
- name: Push changes
run: |
git push
- name: Comment reaction
if: github.event_name == 'issue_comment'
uses: dkershner6/[email protected]
Expand Down

0 comments on commit e0a0033

Please sign in to comment.