Skip to content

Commit bf5fe5c

Browse files
fix(gh-workflow): skip comment when push directly
1 parent 19c0fe2 commit bf5fe5c

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

.github/workflows/analyze.yml

+24-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ on:
88
workflow_dispatch:
99

1010
jobs:
11+
event_type:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Save Event Type
17+
run: echo ${{ github.event_name }} > ./event_type
18+
19+
- name: Upload Event Type
20+
uses: actions/upload-artifact@v2
21+
with:
22+
path: ./event_type
23+
name: event_type
24+
1125
analyze:
1226
runs-on: ubuntu-latest
1327
steps:
@@ -48,10 +62,10 @@ jobs:
4862

4963
- name: Download base branch bundle stats
5064
uses: dawidd6/action-download-artifact@v2
51-
if: success() && github.event.number
65+
if: success()
5266
with:
5367
workflow: analyze.yml
54-
branch: ${{ github.event.pull_request.base.ref }}
68+
branch: ${{ github.event.pull_request.base.ref || 'main' }}
5569
name: bundle_analysis.json
5670
path: .next/analyze/base/bundle
5771

@@ -69,14 +83,21 @@ jobs:
6983
# Either of these arguments can be changed or removed by editing the `nextBundleAnalysis`
7084
# entry in your package.json file.
7185
- name: Compare with base branch bundle
72-
if: success() && github.event.number
86+
if: success()
7387
run: ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare
7488

7589
- name: Upload analysis comment
7690
uses: actions/upload-artifact@v2
7791
with:
7892
name: analysis_comment.txt
7993
path: .next/analyze/__bundle_analysis_comment.txt
94+
95+
number:
96+
runs-on: ubuntu-latest
97+
needs: analyze
98+
if: github.event_name == 'pull_request'
99+
steps:
100+
- uses: actions/checkout@v2
80101

81102
- name: Save PR number
82103
run: echo ${{ github.event.number }} > ./pr_number

.github/workflows/analyze_comment.yml

+17-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,23 @@ on:
99
jobs:
1010
comment:
1111
runs-on: ubuntu-latest
12-
if: >
13-
${{ github.event.workflow_run.event == 'pull_request' &&
14-
github.event.workflow_run.conclusion == 'success' }}
1512
steps:
13+
- name: Download Event Type
14+
uses: dawidd6/action-download-artifact@v2
15+
with:
16+
workflow: analyze.yml
17+
run_id: ${{ github.event.workflow_run.id }}
18+
name: event_type
19+
path: event_type
20+
21+
- name: get type
22+
id: get-type
23+
run: |
24+
event_type=$(cat event_type/event_type)
25+
echo "event-type=$event_type" >> $GITHUB_OUTPUT
26+
1627
- name: Download base branch bundle stats
28+
if: github.event.workflow_run.conclusion == 'success' && steps.get-type.outputs.event-type == 'pull_request'
1729
uses: dawidd6/action-download-artifact@v2
1830
with:
1931
workflow: analyze.yml
@@ -22,6 +34,7 @@ jobs:
2234
path: analysis_comment.txt
2335

2436
- name: Download PR number
37+
if: github.event.workflow_run.conclusion == 'success' && steps.get-type.outputs.event-type == 'pull_request'
2538
uses: dawidd6/action-download-artifact@v2
2639
with:
2740
workflow: analyze.yml
@@ -31,7 +44,7 @@ jobs:
3144

3245
- name: Get comment body
3346
id: get-comment-body
34-
if: success()
47+
if: success() && github.event.workflow_run.conclusion == 'success' && steps.get-type.outputs.event-type == 'pull_request'
3548
run: |
3649
echo 'body<<EOF' >> $GITHUB_OUTPUT
3750
echo '' >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)