From 57298fe37aefbf055717d4705eba836d7d8c6984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?George=20Ara=C3=BAjo?= Date: Tue, 16 Jan 2024 11:43:37 -0300 Subject: [PATCH 1/4] Prettier check now generates a diff comment on PR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: George Araรบjo --- .github/workflows/prettier.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml index c71cd3939580..b24fdb6d0765 100644 --- a/.github/workflows/prettier.yml +++ b/.github/workflows/prettier.yml @@ -1,5 +1,8 @@ name: Prettier code formatter + + + on: push: branches: @@ -23,4 +26,20 @@ jobs: - 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: Show diff ๐Ÿ“ + # https://docs.github.com/en/actions/learn-github-actions/expressions#failure + if: ${{ failure() }} + run: | + npx prettier . --write + git diff > diff.txt + npm install -g diff2html-cli + diff2html -i file -s side -F diff.html -- diff.txt + echo "::set-output name=diff::$(cat diff.html)" + - name: PR comment with file + # 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 \ No newline at end of file From 0f943ac103af2183c41d506dc010591d0bd0b42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?George=20Ara=C3=BAjo?= Date: Tue, 16 Jan 2024 14:36:07 -0300 Subject: [PATCH 2/4] Splitted prettier action into on PR and on push MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: George Araรบjo --- .../{prettier.yml => prettier-on-pr.yml} | 16 ++------ .github/workflows/prettier-on-push.yml | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 12 deletions(-) rename .github/workflows/{prettier.yml => prettier-on-pr.yml} (82%) create mode 100644 .github/workflows/prettier-on-push.yml diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier-on-pr.yml similarity index 82% rename from .github/workflows/prettier.yml rename to .github/workflows/prettier-on-pr.yml index b24fdb6d0765..84928c9f150c 100644 --- a/.github/workflows/prettier.yml +++ b/.github/workflows/prettier-on-pr.yml @@ -1,13 +1,6 @@ -name: Prettier code formatter - - - +name: Prettier code formatter (PR) on: - push: - branches: - - master - - main pull_request: branches: - master @@ -33,13 +26,12 @@ jobs: if: ${{ failure() }} run: | npx prettier . --write - git diff > diff.txt + 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 - echo "::set-output name=diff::$(cat diff.html)" - - name: PR comment with file + - 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 \ No newline at end of file + filePath: diff.html diff --git a/.github/workflows/prettier-on-push.yml b/.github/workflows/prettier-on-push.yml new file mode 100644 index 000000000000..76673d619973 --- /dev/null +++ b/.github/workflows/prettier-on-push.yml @@ -0,0 +1,38 @@ +name: Prettier code formatter (Push) + +on: + push: + branches: + - master + - main + workflow_dispatch: + +jobs: + check: + # available images: https://github.com/actions/runner-images#available-images + runs-on: ubuntu-latest + steps: + - name: Checkout ๐Ÿ›Ž๏ธ + uses: actions/checkout@v3 + - 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: Show 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 + if: ${{ failure() && steps.prettier.conclusion == 'failure' }} + uses: actions/upload-artifact@v3 + with: + name: HTML Diff + path: diff.html + retention-days: 3 From 0042fd6969d37883e81d621657325acba411f024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?George=20Ara=C3=BAjo?= Date: Tue, 16 Jan 2024 14:46:24 -0300 Subject: [PATCH 3/4] Upgraded upload artifact to v4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: George Araรบjo --- .github/workflows/prettier-on-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/prettier-on-push.yml b/.github/workflows/prettier-on-push.yml index 76673d619973..d01662debf10 100644 --- a/.github/workflows/prettier-on-push.yml +++ b/.github/workflows/prettier-on-push.yml @@ -31,7 +31,7 @@ jobs: diff2html -i file -s side -F diff.html -- diff.txt - name: Upload html diff if: ${{ failure() && steps.prettier.conclusion == 'failure' }} - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: HTML Diff path: diff.html From 9109b4fc3ee8391473a365af3d0bca7db743a6b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?George=20Ara=C3=BAjo?= Date: Mon, 22 Jan 2024 16:09:59 -0300 Subject: [PATCH 4/4] Bumped checkout step action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: George Araรบjo --- .github/workflows/prettier-on-pr.yml | 2 +- .github/workflows/prettier-on-push.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/prettier-on-pr.yml b/.github/workflows/prettier-on-pr.yml index 84928c9f150c..5bb850ddf361 100644 --- a/.github/workflows/prettier-on-pr.yml +++ b/.github/workflows/prettier-on-pr.yml @@ -21,7 +21,7 @@ jobs: - name: Prettier Check ๐Ÿ”Ž id: prettier run: npx prettier . --check - - name: Show diff ๐Ÿ“ + - name: Create diff ๐Ÿ“ # https://docs.github.com/en/actions/learn-github-actions/expressions#failure if: ${{ failure() }} run: | diff --git a/.github/workflows/prettier-on-push.yml b/.github/workflows/prettier-on-push.yml index d01662debf10..719757daea1c 100644 --- a/.github/workflows/prettier-on-push.yml +++ b/.github/workflows/prettier-on-push.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout ๐Ÿ›Ž๏ธ - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Node.js โš™๏ธ uses: actions/setup-node@v4 - name: Install Prettier ๐Ÿ’พ @@ -21,7 +21,7 @@ jobs: - name: Prettier Check ๐Ÿ”Ž id: prettier run: npx prettier . --check - - name: Show diff ๐Ÿ“ + - name: Create diff ๐Ÿ“ # https://docs.github.com/en/actions/learn-github-actions/expressions#failure if: ${{ failure() }} run: |