Skip to content

fix(gh-workflow): skip comment when push directly #5860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
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
27 changes: 24 additions & 3 deletions .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
@@ -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,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
27 changes: 20 additions & 7 deletions .github/workflows/analyze_comment.yml
Original file line number Diff line number Diff line change
@@ -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<<EOF' >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
@@ -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/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 }}