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