Skip to content

Commit 64bf8df

Browse files
committed
fix(wokwi): Checkout proper base branch for wokwi tests
1 parent 32fb3b4 commit 64bf8df

File tree

3 files changed

+75
-25
lines changed

3 files changed

+75
-25
lines changed

Diff for: .github/scripts/tests_matrix.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
build_types="'validation'"
4+
hw_types="'validation'"
5+
wokwi_types="'validation'"
6+
qemu_types="'validation'"
7+
8+
if [[ $IS_PR != 'true' ]] || [[ $PERFORMANCE_ENABLED == 'true' ]]; then
9+
build_types+=",'performance'"
10+
hw_types+=",'performance'"
11+
#wokwi_types+=",'performance'"
12+
#qemu_types+=",'performance'"
13+
fi
14+
15+
targets="'esp32','esp32s2','esp32s3','esp32c3','esp32c6','esp32h2'"
16+
17+
mkdir -p info
18+
19+
echo "[$wokwi_types]" > info/wokwi_types.txt
20+
echo "[$targets]" > info/targets.txt
21+
22+
echo "build-types=[$build_types]" >> $GITHUB_OUTPUT
23+
echo "hw-types=[$hw_types]" >> $GITHUB_OUTPUT
24+
echo "wokwi-types=[$wokwi_types]" >> $GITHUB_OUTPUT
25+
echo "qemu-types=[$qemu_types]" >> $GITHUB_OUTPUT
26+
echo "targets=[$targets]" >> $GITHUB_OUTPUT

Diff for: .github/workflows/tests.yml

+17-21
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,25 @@ jobs:
5757
hw-types: ${{ steps.set-matrix.outputs.hw-types }}
5858
wokwi-types: ${{ steps.set-matrix.outputs.wokwi-types }}
5959
qemu-types: ${{ steps.set-matrix.outputs.qemu-types }}
60+
targets: ${{ steps.set-matrix.outputs.targets }}
61+
env:
62+
IS_PR: ${{ github.event.pull_request.number != null }}
63+
PERFORMANCE_ENABLED: ${{ contains(github.event.pull_request.labels.*.name, 'perf_test') }}
6064
steps:
65+
- name: Checkout
66+
uses: actions/checkout@v4
67+
with:
68+
sparse-checkout: .github/scripts/tests_matrix.sh
69+
6170
- name: Set matrix
6271
id: set-matrix
63-
run: |
64-
build_types='["validation"'
65-
hw_types='["validation"'
66-
wokwi_types='["validation"'
67-
qemu_types='["validation"'
68-
69-
is_pr=${{ github.event.pull_request.number != null }}
70-
is_performance_enabled=${{ contains(github.event.pull_request.labels.*.name, 'perf_test') }}
71-
72-
if [[ $is_pr != 'true' ]] || [[ $is_performance_enabled == 'true' ]]; then
73-
build_types+=',"performance"'
74-
hw_types+=',"performance"'
75-
#wokwi_types+=',"performance"'
76-
#qemu_types+=',"performance"'
77-
fi
72+
run: bash .github/scripts/tests_matrix.sh
7873

79-
echo "build-types=$build_types]" >> $GITHUB_OUTPUT
80-
echo "hw-types=$hw_types]" >> $GITHUB_OUTPUT
81-
echo "wokwi-types=$wokwi_types]" >> $GITHUB_OUTPUT
82-
echo "qemu-types=$qemu_types]" >> $GITHUB_OUTPUT
74+
- name: Upload
75+
uses: actions/upload-artifact@v4
76+
with:
77+
name: matrix_info
78+
path: info/*
8379

8480
call-build-tests:
8581
name: Build
@@ -88,7 +84,7 @@ jobs:
8884
strategy:
8985
matrix:
9086
type: ${{ fromJson(needs.gen-matrix.outputs.build-types) }}
91-
chip: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32c6', 'esp32h2']
87+
chip: ${{ fromJson(needs.gen-matrix.outputs.targets) }}
9288
with:
9389
type: ${{ matrix.type }}
9490
chip: ${{ matrix.chip }}
@@ -105,7 +101,7 @@ jobs:
105101
fail-fast: false
106102
matrix:
107103
type: ${{ fromJson(needs.gen-matrix.outputs.hw-types) }}
108-
chip: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32c6', 'esp32h2']
104+
chip: ${{ fromJson(needs.gen-matrix.outputs.targets) }}
109105
with:
110106
type: ${{ matrix.type }}
111107
chip: ${{ matrix.chip }}

Diff for: .github/workflows/tests_wokwi.yml

+32-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
outputs:
2323
pr_num: ${{ steps.set-ref.outputs.pr_num }}
2424
ref: ${{ steps.set-ref.outputs.ref }}
25+
base: ${{ steps.set-ref.outputs.base }}
26+
targets: ${{ steps.set-ref.outputs.targets }}
27+
types: ${{ steps.set-ref.outputs.types }}
2528
steps:
2629
- name: Report pending
2730
uses: actions/github-script@v7
@@ -51,10 +54,18 @@ jobs:
5154
name: event_file
5255
path: artifacts/event_file
5356

57+
- name: Download and extract matrix info
58+
uses: actions/download-artifact@v4
59+
with:
60+
github-token: ${{ secrets.GITHUB_TOKEN }}
61+
run-id: ${{ github.event.workflow_run.id }}
62+
name: matrix_info
63+
path: artifacts/matrix_info
64+
5465
- name: Try to read PR number
5566
id: set-ref
5667
run: |
57-
pr_num=$(jq -r '.pull_request.number' artifacts/event_file/event.json)
68+
pr_num=$(jq -r '.pull_request.number' artifacts/event_file/event.json | tr -cd "[:digit:]")
5869
if [ -z "$pr_num" ] || [ "$pr_num" == "null" ]; then
5970
pr_num=""
6071
fi
@@ -64,11 +75,22 @@ jobs:
6475
ref=${{ github.ref }}
6576
fi
6677
67-
action=$(jq -r '.action' artifacts/event_file/event.json)
78+
action=$(jq -r '.action' artifacts/event_file/event.json | tr -cd "[:alpha:]_")
6879
if [ "$action" == "null" ]; then
6980
action=""
7081
fi
7182
83+
base=$(jq -r '.pull_request.base.ref' artifacts/event_file/event.json | tr -cd "[:alnum:]/_.-")
84+
if [ -z "$base" ] || [ "$base" == "null" ]; then
85+
base=${{ github.ref }}
86+
fi
87+
88+
types=$(cat artifacts/matrix_info/wokwi_types.txt | tr -cd "[:alpha:],[]'")
89+
targets=$(cat artifacts/matrix_info/targets.txt | tr -cd "[:alnum:],[]'")
90+
91+
echo "base = $base"
92+
echo "targets = $targets"
93+
echo "types = $types"
7294
echo "pr_num = $pr_num"
7395
7496
printf "$ref" >> artifacts/ref.txt
@@ -98,6 +120,9 @@ jobs:
98120
cat artifacts/conclusion.txt
99121
100122
echo "pr_num=$pr_num" >> $GITHUB_OUTPUT
123+
echo "base=$base" >> $GITHUB_OUTPUT
124+
echo "targets=$targets" >> $GITHUB_OUTPUT
125+
echo "types=$types" >> $GITHUB_OUTPUT
101126
echo "ref=$ref" >> $GITHUB_OUTPUT
102127
103128
- name: Download and extract parent hardware results
@@ -164,8 +189,8 @@ jobs:
164189
strategy:
165190
fail-fast: false
166191
matrix:
167-
type: ['validation']
168-
chip: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32c6', 'esp32h2']
192+
type: ${{ fromJson(needs.get-artifacts.outputs.types) }}
193+
chip: ${{ fromJson(needs.get-artifacts.outputs.targets) }}
169194
steps:
170195
- name: Report pending
171196
uses: actions/github-script@v7
@@ -211,9 +236,12 @@ jobs:
211236
echo "enabled=$enabled" >> $GITHUB_OUTPUT
212237
213238
# Note that changes to the workflows and tests will only be picked up after the PR is merged
239+
# DO NOT CHECKOUT THE USER'S REPOSITORY IN THIS WORKFLOW. IT HAS HIGH SECURITY RISKS.
214240
- name: Checkout repository
215241
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
216242
uses: actions/checkout@v4
243+
with:
244+
ref: ${{ needs.get-artifacts.outputs.base || github.ref }}
217245

218246
- uses: actions/setup-python@v5
219247
if: ${{ steps.check-tests.outputs.enabled == 'true' }}

0 commit comments

Comments
 (0)