Skip to content

Commit cf2227a

Browse files
Fix artifact downloading in size-comment.yml (#20887)
* AHHHHH * Test empty commit * Test empty commit * Test empty commit * Trigger Main CI * Test empty commit * Allow workflow_dispatch * Test empty commit * fix * Test empty commit * Fix run-id * what * what * AHHHH * AHHHH * AHHHH * AHHHH * AHHHH * AHHHH * AHHHH * AHHHH * AHHHH * Fix PR number saving * AHHHH * AHHHH * AHHHH * AHHHH * AHHHH * AHHHH * ope * All * Shrink output * Fix paths
1 parent 8548d45 commit cf2227a

File tree

3 files changed

+75
-25
lines changed

3 files changed

+75
-25
lines changed

.github/workflows/size-comment.yml

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,101 @@ name: "Size: Comment"
55
#
66
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
77
on:
8+
workflow_dispatch:
9+
inputs:
10+
RUN_ID:
11+
description: Which workflow run to get artifacts from
12+
required: true
13+
type: string
814
workflow_run:
915
workflows: ["Size: PR"]
1016
types:
1117
- completed
1218

19+
permissions:
20+
contents: read
21+
issues: write
22+
pull-requests: write
23+
1324
jobs:
1425
compare_sizes:
1526
name: 'Compare Sizes and Comment'
1627
runs-on: 'ubuntu-latest'
1728

1829
steps:
30+
# better `du`
1931
- run: sudo snap install dust
2032

21-
- uses: actions/download-artifact@v4
33+
- uses: dawidd6/action-download-artifact@v9
2234
with:
23-
name: pr-${{ github.event.workflow_run.id }}
35+
run_id: ${{ inputs.RUN_ID || github.event.workflow_run.id }}
36+
workflow: size-pr.yml
37+
path: pr
38+
if_no_artifact_found: fail
2439

25-
- uses: actions/download-artifact@v4
40+
- uses: dawidd6/action-download-artifact@v9
2641
with:
2742
name: sizes-main
43+
path: main
44+
workflow: size-main.yml
45+
if_no_artifact_found: fail
2846

29-
- name: "[PR] Get sizes for development outputs"
30-
id: dev
47+
- name: "[Debug] artifacts' files"
48+
run: |
49+
ls -la ./main
50+
ls -la ./pr/**
51+
52+
- name: "[PR] Get path of size output txt file"
53+
id: find-pr-txt
3154
run: |
3255
cd pr/
56+
filePath=$(find . -name "out.txt")
57+
echo $filePath
58+
echo "txtPath=pr/$filePath" >> $GITHUB_OUTPUT
3359
60+
- name: "[PR] Get PR number"
61+
id: find-pr-number
62+
run: |
63+
cd pr/
64+
filePath=$(find . -name "NR")
65+
contents=$(cat $filePath)
66+
echo $filePath
67+
echo $contents
68+
echo "prNumber=$contents" >> $GITHUB_OUTPUT
69+
70+
- name: "[PR] Get sizes for development outputs"
71+
id: dev
72+
run: |
73+
cat ${{ steps.find-pr-txt.outputs.txtPath }}
3474
echo 'sizes<<EOF' >> $GITHUB_OUTPUT
3575
while IFS= read -r line; do
3676
echo "$line" >> $GITHUB_OUTPUT
37-
done <<< $(cat out.txt)
77+
done <<< $(cat ${{ steps.find-pr-txt.outputs.txtPath }})
3878
echo 'EOF' >> $GITHUB_OUTPUT
39-
cat out.txt
40-
41-
- name: "[PR]: Get PR Number"
42-
id: pr-number
43-
run: echo "number=$(cat pr/NR)" >> $GITHUB_OUTPUT
4479
4580
- name: "[Main] Get sizes for development outputs"
4681
id: main-dev
4782
run: |
4883
cd main/
84+
cat out.txt
4985
5086
echo 'sizes<<EOF' >> $GITHUB_OUTPUT
5187
while IFS= read -r line; do
5288
echo "$line" >> $GITHUB_OUTPUT
5389
done <<< $(cat out.txt)
5490
echo 'EOF' >> $GITHUB_OUTPUT
55-
cat out.txt
91+
92+
93+
- name: "[Debug] collected data from artifacts"
94+
run: |
95+
echo "PR number"
96+
echo -e "${{ steps.find-pr-number.outputs.prNumber }}"
97+
98+
echo "Main out.txt"
99+
echo -e "${{ steps.main-dev.outputs.sizes }}"
100+
101+
echo "PR out.txt"
102+
echo -e "${{ steps.dev.outputs.sizes }}"
56103
57104
#########################
58105
# Intended Layout:
@@ -68,7 +115,7 @@ jobs:
68115
#########################
69116
- uses: mshick/add-pr-comment@v2
70117
with:
71-
issue: ${{ steps.pr-number.outputs.number }}
118+
issue: ${{ steps.find-pr-number.outputs.prNumber }}
72119
message: |
73120
<table><thead><tr><th></th><th>This PR</th><th>main</th></tr></thead>
74121
<tbody>

.github/workflows/size-main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ jobs:
2020
id: main-dev
2121
run: |
2222
mkdir -p main
23-
cd dist
23+
cd dist/packages
2424
dust --ignore_hidden \
2525
--reverse --apparent-size \
26-
--filter ".+.js$" \
2726
--no-percent-bars \
28-
--only-file \
29-
--full-paths > out.txt
30-
cp out.txt ../main/
27+
--only-dir \
28+
--depth 20 \
29+
> out.txt
30+
cp out.txt ../../main/
3131
3232
3333
- uses: actions/upload-artifact@v4

.github/workflows/size-pr.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Do a build
44
# Measure assets sizes
55
# Upload artifact
6-
# Consumed by size.yml for comparison
6+
# Consumed by size-comment.yml for comparison
77
name: "Size: PR"
88

99
# read-only repo token
@@ -24,23 +24,26 @@ jobs:
2424
- name: Save PR number
2525
run: |
2626
mkdir -p ./pr
27-
echo ${{ github.event.number }} > ./pr/NR
27+
echo "${{ github.event.number }}" > ./pr/NR
2828
2929
- name: "Get sizes for development outputs"
3030
id: dev
3131
run: |
32-
cd dist
32+
cd dist/packages
3333
dust --ignore_hidden \
3434
--reverse --apparent-size \
35-
--filter ".+.js$" \
3635
--no-percent-bars \
37-
--only-file \
38-
--full-paths > out.txt
39-
cp out.txt ../pr/
36+
--only-dir \
37+
--depth 20 \
38+
> out.txt
39+
cp out.txt ../../pr/
4040
4141
4242
- uses: actions/upload-artifact@v4
4343
with:
4444
name: pr-${{ github.run_id }}
4545
path: pr/
4646
overwrite: true
47+
# This artifact should be read immediately by
48+
# size-comment.yml upon completion
49+
retention-days: 1

0 commit comments

Comments
 (0)