Skip to content

Commit fbcd8c8

Browse files
Port the sizes workflow from glimmer-vm (#20883)
* Port the sizes workflow from glimmer-vm * Explicity set permission * Adjust permissions * Use pull_request_target for safety * pull_requset_target => pull_request * Try to not be vulnerable to basic attacks in GH Actions * Don't upload the whole dist as an artifact * Cache main on main * Build on #main * Rename * Updates * Concat the run id * Fix path * Fix paths * paths
1 parent d568352 commit fbcd8c8

File tree

3 files changed

+178
-0
lines changed

3 files changed

+178
-0
lines changed

.github/workflows/size-comment.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: "Size: Comment"
2+
3+
# read-write repo token
4+
# access to secrets
5+
#
6+
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
7+
on:
8+
workflow_run:
9+
workflows: ["Size: PR"]
10+
types:
11+
- completed
12+
13+
jobs:
14+
compare_sizes:
15+
name: 'Compare Sizes and Comment'
16+
runs-on: 'ubuntu-latest'
17+
18+
steps:
19+
- run: sudo snap install dust
20+
21+
- uses: actions/download-artifact@v4
22+
with:
23+
name: pr-${{ github.event.workflow_run.id }}
24+
run-id: ${{ github.event.workflow_run.id }}
25+
26+
- uses: actions/download-artifact@v4
27+
with:
28+
name: sizes-main
29+
30+
- name: "[PR] Get sizes for development outputs"
31+
id: dev
32+
run: |
33+
cd pr/
34+
35+
echo 'sizes<<EOF' >> $GITHUB_OUTPUT
36+
while IFS= read -r line; do
37+
echo "$line" >> $GITHUB_OUTPUT
38+
done <<< $(cat out.txt)
39+
echo 'EOF' >> $GITHUB_OUTPUT
40+
cat out.txt
41+
42+
- name: "[PR]: Get PR Number"
43+
id: pr-number
44+
run: echo "number=$(cat pr/NR)" >> $GITHUB_OUTPUT
45+
46+
- name: "[Main] Get sizes for development outputs"
47+
id: main-dev
48+
run: |
49+
cd main/
50+
51+
echo 'sizes<<EOF' >> $GITHUB_OUTPUT
52+
while IFS= read -r line; do
53+
echo "$line" >> $GITHUB_OUTPUT
54+
done <<< $(cat out.txt)
55+
echo 'EOF' >> $GITHUB_OUTPUT
56+
cat out.txt
57+
58+
#########################
59+
# Intended Layout:
60+
#
61+
# | | This PR | Main |
62+
# | Dev | x1 | y1 |
63+
# | Prod | x2 | y2 |
64+
#
65+
# NOTE: we we don't have a prod build for this library
66+
# because we currently expect non-compiler usage
67+
# (so consumers should have terser or similar properly configured for DCE)
68+
#
69+
#########################
70+
- uses: mshick/add-pr-comment@v2
71+
with:
72+
issue: ${{ steps.pr-number.outputs.number }}
73+
message: |
74+
<table><thead><tr><th></th><th>This PR</th><th>main</th></tr></thead>
75+
<tbody>
76+
<tr><td>Dev</td><td>
77+
78+
```
79+
${{ steps.dev.outputs.sizes }}
80+
```
81+
82+
</td><td>
83+
84+
```
85+
${{ steps.main-dev.outputs.sizes }}
86+
```
87+
88+
</td></tr>
89+
</tbody></table>
90+
91+
92+
93+
env:
94+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+

.github/workflows/size-main.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "Size: main"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
name: 'Build'
11+
runs-on: 'ubuntu-latest'
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: ./.github/actions/setup
16+
- run: sudo snap install dust
17+
- run: pnpm build
18+
19+
- name: "Get sizes for development outputs"
20+
id: main-dev
21+
run: |
22+
mkdir -p main
23+
cd dist
24+
dust --ignore_hidden \
25+
--reverse --apparent-size \
26+
--filter ".+.js$" \
27+
--no-percent-bars \
28+
--only-file \
29+
--full-paths > out.txt
30+
cp out.txt ../main/
31+
32+
33+
- uses: actions/upload-artifact@v4
34+
with:
35+
name: sizes-main
36+
path: main/
37+
overwrite: true

.github/workflows/size-pr.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
2+
#
3+
# Do a build
4+
# Measure assets sizes
5+
# Upload artifact
6+
# Consumed by size.yml for comparison
7+
name: "Size: PR"
8+
9+
# read-only repo token
10+
# no access to secrets
11+
on:
12+
pull_request:
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: ./.github/actions/setup
21+
- run: pnpm build
22+
- run: sudo snap install dust
23+
24+
- name: Save PR number
25+
run: |
26+
mkdir -p ./pr
27+
echo ${{ github.event.number }} > ./pr/NR
28+
29+
- name: "Get sizes for development outputs"
30+
id: dev
31+
run: |
32+
cd dist
33+
dust --ignore_hidden \
34+
--reverse --apparent-size \
35+
--filter ".+.js$" \
36+
--no-percent-bars \
37+
--only-file \
38+
--full-paths > out.txt
39+
cp out.txt ../pr/
40+
41+
42+
- uses: actions/upload-artifact@v4
43+
with:
44+
name: pr-${{ github.event.workflow_run.id }}
45+
path: pr/
46+
overwrite: true

0 commit comments

Comments
 (0)