From db0a92b8d4545f69fb6fac34cd1c72d356198e25 Mon Sep 17 00:00:00 2001 From: George <31376482+george-gca@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:01:55 -0300 Subject: [PATCH] Moved prettier comment on PR to its own action (#2114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: George Araรบjo --- .github/workflows/prettier-comment-on-pr.yml | 18 +++++++++ .github/workflows/prettier-on-push.yml | 38 ------------------- .../{prettier-on-pr.yml => prettier.yml} | 17 +++++---- 3 files changed, 28 insertions(+), 45 deletions(-) create mode 100644 .github/workflows/prettier-comment-on-pr.yml delete mode 100644 .github/workflows/prettier-on-push.yml rename .github/workflows/{prettier-on-pr.yml => prettier.yml} (74%) diff --git a/.github/workflows/prettier-comment-on-pr.yml b/.github/workflows/prettier-comment-on-pr.yml new file mode 100644 index 000000000000..e95075ce82e4 --- /dev/null +++ b/.github/workflows/prettier-comment-on-pr.yml @@ -0,0 +1,18 @@ +name: Comment on pull request + +on: + repository_dispatch: + types: [prettier-failed-on-pr] + +jobs: + comment: + # available images: https://github.com/actions/runner-images#available-images + runs-on: ubuntu-latest + steps: + - name: PR comment with html diff ๐Ÿ’ฌ + uses: thollander/actions-comment-pull-request@v2 + with: + comment_tag: prettier-failed + pr_number: ${{ github.event.client_payload.pr_number }} + message: | + Failed [prettier code check](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.client_payload.run_id }}). Check [this file](${{ github.event.client_payload.artifact_url }}) for more information. diff --git a/.github/workflows/prettier-on-push.yml b/.github/workflows/prettier-on-push.yml deleted file mode 100644 index 0f44155d98bb..000000000000 --- a/.github/workflows/prettier-on-push.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Prettier code formatter (push) - -on: - push: - 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 diff --git a/.github/workflows/prettier-on-pr.yml b/.github/workflows/prettier.yml similarity index 74% rename from .github/workflows/prettier-on-pr.yml rename to .github/workflows/prettier.yml index 5892844f941a..60446c8db359 100644 --- a/.github/workflows/prettier-on-pr.yml +++ b/.github/workflows/prettier.yml @@ -1,10 +1,14 @@ -name: Prettier code formatter (PR) +name: Prettier code formatter on: pull_request: branches: - master - main + push: + branches: + - master + - main jobs: check: @@ -36,10 +40,9 @@ jobs: 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 + - name: Dispatch information to repository ๐Ÿ—ฃ๏ธ + if: ${{ failure() && steps.prettier.conclusion == 'failure' && github.event_name == 'pull_request' }} + uses: peter-evans/repository-dispatch@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. + event-type: prettier-failed-on-pr + client-payload: '{"pr_number": "${{ github.event.number }}", "artifact_url": "${{ steps.artifact-upload.outputs.artifact-url }}", "run_id": "${{ github.run_id }}"}'