Skip to content

Commit 1a5deec

Browse files
committed
feat(ci): Run Wokwi tests on PR
1 parent c396834 commit 1a5deec

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

.github/workflows/wokwi.yml

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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: hil-${{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: ~/.arduino/tests/
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: Upload test result artifacts
86+
uses: actions/upload-artifact@v4
87+
if: always()
88+
with:
89+
name: wokwi_results-${{matrix.chip}}-${{matrix.chunks}}
90+
path: tests/*/*.xml
91+
92+
report-result:
93+
name: Report wokwi test result
94+
runs-on: ubuntu-latest
95+
needs: wokwi-test
96+
if: always() && github.event.workflow_run.event == 'pull_request'
97+
steps:
98+
- name: Report result
99+
uses: actions/github-script@v7
100+
with:
101+
debug: true
102+
script: |
103+
const owner = '${{ github.repository_owner }}';
104+
const repo = '${{ github.repository }}'.split('/')[1];
105+
const sha = '${{ github.event.workflow_run.head_sha }}';
106+
const result = '${{ needs.wokwi-test.result }}';
107+
core.debug(`owner: ${owner}`);
108+
core.debug(`repo: ${repo}`);
109+
core.debug(`sha: ${sha}`);
110+
core.debug(`result: ${result}`);
111+
const { context: name, state } = (await github.rest.repos.createCommitStatus({
112+
context: 'Wokwi tests',
113+
description: 'Wokwi simulator tests',
114+
owner: owner,
115+
repo: repo,
116+
sha: sha,
117+
state: result,
118+
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
119+
})).data;
120+
core.info(`${name} is ${state}`);
121+

0 commit comments

Comments
 (0)