Skip to content

Commit

Permalink
Fixed prettier actions (#2113)
Browse files Browse the repository at this point in the history
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 <george.gcac@gmail.com>
  • Loading branch information
george-gca authored Jan 22, 2024
1 parent 27d2fa0 commit bbaae0a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 50 deletions.
43 changes: 0 additions & 43 deletions .github/workflows/prettier-comment-on-pr.yml

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/prettier-on-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Prettier code formatter (PR)

on:
pull_request:
branches:
- master
- main

jobs:
check:
# available images: https://github.com/actions/runner-images#available-images
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
- name: Setup Node.js ⚙️
uses: actions/setup-node@v4
- name: Install Prettier 💾
run: npm install --save-dev --save-exact prettier @shopify/prettier-plugin-liquid
- name: Prettier Check 🔎
id: prettier
run: npx prettier . --check
- name: Create diff 📝
# https://docs.github.com/en/actions/learn-github-actions/expressions#failure
if: ${{ failure() }}
run: |
npx prettier . --write
git diff -- . ':(exclude)package-lock.json' ':(exclude)package.json' > diff.txt
npm install -g diff2html-cli
diff2html -i file -s side -F diff.html -- diff.txt
- name: Upload html diff ⬆️
id: artifact-upload
if: ${{ failure() && steps.prettier.conclusion == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: HTML Diff
path: diff.html
retention-days: 7
- name: PR comment with diff 💬
if: ${{ failure() && steps.prettier.conclusion == 'failure' }}
uses: thollander/actions-comment-pull-request@v2
with:
comment_tag: prettier-failed
message: |
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.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Prettier code formatter
name: Prettier code formatter (push)

on:
pull_request:
branches:
- master
- main
push:
branches:
- master
Expand Down Expand Up @@ -32,10 +28,11 @@ jobs:
git diff -- . ':(exclude)package-lock.json' ':(exclude)package.json' > diff.txt
npm install -g diff2html-cli
diff2html -i file -s side -F diff.html -- diff.txt
- name: Upload html diff
- name: Upload html diff ⬆️
id: artifact-upload
if: ${{ failure() && steps.prettier.conclusion == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: HTML Diff
path: diff.html
retention-days: 3
retention-days: 7

0 comments on commit bbaae0a

Please sign in to comment.