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