diff --git a/.github/workflows/analyze.yml b/.github/workflows/analyze.yml index c447a2cdb6a..075bd489ea3 100644 --- a/.github/workflows/analyze.yml +++ b/.github/workflows/analyze.yml @@ -8,6 +8,20 @@ on: workflow_dispatch: jobs: + event_type: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Save Event Type + run: echo ${{ github.event_name }} > ./event_type + + - name: Upload Event Type + uses: actions/upload-artifact@v2 + with: + path: ./event_type + name: event_type + analyze: runs-on: ubuntu-latest steps: @@ -48,10 +62,10 @@ jobs: - name: Download base branch bundle stats uses: dawidd6/action-download-artifact@v2 - if: success() && github.event.number + if: success() with: workflow: analyze.yml - branch: ${{ github.event.pull_request.base.ref }} + branch: ${{ github.event.pull_request.base.ref || 'main' }} name: bundle_analysis.json path: .next/analyze/base/bundle @@ -69,7 +83,7 @@ jobs: # 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 + if: success() run: ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare - name: Upload analysis comment @@ -77,6 +91,13 @@ jobs: with: name: analysis_comment.txt path: .next/analyze/__bundle_analysis_comment.txt + + number: + runs-on: ubuntu-latest + needs: analyze + if: github.event_name == 'pull_request' + steps: + - uses: actions/checkout@v2 - name: Save PR number run: echo ${{ github.event.number }} > ./pr_number diff --git a/.github/workflows/analyze_comment.yml b/.github/workflows/analyze_comment.yml index bd73b6b4ea3..60b3b4f34f8 100644 --- a/.github/workflows/analyze_comment.yml +++ b/.github/workflows/analyze_comment.yml @@ -9,11 +9,23 @@ on: jobs: comment: runs-on: ubuntu-latest - if: > - ${{ github.event.workflow_run.event == 'pull_request' && - github.event.workflow_run.conclusion == 'success' }} steps: + - name: Download Event Type + uses: dawidd6/action-download-artifact@v2 + with: + workflow: analyze.yml + run_id: ${{ github.event.workflow_run.id }} + name: event_type + path: event_type + + - name: get type + id: get-type + run: | + event_type=$(cat event_type/event_type) + echo "event-type=$event_type" >> $GITHUB_OUTPUT + - name: Download base branch bundle stats + if: github.event.workflow_run.conclusion == 'success' && steps.get-type.outputs.event-type == 'pull_request' uses: dawidd6/action-download-artifact@v2 with: workflow: analyze.yml @@ -22,6 +34,7 @@ jobs: path: analysis_comment.txt - name: Download PR number + if: github.event.workflow_run.conclusion == 'success' && steps.get-type.outputs.event-type == 'pull_request' uses: dawidd6/action-download-artifact@v2 with: workflow: analyze.yml @@ -31,7 +44,7 @@ jobs: - name: Get comment body id: get-comment-body - if: success() + if: success() && github.event.workflow_run.conclusion == 'success' && steps.get-type.outputs.event-type == 'pull_request' run: | echo 'body<> $GITHUB_OUTPUT echo '' >> $GITHUB_OUTPUT @@ -49,7 +62,7 @@ jobs: - name: Find Comment uses: peter-evans/find-comment@v1 - if: success() + if: success() && github.event.workflow_run.conclusion == 'success' && steps.get-type.outputs.event-type == 'pull_request' id: fc with: issue-number: ${{ steps.get-comment-body.outputs.pr-number }} @@ -57,14 +70,14 @@ jobs: - name: Create Comment uses: peter-evans/create-or-update-comment@v1.4.4 - if: success() && steps.fc.outputs.comment-id == 0 + if: success() && steps.fc.outputs.comment-id == 0 && github.event.workflow_run.conclusion == 'success' && steps.get-type.outputs.event-type == 'pull_request' with: issue-number: ${{ steps.get-comment-body.outputs.pr-number }} body: ${{ steps.get-comment-body.outputs.body }} - name: Update Comment uses: peter-evans/create-or-update-comment@v1.4.4 - if: success() && steps.fc.outputs.comment-id != 0 + if: success() && steps.fc.outputs.comment-id != 0 && github.event.workflow_run.conclusion == 'success' && steps.get-type.outputs.event-type == 'pull_request' with: issue-number: ${{ steps.get-comment-body.outputs.pr-number }} body: ${{ steps.get-comment-body.outputs.body }}