Skip to content

Commit b59a368

Browse files
authored
feat(ci): Run Wokwi tests on PR (#9597)
* feat(ci): Run Wokwi tests on PR * fix(ci): Concurrency change to wokwi * ci(wokwi): Fix skipped tests
1 parent 1299582 commit b59a368

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

Diff for: .github/workflows/wokwi.yml

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: Run tests in wokwi on PR
2+
3+
on:
4+
workflow_run:
5+
workflows: [Run tests]
6+
types:
7+
- completed
8+
9+
permissions:
10+
statuses: write
11+
12+
env:
13+
MAX_CHUNKS: 15
14+
WOKWI_TIMEOUT: 600000 # Milliseconds
15+
WOKWI_CLI_TOKEN: ${{ secrets.WOKWI_CLI_TOKEN }}
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
18+
concurrency:
19+
group: wokwi-${{github.event.pull_request.number || github.ref}}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
gen_chunks:
24+
if: github.event.workflow_run.event == 'pull_request'
25+
name: Generate Chunks matrix
26+
runs-on: ubuntu-latest
27+
outputs:
28+
chunks: ${{ steps.gen-chunks.outputs.chunks }}
29+
steps:
30+
- name: Checkout Repository
31+
uses: actions/checkout@v4
32+
with:
33+
ref: ${{ github.event.workflow_run.head_sha }} # Check out the code of the PR to generate accurate chunks
34+
35+
- name: Generate Chunks matrix
36+
id: gen-chunks
37+
run: |
38+
set +e
39+
.github/scripts/sketch_utils.sh count tests
40+
sketches=$?
41+
if [[ $sketches -ge ${{env.MAX_CHUNKS}} ]]; then
42+
$sketches=${{env.MAX_CHUNKS}}
43+
fi
44+
set -e
45+
rm sketches.txt
46+
CHUNKS=$(jq -c -n '$ARGS.positional' --args `seq 0 1 $((sketches - 1))`)
47+
echo "chunks=${CHUNKS}" >>$GITHUB_OUTPUT
48+
49+
wokwi-test:
50+
needs: [gen_chunks]
51+
name: ${{matrix.chip}}-Wokwi_Test#${{matrix.chunks}}
52+
strategy:
53+
fail-fast: false
54+
matrix:
55+
chip: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32c6', 'esp32h2']
56+
chunks: ${{fromJson(needs.gen_chunks.outputs.chunks)}}
57+
runs-on: ubuntu-latest
58+
steps:
59+
- name: Checkout repository
60+
uses: actions/checkout@v4
61+
with:
62+
ref: ${{ github.event.workflow_run.head_sha }} # Check out the code of the PR to get correct pytest files
63+
64+
- name: Download ${{matrix.chip}}-${{matrix.chunks}} artifacts
65+
uses: actions/download-artifact@v4
66+
with:
67+
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
68+
path: ~/
69+
run-id: ${{github.event.workflow_run.id}}
70+
github-token: ${{env.GITHUB_TOKEN}}
71+
72+
- name: Install Wokwi CLI
73+
run: curl -L https://wokwi.com/ci/install.sh | sh
74+
75+
- name: Install dependencies
76+
run: |
77+
pip install -U pip
78+
pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi
79+
sudo apt update && sudo apt install -y -qq jq
80+
81+
- name: Run Tests
82+
run: |
83+
bash .github/scripts/tests_run.sh -c -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}} -w ${{env.WOKWI_TIMEOUT}}
84+
85+
- name: Check if tests were skipped
86+
id: check-test-skipped
87+
run: |
88+
if [ -f ~/.test_skipped ]; then
89+
echo "skipped=true" >> $GITHUB_OUTPUT
90+
else
91+
echo "skipped=false" >> $GITHUB_OUTPUT
92+
fi
93+
94+
- name: Upload test result artifacts
95+
uses: actions/upload-artifact@v4
96+
if: ${{ always() && steps.check-test-skipped.outputs.skipped == 'false' }}
97+
with:
98+
name: wokwi_results-${{matrix.chip}}-${{matrix.chunks}}
99+
path: tests/**/*.xml
100+
101+
report-result:
102+
name: Report wokwi test result
103+
runs-on: ubuntu-latest
104+
needs: wokwi-test
105+
if: always() && github.event.workflow_run.event == 'pull_request'
106+
steps:
107+
- name: Report result
108+
uses: actions/github-script@v7
109+
with:
110+
debug: true
111+
script: |
112+
const owner = '${{ github.repository_owner }}';
113+
const repo = '${{ github.repository }}'.split('/')[1];
114+
const sha = '${{ github.event.workflow_run.head_sha }}';
115+
const result = '${{ needs.wokwi-test.result }}';
116+
core.debug(`owner: ${owner}`);
117+
core.debug(`repo: ${repo}`);
118+
core.debug(`sha: ${sha}`);
119+
core.debug(`result: ${result}`);
120+
const { context: name, state } = (await github.rest.repos.createCommitStatus({
121+
context: 'Wokwi tests',
122+
description: 'Wokwi simulator tests',
123+
owner: owner,
124+
repo: repo,
125+
sha: sha,
126+
state: result,
127+
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
128+
})).data;
129+
core.info(`${name} is ${state}`);
130+

0 commit comments

Comments
 (0)