diff --git a/.github/workflows/prettier-comment-on-pr.yml b/.github/workflows/prettier-comment-on-pr.yml new file mode 100644 index 000000000000..e3d5640496f9 --- /dev/null +++ b/.github/workflows/prettier-comment-on-pr.yml @@ -0,0 +1,43 @@ +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 deleted file mode 100644 index 320df2f5290d..000000000000 --- a/.github/workflows/prettier-on-pr.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Prettier code formatter (PR) - -on: - pull_request: - branches: - - master - - main - workflow_dispatch: - -permissions: - pull-requests: write - -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: PR comment with html diff - # https://docs.github.com/en/actions/learn-github-actions/expressions#failure-with-conditions - if: ${{ failure() && steps.prettier.conclusion == 'failure' }} - uses: thollander/actions-comment-pull-request@v2 - with: - filePath: diff.html diff --git a/.github/workflows/prettier-on-push.yml b/.github/workflows/prettier.yml similarity index 92% rename from .github/workflows/prettier-on-push.yml rename to .github/workflows/prettier.yml index 719757daea1c..75b87f359c24 100644 --- a/.github/workflows/prettier-on-push.yml +++ b/.github/workflows/prettier.yml @@ -1,11 +1,14 @@ -name: Prettier code formatter (Push) +name: Prettier code formatter on: + pull_request: + branches: + - master + - main push: branches: - master - main - workflow_dispatch: jobs: check: