From 0225e416a37691af20415dc62278b5d7b15275e5 Mon Sep 17 00:00:00 2001 From: George <31376482+george-gca@users.noreply.github.com> Date: Mon, 22 Jan 2024 17:45:34 -0300 Subject: [PATCH] Fixed prettier actions (#2113) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .github/workflows/prettier-comment-on-pr.yml | 43 ------------------ .github/workflows/prettier-on-pr.yml | 45 +++++++++++++++++++ .../{prettier.yml => prettier-on-push.yml} | 11 ++--- 3 files changed, 49 insertions(+), 50 deletions(-) delete mode 100644 .github/workflows/prettier-comment-on-pr.yml create mode 100644 .github/workflows/prettier-on-pr.yml rename .github/workflows/{prettier.yml => prettier-on-push.yml} (88%) diff --git a/.github/workflows/prettier-comment-on-pr.yml b/.github/workflows/prettier-comment-on-pr.yml deleted file mode 100644 index e3d5640496f9..000000000000 --- a/.github/workflows/prettier-comment-on-pr.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Comment on pull request - -on: - workflow_run: - workflows: [Prettier code formatter] - types: - - completed - -jobs: - comment: - # available images: https://github.com/actions/runner-images#available-images - runs-on: ubuntu-latest - if: > - github.event.workflow_run.event == 'pull_request' && - github.event.workflow_run.conclusion == 'failure' - steps: - - name: Download artifact - uses: actions/github-script@v7 - with: - script: | - var artifacts = await github.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: ${{github.event.workflow_run.id }}, - }); - var matchArtifact = artifacts.data.artifacts.filter((artifact) => { - return artifact.name == "HTML Diff" - })[0]; - var download = await github.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact.id, - archive_format: 'zip', - }); - var fs = require('fs'); - fs.writeFileSync('${{github.workspace}}/HTML Diff.zip', Buffer.from(download.data)); - - name: Unzip artifact - run: unzip HTML\ Diff.zip - - name: PR comment with html diff - # https://docs.github.com/en/actions/learn-github-actions/expressions#failure-with-conditions - uses: thollander/actions-comment-pull-request@v2 - with: - filePath: diff.html diff --git a/.github/workflows/prettier-on-pr.yml b/.github/workflows/prettier-on-pr.yml new file mode 100644 index 000000000000..5892844f941a --- /dev/null +++ b/.github/workflows/prettier-on-pr.yml @@ -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. diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier-on-push.yml similarity index 88% rename from .github/workflows/prettier.yml rename to .github/workflows/prettier-on-push.yml index 75b87f359c24..0f44155d98bb 100644 --- a/.github/workflows/prettier.yml +++ b/.github/workflows/prettier-on-push.yml @@ -1,10 +1,6 @@ -name: Prettier code formatter +name: Prettier code formatter (push) on: - pull_request: - branches: - - master - - main push: branches: - master @@ -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