Skip to content

Commit 435ddf9

Browse files
committed
Updated prettier workflows
Signed-off-by: George Araújo <[email protected]>
1 parent b2ee83a commit 435ddf9

File tree

3 files changed

+50
-32
lines changed

3 files changed

+50
-32
lines changed

.github/workflows/prettier-comment-on-pr.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/workflows/prettier.yml renamed to .github/workflows/prettier-on-pr.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
name: Prettier code formatter
1+
name: Prettier code formatter (PR)
22

33
on:
44
pull_request:
55
branches:
66
- master
77
- main
8-
push:
9-
branches:
10-
- master
11-
- main
128

139
jobs:
1410
check:
@@ -32,17 +28,19 @@ jobs:
3228
git diff -- . ':(exclude)package-lock.json' ':(exclude)package.json' > diff.txt
3329
npm install -g diff2html-cli
3430
diff2html -i file -s side -F diff.html -- diff.txt
35-
- name: Upload html diff
36-
id: artifact-upload-step
31+
- name: Upload html diff ⬆️
32+
id: artifact-upload
3733
if: ${{ failure() && steps.prettier.conclusion == 'failure' }}
3834
uses: actions/upload-artifact@v4
3935
with:
40-
name: HTML_Diff
36+
name: HTML Diff
4137
path: diff.html
42-
retention-days: 3
43-
- name: Dispatch information to repository
44-
if: ${{ failure() && steps.prettier.conclusion == 'failure' && github.event_name == 'pull_request' }}
45-
uses: peter-evans/repository-dispatch@v2
38+
retention-days: 7
39+
- name: PR comment with diff 💬
40+
if: ${{ failure() && steps.prettier.conclusion == 'failure' }}
41+
uses: thollander/actions-comment-pull-request@v2
4642
with:
47-
event-type: prettier-failed-on-pr
48-
client-payload: '{"pr_number": "${{ github.event.number }}", "artifact_url": "${{ steps.artifact-upload-step.outputs.artifact-url }}"}'
43+
comment_tag: prettier-failed
44+
message: |
45+
Failed [prettier code check](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).
46+
Check [this file](${{ steps.artifact-upload.outputs.artifact-url }}) for more information.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Prettier code formatter (push)
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
9+
jobs:
10+
check:
11+
# available images: https://github.com/actions/runner-images#available-images
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout 🛎️
15+
uses: actions/checkout@v4
16+
- name: Setup Node.js ⚙️
17+
uses: actions/setup-node@v4
18+
- name: Install Prettier 💾
19+
run: npm install --save-dev --save-exact prettier @shopify/prettier-plugin-liquid
20+
- name: Prettier Check 🔎
21+
id: prettier
22+
run: npx prettier . --check
23+
- name: Create diff 📝
24+
# https://docs.github.com/en/actions/learn-github-actions/expressions#failure
25+
if: ${{ failure() }}
26+
run: |
27+
npx prettier . --write
28+
git diff -- . ':(exclude)package-lock.json' ':(exclude)package.json' > diff.txt
29+
npm install -g diff2html-cli
30+
diff2html -i file -s side -F diff.html -- diff.txt
31+
- name: Upload html diff ⬆️
32+
id: artifact-upload
33+
if: ${{ failure() && steps.prettier.conclusion == 'failure' }}
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: HTML Diff
37+
path: diff.html
38+
retention-days: 7

0 commit comments

Comments
 (0)