Skip to content

Commit 0fb66ac

Browse files
authored
ci(test-size): takes example name (#5264)
* ci(test-size): takes example name * help message
1 parent 6a29451 commit 0fb66ac

File tree

3 files changed

+86
-62
lines changed

3 files changed

+86
-62
lines changed

.github/workflows/binary-size.yml

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
description: "Pull request number to analyze"
88
required: true
99
type: string
10+
example_name:
11+
description: "Example directory name to analyze (e.g., embassy_dhcp)"
12+
required: true
13+
type: string
1014

1115
jobs:
1216
binary-size:
@@ -22,16 +26,10 @@ jobs:
2226
target:
2327
- soc: esp32c3
2428
rust-target: riscv32imc-unknown-none-elf
25-
dir-qa: ./qa-test
26-
dir-dhcp: ./examples/wifi/embassy_dhcp
2729
- soc: esp32c6
2830
rust-target: riscv32imac-unknown-none-elf
29-
dir-qa: ./qa-test
30-
dir-dhcp: ./examples/wifi/embassy_dhcp
3131
- soc: esp32
3232
rust-target: xtensa-esp32-none-elf
33-
dir-qa: ./qa-test
34-
dir-dhcp: ./examples/wifi/embassy_dhcp
3533

3634
steps:
3735
- name: Setup Rust
@@ -82,45 +80,82 @@ jobs:
8280
cd $HOME
8381
mkdir results
8482
85-
- name: Build PR QA Binary
86-
working-directory: ${{ matrix.target.dir-qa }}
83+
- name: Build PR example
8784
run: |
88-
cargo build --release --bin sleep_timer --features ${{ matrix.target.soc }} --target ${{ matrix.target.rust-target }}
89-
cp target/${{ matrix.target.rust-target }}/release/sleep_timer $HOME/results/pr_qa_build_${{ matrix.target.soc }}.elf
85+
set -euo pipefail
86+
87+
RAW_INPUT="${{ github.event.inputs.example_name }}"
88+
cargo xtask build examples $RAW_INPUT --chip "${{ matrix.target.soc }}"
89+
90+
EXAMPLE_NAME=$(echo "$RAW_INPUT" | awk '{print $1}')
91+
BIN_NAME=$(echo "$EXAMPLE_NAME" | tr '_' '-')
92+
93+
BIN=$(
94+
find target qa-test/target examples -type f \
95+
-path "*/release/${BIN_NAME}" \
96+
-executable \
97+
2>/dev/null | head -n 1 || true
98+
)
99+
100+
# Fallback to `_` instead of `-`
101+
if [ -z "$BIN" ]; then
102+
BIN=$(find target qa-test/target examples -type f \
103+
-path "*/release/${EXAMPLE_NAME}" \
104+
-executable \
105+
2>/dev/null | head -n 1 || true)
106+
fi
90107
91-
- name: Build PR DHCP Binary
92-
working-directory: ${{ matrix.target.dir-dhcp }}
93-
run: |
94-
# Build
95-
cargo build --release --features ${{ matrix.target.soc }} --target ${{ matrix.target.rust-target }}
96-
# Copy PR binary to parent directory (outside workspace)
97-
cp target/${{ matrix.target.rust-target }}/release/embassy-dhcp $HOME/results/pr_dhcp_build_${{ matrix.target.soc }}.elf
108+
if [ -z "$BIN" ]; then
109+
echo "Error: Built PR binary not found"
110+
exit 1
111+
fi
98112
99-
# Checkout base (current default branch HEAD) for comparison
113+
cp "$BIN" $HOME/results/pr_qa_build_${{ matrix.target.soc }}.elf
114+
115+
# Checkout base
100116
- name: Checkout Base Commit
101117
uses: actions/checkout@v6
102118
with:
103119
fetch-depth: 0
104120

105-
- name: Build Base QA Binary
106-
working-directory: ${{ matrix.target.dir-qa }}
121+
- name: Build Base example
107122
run: |
108-
cargo build --release --bin sleep_timer --features ${{ matrix.target.soc }} --target ${{ matrix.target.rust-target }}
109-
cp target/${{ matrix.target.rust-target }}/release/sleep_timer $HOME/results/base_qa_build_${{ matrix.target.soc }}.elf
123+
set -euo pipefail
124+
cargo clean
125+
126+
RAW_INPUT="${{ github.event.inputs.example_name }}"
127+
cargo xtask build examples $RAW_INPUT --chip "${{ matrix.target.soc }}"
128+
129+
EXAMPLE_NAME=$(echo "$RAW_INPUT" | awk '{print $1}')
130+
BIN_NAME=$(echo "$EXAMPLE_NAME" | tr '_' '-')
131+
132+
BIN=$(
133+
find target qa-test/target examples -type f \
134+
-path "*/release/${BIN_NAME}" \
135+
-executable \
136+
2>/dev/null | head -n 1 || true
137+
)
138+
139+
# Fallback to `_` instead of `-`
140+
if [ -z "$BIN" ]; then
141+
BIN=$(find target qa-test/target examples -type f \
142+
-path "*/release/${EXAMPLE_NAME}" \
143+
-executable \
144+
2>/dev/null | head -n 1 || true)
145+
fi
110146
111-
- name: Build Base DHCP Binary
112-
working-directory: ${{ matrix.target.dir-dhcp }}
113-
run: |
114-
cargo build --release --features ${{ matrix.target.soc }} --target ${{ matrix.target.rust-target }}
115-
cp target/${{ matrix.target.rust-target }}/release/embassy-dhcp $HOME/results/base_dhcp_build_${{ matrix.target.soc }}.elf
147+
if [ -z "$BIN" ]; then
148+
echo "Error: Built BASE binary not found"
149+
exit 1
150+
fi
151+
152+
cp "$BIN" $HOME/results/base_qa_build_${{ matrix.target.soc }}.elf
116153
117154
- name: Copy binaries to workspace for Bloaty
118155
run: |
119156
# Copy files from $HOME/results to current workspace
120157
cp $HOME/results/base_qa_build_${{ matrix.target.soc }}.elf ./
121158
cp $HOME/results/pr_qa_build_${{ matrix.target.soc }}.elf ./
122-
cp $HOME/results/base_dhcp_build_${{ matrix.target.soc }}.elf ./
123-
cp $HOME/results/pr_dhcp_build_${{ matrix.target.soc }}.elf ./
124159
ls -la *.elf
125160
126161
# Diffs and Artifacts
@@ -140,23 +175,6 @@ jobs:
140175
echo "\`\`\`" >> result-pr-${{ matrix.target.soc }}.txt
141176
echo "EOF" >> result-pr-${{ matrix.target.soc }}.txt
142177
143-
- name: Run Bloaty DHCP Diff
144-
id: bloaty-dhcp
145-
uses: carlosperate/bloaty-action@v1
146-
with:
147-
bloaty-args: -d sections --domain vm --source-filter "^.text$|^.data|^.bss|^.rwdata|^.rwtext" base_dhcp_build_${{ matrix.target.soc }}.elf -- pr_dhcp_build_${{ matrix.target.soc }}.elf
148-
output-to-summary: false
149-
continue-on-error: true
150-
151-
- name: Save Bloaty DHCP output
152-
run: |
153-
echo "DHCP_DIFF<<EOF" >> result-pr-${{ matrix.target.soc }}.txt
154-
echo "\`\`\`" >> result-pr-${{ matrix.target.soc }}.txt
155-
echo "${{ steps.bloaty-dhcp.outputs.bloaty-output || 'N/A' }}" >> result-pr-${{ matrix.target.soc }}.txt
156-
echo "\`\`\`" >> result-pr-${{ matrix.target.soc }}.txt
157-
echo "EOF" >> result-pr-${{ matrix.target.soc }}.txt
158-
cat result-pr-${{ matrix.target.soc }}.txt
159-
160178
- name: Upload Result Artifact
161179
uses: actions/upload-artifact@v6
162180
with:

.github/workflows/dispatch.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ jobs:
559559
- `/hil quick` — run a quick HIL matrix (only `ESP32-S3` (Xtensa) and `ESP32-C6` (RISC-V) tests)
560560
- `/hil full` — run the full HIL matrix for all supported chips
561561
- `/hil <chip> [<chip> ...]` — run the full HIL tests **only** for the listed chips
562-
- `/test-size` — run binary size analysis for this PR
562+
- `/test-size <example_name>` — run binary size analysis for this PR for specified example, for `qa-test` example use `<example_name> --package qa-test`
563563
- You can optionally append `--test <name>[,<name>...]` to any `/hil` command to only run selected tests.
564564
If you aren't a repository **member/owner**, you must be **trusted for this PR**.
565565
Maintainers can grant access with a `trusted-author` label or with:
@@ -578,14 +578,33 @@ jobs:
578578
startsWith(github.event.comment.body, '/test-size')
579579
runs-on: ubuntu-latest
580580
steps:
581+
- name: Extract example name from comment
582+
id: extract
583+
run: |
584+
# Expected format: /test-size example_name
585+
COMMENT="${{ github.event.comment.body }}"
586+
587+
# Remove the /test-size prefix and trim whitespace
588+
EXAMPLE_NAME=$(echo "$COMMENT" | sed 's|/test-size||' | xargs)
589+
590+
if [ -z "$EXAMPLE_NAME" ]; then
591+
echo "Error: No example name provided in comment"
592+
echo "Expected format: /test-size example_name"
593+
exit 1
594+
fi
595+
596+
echo "example_name=$EXAMPLE_NAME" >> $GITHUB_OUTPUT
597+
echo "Extracted example name: $EXAMPLE_NAME"
598+
581599
- name: Dispatch Binary Size Analysis
582600
uses: benc-uk/workflow-dispatch@v1
583601
with:
584602
workflow: binary-size.yml
585603
ref: ${{ github.event.repository.default_branch }}
586604
inputs: |
587605
{
588-
"pr_number": "${{ github.event.issue.number }}"
606+
"pr_number": "${{ github.event.issue.number }}",
607+
"example_name": "${{ steps.extract.outputs.example_name }}"
589608
}
590609
591610
- name: Confirm in PR

xtask/src/commands/generate_report.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,13 @@ pub fn generate_report(workspace: &Path, args: ReportArgs) -> Result<()> {
6767
&code_fence_re,
6868
&leading_ws_re,
6969
);
70-
let dhcp_diff = extract_block(
71-
&content,
72-
"DHCP_DIFF<<EOF",
73-
"EOF",
74-
&exclude_re,
75-
&code_fence_re,
76-
&leading_ws_re,
77-
);
7870

7971
writeln!(combined, "### `{}`\n", soc)?;
8072
writeln!(
8173
combined,
82-
"##### sleep-timer Diff (PR vs. Base)\n```\n{}\n```\n",
74+
"##### Diff (PR vs. Base)\n```\n{}\n```\n",
8375
qa_diff
8476
)?;
85-
writeln!(
86-
combined,
87-
"##### embassy-dhcp Diff (PR vs. Base)\n```\n{}\n```\n",
88-
dhcp_diff
89-
)?;
9077
}
9178

9279
Ok(())

0 commit comments

Comments
 (0)