From e631a6efee3a553e7dddc593df44d8a523ff37a9 Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 28 Apr 2023 01:56:10 +0800 Subject: [PATCH] fix: next analyze ci (#437) --- .github/workflows/comment-pr.yml | 65 ++++++++++++++++++++ .github/workflows/nextjs_bundle_analysis.yml | 63 +++++-------------- 2 files changed, 81 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/comment-pr.yml diff --git a/.github/workflows/comment-pr.yml b/.github/workflows/comment-pr.yml new file mode 100644 index 00000000..68e68375 --- /dev/null +++ b/.github/workflows/comment-pr.yml @@ -0,0 +1,65 @@ +name: Comment on the pull request + +# read-write repo token +# access to secrets +on: + workflow_run: + workflows: ["Next.js Bundle Analysis"] + types: + - completed + +jobs: + upload: + runs-on: ubuntu-latest + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + steps: + - name: download pr artifact + uses: dawidd6/action-download-artifact@v2 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + name: pr + + - name: save PR id + id: pr + run: echo "::set-output name=id::$(> $GITHUB_OUTPUT + echo "$(cat .next/analyze/__bundle_analysis_comment.txt)" >> $GITHUB_OUTPUT + echo EOF >> $GITHUB_OUTPUT + + - name: Find Comment + uses: peter-evans/find-comment@v2 + if: success() && steps.pr.outputs.id + id: fc + with: + issue-number: ${{ steps.pr.outputs.id }} + body-includes: "" + + - name: Create Comment + uses: peter-evans/create-or-update-comment@v2 + if: success() && steps.pr.outputs.id && steps.fc.outputs.comment-id == 0 + with: + issue-number: ${{ steps.pr.outputs.id }} + body: ${{ steps.get-comment-body.outputs.body }} + + - name: Update Comment + uses: peter-evans/create-or-update-comment@v2 + if: success() && steps.pr.outputs.id && steps.fc.outputs.comment-id != 0 + with: + issue-number: ${{ steps.pr.outputs.id }} + body: ${{ steps.get-comment-body.outputs.body }} + comment-id: ${{ steps.fc.outputs.comment-id }} + edit-mode: replace \ No newline at end of file diff --git a/.github/workflows/nextjs_bundle_analysis.yml b/.github/workflows/nextjs_bundle_analysis.yml index 3903fda5..d4d3e319 100644 --- a/.github/workflows/nextjs_bundle_analysis.yml +++ b/.github/workflows/nextjs_bundle_analysis.yml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - name: "Next.js Bundle Analysis" on: @@ -17,10 +14,10 @@ defaults: # change this if your nextjs app does not live at the root of the repo working-directory: ./ -permissions: - contents: read # for checkout repository - actions: read # for fetching base branch bundle stats - pull-requests: write # for comments +# permissions: +# contents: read # for checkout repository +# actions: read # for fetching base branch bundle stats +# pull-requests: write # for comments jobs: analyze: @@ -77,52 +74,24 @@ jobs: branch: ${{ github.event.pull_request.base.ref }} path: .next/analyze/base - # And here's the second place - this runs after we have both the current and - # base branch bundle stats, and will compare them to determine what changed. - # There are two configurable arguments that come from package.json: - # - # - budget: optional, set a budget (bytes) against which size changes are measured - # it's set to 350kb here by default, as informed by the following piece: - # https://infrequently.org/2021/03/the-performance-inequality-gap/ - # - # - red-status-percentage: sets the percent size increase where you get a red - # status indicator, defaults to 20% - # - # Either of these arguments can be changed or removed by editing the `nextBundleAnalysis` - # entry in your package.json file. - name: Compare with base branch bundle if: success() && github.event.number run: ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare - - name: Get Comment Body - id: get-comment-body + - name: Upload analysis if: success() && github.event.number - # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings - run: | - echo "body<> $GITHUB_OUTPUT - echo "$(cat .next/analyze/__bundle_analysis_comment.txt)" >> $GITHUB_OUTPUT - echo EOF >> $GITHUB_OUTPUT - - - name: Find Comment - uses: peter-evans/find-comment@v2 - if: success() && github.event.number - id: fc + uses: actions/upload-artifact@v2 with: - issue-number: ${{ github.event.number }} - body-includes: "" + name: analysis_comment + path: .next/analyze/__bundle_analysis_comment.txt - - name: Create Comment - uses: peter-evans/create-or-update-comment@v2 - if: success() && github.event.number && steps.fc.outputs.comment-id == 0 - with: - issue-number: ${{ github.event.number }} - body: ${{ steps.get-comment-body.outputs.body }} + - name: Save PR number + if: ${{ always() }} + run: echo ${{ github.event.number }} > ./pr-id.txt - - name: Update Comment - uses: peter-evans/create-or-update-comment@v2 - if: success() && github.event.number && steps.fc.outputs.comment-id != 0 + - name: Upload PR number + if: ${{ always() }} + uses: actions/upload-artifact@v2 with: - issue-number: ${{ github.event.number }} - body: ${{ steps.get-comment-body.outputs.body }} - comment-id: ${{ steps.fc.outputs.comment-id }} - edit-mode: replace + name: pr + path: ./pr-id.txt \ No newline at end of file