Skip to content

Commit bbaae0a

Browse files
authored
Fixed prettier actions (cotes2020#2113)
After some thorough testing, finally made prettier on PR work. Since an html file can't be used as comment on GitHub, changed to simply point to the action that failed and to the file containing the html diff. Signed-off-by: George Araújo <[email protected]>
1 parent 27d2fa0 commit bbaae0a

File tree

3 files changed

+49
-50
lines changed

3 files changed

+49
-50
lines changed

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

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Prettier code formatter (PR)
2+
3+
on:
4+
pull_request:
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
39+
- name: PR comment with diff 💬
40+
if: ${{ failure() && steps.prettier.conclusion == 'failure' }}
41+
uses: thollander/actions-comment-pull-request@v2
42+
with:
43+
comment_tag: prettier-failed
44+
message: |
45+
Failed [prettier code check](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). Check [this file](${{ steps.artifact-upload.outputs.artifact-url }}) for more information.

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
name: Prettier code formatter
1+
name: Prettier code formatter (push)
22

33
on:
4-
pull_request:
5-
branches:
6-
- master
7-
- main
84
push:
95
branches:
106
- master
@@ -32,10 +28,11 @@ 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
31+
- name: Upload html diff ⬆️
32+
id: artifact-upload
3633
if: ${{ failure() && steps.prettier.conclusion == 'failure' }}
3734
uses: actions/upload-artifact@v4
3835
with:
3936
name: HTML Diff
4037
path: diff.html
41-
retention-days: 3
38+
retention-days: 7

0 commit comments

Comments
 (0)