Repository navigation
282 lines (241 loc) · 9.58 KB
/
Copy pathbinary-size.yml
File metadata and controls
282 lines (241 loc) · 9.58 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
name: Binary Size Analysis
run-name: >-
${{ format('Binary size for PR #{0}{1}',
inputs.pr_number,
inputs.distinct_id != '' && format(' [dispatch-id: {0}]', inputs.distinct_id) || ''
) }}
on:
workflow_dispatch:
inputs:
pr_number:
description: "Pull request number to analyze"
required: true
type: string
example_name:
description: "Example directory name to analyze (e.g., embassy_dhcp)"
required: true
type: string
package:
description: "Optional --package argument (e.g., qa)"
required: false
default: ""
type: string
chips:
description: 'JSON array of chips to test, e.g. ["esp32c3","esp32c6"]'
required: true
type: string
comment_id:
description: "Comment ID to update with binary size results"
required: false
default: ""
type: string
distinct_id:
description: "Correlation marker set by the dispatcher; do not set manually"
required: false
default: ""
type: string
jobs:
binary-size:
runs-on: ubuntu-latest
permissions:
actions: read
pull-requests: write
contents: read
strategy:
fail-fast: false
matrix:
soc: ${{ fromJSON(inputs.chips) }}
steps:
# Checked out first so the chip metadata is available to the step below.
- name: Checkout Repo (Initial)
uses: actions/checkout@v6
- name: Resolve Rust target
id: target
run: |
ENTRY=$(jq -c --arg s "${{ matrix.soc }}" '.[] | select(.soc == $s)' .github/chips.json)
if [ -z "$ENTRY" ]; then
echo "Error: Unknown SoC: ${{ matrix.soc }}"
exit 1
fi
echo "rust-target=$(echo "$ENTRY" | jq -r '."rust-target"')" >> $GITHUB_OUTPUT
echo "arch=$(echo "$ENTRY" | jq -r '.arch')" >> $GITHUB_OUTPUT
# Only the toolchain for this leg's architecture is installed.
- name: Setup Rust
uses: ./.github/actions/setup-toolchains
with:
xtensa: ${{ steps.target.outputs.arch == 'xtensa' }}
xtensa-buildtargets: ${{ matrix.soc }}
xtensa-default: "true"
riscv: ${{ steps.target.outputs.arch == 'riscv' }}
riscv-targets: ${{ steps.target.outputs.rust-target }}
riscv-components: rust-src, llvm-tools
- name: Install Binutils and Hub
run: |
cargo install cargo-binutils
sudo apt-get update
sudo apt-get install -y hub
# Checkout the PR on top of the initial checkout above.
# context https://github.com/actions/checkout/issues/331
- name: Checkout Pull Request (PR Code at Root)
run: hub pr checkout ${{ github.event.inputs.pr_number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Cache Cargo Dependencies
uses: actions/cache@v6
with:
path: |
~/.cargo/bin/
~/.cargo/registry/
~/.cargo/git/
./target/
key: ${{ runner.os }}-${{ matrix.soc }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Dir for result files
run: mkdir -p $HOME/results
- name: Build PR example
run: |
set -euo pipefail
RAW_INPUT="${{ github.event.inputs.example_name }}"
PACKAGE="${{ github.event.inputs.package }}"
PKG_ARGS=""
if [ -n "$PACKAGE" ]; then
PKG_ARGS="--package $PACKAGE"
fi
cargo xtask build $RAW_INPUT $PKG_ARGS "${{ matrix.soc }}"
EXAMPLE_NAME=$(echo "$RAW_INPUT" | awk '{print $1}')
MANIFEST=$(find examples -path "*/${EXAMPLE_NAME}/Cargo.toml" -print -quit 2>/dev/null || true)
if [ -n "$MANIFEST" ]; then
EXAMPLE_NAME=$(sed -n '/^\[package\]$/,/^\[/{s/^[[:space:]]*name[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p}' "$MANIFEST" | head -n 1)
fi
BIN_NAME=$(echo "$EXAMPLE_NAME" | tr '_' '-')
BIN=$(find target examples -type f \
-path "*/release/${BIN_NAME}" -executable 2>/dev/null | head -n 1 || true)
# Fallback to `_` instead of `-`
if [ -z "$BIN" ]; then
BIN=$(find target examples -type f \
-path "*/release/${EXAMPLE_NAME}" -executable 2>/dev/null | head -n 1 || true)
fi
if [ -z "$BIN" ]; then
echo "Error: Built PR binary not found"
exit 1
fi
cp "$BIN" $HOME/results/pr_qa_build_${{ matrix.soc }}.elf
# Checkout base
- name: Checkout Base Commit
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Build Base example
run: |
set -euo pipefail
cargo clean
RAW_INPUT="${{ github.event.inputs.example_name }}"
PACKAGE="${{ github.event.inputs.package }}"
PKG_ARGS=""
if [ -n "$PACKAGE" ]; then
PKG_ARGS="--package $PACKAGE"
fi
cargo xtask build $RAW_INPUT $PKG_ARGS "${{ matrix.soc }}"
EXAMPLE_NAME=$(echo "$RAW_INPUT" | awk '{print $1}')
MANIFEST=$(find examples -path "*/${EXAMPLE_NAME}/Cargo.toml" -print -quit 2>/dev/null || true)
if [ -n "$MANIFEST" ]; then
EXAMPLE_NAME=$(sed -n '/^\[package\]$/,/^\[/{s/^[[:space:]]*name[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p}' "$MANIFEST" | head -n 1)
fi
BIN_NAME=$(echo "$EXAMPLE_NAME" | tr '_' '-')
BIN=$(find target examples -type f \
-path "*/release/${BIN_NAME}" -executable 2>/dev/null | head -n 1 || true)
# Fallback to `_` instead of `-`
if [ -z "$BIN" ]; then
BIN=$(find target examples -type f \
-path "*/release/${EXAMPLE_NAME}" -executable 2>/dev/null | head -n 1 || true)
fi
if [ -z "$BIN" ]; then
echo "Error: Built BASE binary not found"
exit 1
fi
cp "$BIN" $HOME/results/base_qa_build_${{ matrix.soc }}.elf
- name: Copy binaries to workspace for Bloaty
run: |
# Copy files from $HOME/results to current workspace
cp $HOME/results/base_qa_build_${{ matrix.soc }}.elf ./
cp $HOME/results/pr_qa_build_${{ matrix.soc }}.elf ./
ls -la *.elf
# Diffs and Artifacts
- name: Run Bloaty Diff
id: bloaty-qa
uses: carlosperate/bloaty-action@v1
with:
bloaty-args: -d sections --domain vm --source-filter "^.text$|^.data|^.bss|^.rwdata|^.rwtext" pr_qa_build_${{ matrix.soc }}.elf -- base_qa_build_${{ matrix.soc }}.elf
output-to-summary: false
continue-on-error: true
- name: Save Bloaty output
run: |
echo "EXAMPLE_DIFF<<EOF" > result-pr-${{ matrix.soc }}.txt
echo "\`\`\`" >> result-pr-${{ matrix.soc }}.txt
echo "${{ steps.bloaty-qa.outputs.bloaty-output || 'N/A' }}" >> result-pr-${{ matrix.soc }}.txt
echo "\`\`\`" >> result-pr-${{ matrix.soc }}.txt
echo "EOF" >> result-pr-${{ matrix.soc }}.txt
- name: Upload Result Artifact
uses: actions/upload-artifact@v6
with:
name: result-${{ matrix.soc }}
path: result-pr-${{ matrix.soc }}.txt
report-results:
needs: binary-size
if: always()
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v6
- uses: actions/download-artifact@v4
with:
pattern: result-*
path: ./results
merge-multiple: true
- name: Generate Combined Report
if: needs.binary-size.result == 'success'
id: combine
working-directory: ${{ github.workspace }}
run: cargo run -p esp-devtool --features report -- generate-report --input results
- name: Find and Update Comment with GH CLI
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ISSUE_NUMBER=${{ github.event.inputs.pr_number }}
echo "Processing PR Number: $ISSUE_NUMBER"
COMMENTS=$(gh api repos/${{ github.repository }}/issues/$ISSUE_NUMBER/comments)
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
RESULT="${{ needs.binary-size.result }}"
COMMENT_ID="${{ github.event.inputs.comment_id }}"
{
echo "Run: $RUN_URL"
echo
if [ "$RESULT" = "success" ]; then
cat report.txt
else
echo "Binary size analysis **failed** (conclusion: $RESULT)."
echo
echo "Please inspect the workflow run for details."
fi
} > comment-body.md
# Fallback to an existing Binary Size Report comment (for older runs)
if [ -z "$COMMENT_ID" ] || [ "$COMMENT_ID" = "null" ]; then
COMMENT_ID=$(echo "$COMMENTS" | jq -r '
.[]
| select(.user.login == "github-actions[bot]")
| select(.body | test("^## Binary Size Report"))
| .id' | head -n1)
fi
if [ -n "$COMMENT_ID" ] && [ "$COMMENT_ID" != "null" ]; then
echo "Updating existing comment: $COMMENT_ID"
gh api -X PATCH \
repos/${{ github.repository }}/issues/comments/$COMMENT_ID \
-f "body=$(cat comment-body.md)"
else
echo "Creating new comment"
gh api -X POST \
repos/${{ github.repository }}/issues/$ISSUE_NUMBER/comments \
-f "body=$(cat comment-body.md)"
fi