From 5c965cf77fc3efdc6078dd5d31018d261002a01d Mon Sep 17 00:00:00 2001 From: claustra01 Date: Sat, 10 Aug 2024 01:40:16 +0900 Subject: [PATCH] add: analyze ci --- .github/workflows/pr-analyze.yml | 58 ++++++++++++++++++++++++++++++++ package.json | 8 ++++- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pr-analyze.yml diff --git a/.github/workflows/pr-analyze.yml b/.github/workflows/pr-analyze.yml new file mode 100644 index 0000000..126831b --- /dev/null +++ b/.github/workflows/pr-analyze.yml @@ -0,0 +1,58 @@ +name: analyze + +on: + pull_request: + +jobs: + analyze: + needs: build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - run: | + npm install + npm run build + npx -p nextjs-bundle-analysis report + + - name: Upload bundle + uses: actions/upload-artifact@v3 + with: + name: bundle + path: .next/analyze/__bundle_analysis.json + + - name: Download base branch bundle stats + uses: dawidd6/action-download-artifact@v2 + if: success() && github.event.number + with: + workflow: nextjs_bundle_analysis.yml + branch: ${{ github.event.pull_request.base.ref }} + path: .next/analyze/base + + - 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 + 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 + with: + issue-number: ${{ github.event.number }} + body-includes: '' + + - 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 }} diff --git a/package.json b/package.json index 052b607..b32e7ba 100644 --- a/package.json +++ b/package.json @@ -29,5 +29,11 @@ "eslint-plugin-react-refresh": "^0.4.7", "typescript": "^5.2.2", "vite": "^5.3.4" + }, + "nextBundleAnalysis": { + "budget": 358400, + "budgetPercentIncreaseRed": 20, + "minimumChangeThreshold": 0, + "showDetails": true } -} +} \ No newline at end of file