-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
172 lines (138 loc) · 4.43 KB
/
size-comment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: "Size: Comment"
# read-write repo token
# access to secrets
#
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
on:
workflow_dispatch:
inputs:
RUN_ID:
description: Which workflow run to get artifacts from
required: true
type: string
workflow_run:
workflows: ["Size: PR"]
types:
- completed
permissions:
contents: read
issues: write
pull-requests: write
jobs:
compare_sizes:
name: 'Compare Sizes and Comment'
runs-on: 'ubuntu-latest'
steps:
# better `du`
- run: sudo snap install dust
- uses: dawidd6/action-download-artifact@v9
with:
run_id: ${{ inputs.RUN_ID || github.event.workflow_run.id }}
workflow: size-pr.yml
path: pr
if_no_artifact_found: fail
- uses: dawidd6/action-download-artifact@v9
with:
name: sizes-main
path: main
workflow: size-main.yml
if_no_artifact_found: fail
- name: "[Debug] artifacts' files"
run: |
ls -la ./main
ls -la ./pr/**
- name: "[PR] Get path of size output txt file"
id: find-pr-txt
run: |
cd pr/
filePath=$(find . -name "out.txt")
echo $filePath
echo "txtPath=pr/$filePath" >> $GITHUB_OUTPUT
- name: "[PR] Get PR number"
id: find-pr-number
run: |
cd pr/
filePath=$(find . -name "NR")
contents=$(cat $filePath)
echo $filePath
echo $contents
echo "prNumber=$contents" >> $GITHUB_OUTPUT
- name: "[PR] Get sizes for development outputs"
id: dev
run: |
cat ${{ steps.find-pr-txt.outputs.txtPath }}
echo 'sizes<<EOF' >> $GITHUB_OUTPUT
while IFS= read -r line; do
echo "$line" >> $GITHUB_OUTPUT
done <<< $(cat ${{ steps.find-pr-txt.outputs.txtPath }})
echo 'EOF' >> $GITHUB_OUTPUT
- name: "[Main] Get sizes for development outputs"
id: main-dev
run: |
cd main/
cat out.txt
echo 'sizes<<EOF' >> $GITHUB_OUTPUT
while IFS= read -r line; do
echo "$line" >> $GITHUB_OUTPUT
done <<< $(cat out.txt)
echo 'EOF' >> $GITHUB_OUTPUT
- name: "[Dev] calculate diff"
run: |
# diff exits with status 1 if there is a diff
diff -u main/out.txt ${{ steps.find-pr-txt.outputs.txtPath }} > dev-diff.txt || echo "Differences exist"
cat dev-diff.txt
- name: "[Dev] store diff in GITHUB_OUTPUT"
id: dev-diff
run: |
echo 'diffText<<EOF' >> $GITHUB_OUTPUT
while IFS= read -r line; do
echo "$line" >> $GITHUB_OUTPUT
done <<< $(cat ./dev-diff.txt)
echo 'EOF' >> $GITHUB_OUTPUT
- name: "[Debug] collected data from artifacts"
run: |
echo "PR number"
echo -e "${{ steps.find-pr-number.outputs.prNumber }}"
echo "Main out.txt"
echo -e "${{ steps.main-dev.outputs.sizes }}"
echo "PR out.txt"
echo -e "${{ steps.dev.outputs.sizes }}"
echo "Dev diff"
echo -e "${{ steps.dev-diff.outputs.diffText }}"
#########################
# Intended Layout:
#
# | | This PR | Main |
# | Dev | x1 | y1 |
# | Prod | x2 | y2 |
#
# NOTE: we we don't have a prod build for this library
# because we currently expect non-compiler usage
# (so consumers should have terser or similar properly configured for DCE)
#
#########################
- uses: mshick/add-pr-comment@v2
with:
issue: ${{ steps.find-pr-number.outputs.prNumber }}
message: |
<details><summary>Development Assets</summary>
Diff
```diff
${{ steps.dev-diff.outputs.diffText }}
```
Details
<table><thead><tr><th></th><th>This PR</th><th>main</th></tr></thead>
<tbody>
<tr><td>Dev</td><td>
```
${{ steps.dev.outputs.sizes }}
```
</td><td>
```
${{ steps.main-dev.outputs.sizes }}
```
</td></tr>
</tbody></table>
</details>
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}