Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -69,14 +83,21 @@ 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
uses: actions/upload-artifact@v2
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
Expand All @@ -89,3 +110,4 @@ jobs:

# The actual commenting happens in the other action, matching the guidance in
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/

27 changes: 20 additions & 7 deletions .github/workflows/analyze_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<<EOF' >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
Expand All @@ -49,22 +62,22 @@ 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 }}
body-includes: "<!-- __NEXTJS_BUNDLE -->"

- name: Create Comment
uses: peter-evans/[email protected]
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/[email protected]
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 }}
Expand Down