Skip to content

Commit 7e8f2fe

Browse files
committed
test
1 parent 8e46c04 commit 7e8f2fe

File tree

5 files changed

+101
-144
lines changed

5 files changed

+101
-144
lines changed

.github/workflows/build_tests.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,64 @@ jobs:
1515
matrix:
1616
type: ['validation', 'performance']
1717
chip: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32c6', 'esp32h2']
18+
env:
19+
build-cache-key: tests-bin-${{ github.event.pull_request.number || github.ref }}-${{ matrix.chip }}-${{ matrix.type }}-${{ github.event.pull_request.head.sha || github.sha }}
1820
steps:
1921
- name: Check if already built
2022
if: ${{ github.event.pull_request.number != null }}
2123
id: cache-build-binaries
2224
uses: actions/cache/restore@v4
2325
with:
2426
lookup-only: true
25-
path: ~/.arduino/tests/*
26-
key: tests-${{ github.event.pull_request.number }}-${{ matrix.chip }}-${{ matrix.type }}-${{ github.event.pull_request.head.sha }}
27+
key: ${{ env.build-cache-key }}
28+
path: |
29+
~/.arduino/tests/**/build*.tmp/*.bin
30+
~/.arduino/tests/**/build*.tmp/*.elf
31+
~/.arduino/tests/**/build*.tmp/*.json
2732
2833
- name: Evaluate if tests should be built
2934
id: check-build
3035
run: |
31-
artifact_exists=${{ steps.cache-build-binaries.outputs.cache-hit == 'true' || false }}
36+
cache_exists=${{ steps.cache-build-binaries.outputs.cache-hit == 'true' || false }}
3237
is_pr=${{ github.event.pull_request.number != null }}
3338
is_performance_test=${{ matrix.type == 'performance' }}
3439
is_performance_enabled=${{ contains(github.event.pull_request.labels.*.name, 'perf_test') }}
40+
enabled=true
3541
36-
if [[ $artifact_exists == 'true' ]]; then
42+
if [[ $cache_exists == 'true' ]]; then
3743
echo "Already built, skipping"
38-
exit 0
44+
enabled=false
3945
elif [[ $is_pr != 'true' ]]; then
4046
echo "Not a PR, building"
4147
elif [[ $is_performance_test == 'true' ]]; then
4248
if [[ $is_performance_enabled == 'true' ]]; then
4349
echo "Performance test enabled, building"
4450
else
4551
echo "Performance test disabled, skipping"
46-
exit 0
52+
enabled=false
4753
fi
4854
else
4955
echo "Validation test, building"
5056
fi
5157
58+
echo "enabled=$enabled" >> $GITHUB_OUTPUT
59+
5260
- name: Checkout Repository
5361
uses: actions/checkout@v4
62+
if: ${{ steps.check-build.outputs.enabled == 'true' }}
5463
with:
55-
ref: ${{ github.event.pull_request.head.sha }}
64+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
5665

5766
- name: Build sketches
67+
if: ${{ steps.check-build.outputs.enabled == 'true' }}
5868
run: |
5969
bash .github/scripts/tests_build.sh -c -type ${{ matrix.type }} -t ${{ matrix.chip }}
6070
6171
- name: Upload ${{ matrix.chip }}-${{ matrix.type }} binaries as cache
6272
uses: actions/cache/save@v4
73+
if: ${{ steps.check-build.outputs.enabled == 'true' }}
6374
with:
64-
key: tests-${{ github.event.pull_request.number || github.ref }}-${{ matrix.chip }}-${{ matrix.type }}-${{ github.event.pull_request.head.sha || github.sha }}
75+
key: ${{ env.build-cache-key }}
6576
path: |
6677
~/.arduino/tests/**/build*.tmp/*.bin
6778
~/.arduino/tests/**/build*.tmp/*.elf

.github/workflows/clean.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: Clean objects
22

33
on:
4-
workflow_call:
4+
pull_request_target:
5+
types: [closed]
56

67
jobs:
78
clean:

.github/workflows/hw.yml

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,64 +12,95 @@ jobs:
1212
name: Hardware ${{ matrix.chip }} ${{ matrix.type }} tests
1313
runs-on: [arduino, "${{ matrix.chip }}"]
1414
strategy:
15+
fail-fast: false
1516
matrix:
1617
type: ['validation', 'performance']
1718
chip: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32c6', 'esp32h2']
19+
env:
20+
cache-binaries-key: tests-bin-${{ github.event.pull_request.number || github.ref }}-${{ matrix.chip }}-${{ matrix.type }}-${{ github.event.pull_request.head.sha || github.sha }}
21+
cache-results-key: tests-hw-${{ github.event.pull_request.number || github.ref }}-${{ matrix.chip }}-${{ matrix.type }}-${{ github.event.pull_request.head.sha || github.sha }}
1822
container:
1923
image: python:3.10.1-bullseye
2024
options: --privileged
2125
steps:
26+
- name: Check if already built
27+
if: ${{ github.event.pull_request.number != null }}
28+
id: cache-results
29+
uses: actions/cache/restore@v4
30+
with:
31+
lookup-only: true
32+
key: ${{ env.cache-results-key }}
33+
path: |
34+
tests/**/*.xml
35+
tests/**/result_*.json
36+
2237
- name: Evaluate if tests should be run
2338
id: check-tests
2439
run: |
40+
cache_exists=${{ steps.cache-results.outputs.cache-hit == 'true' || false }}
2541
is_pr=${{ github.event.pull_request.number != null }}
2642
is_performance_test=${{ matrix.type == 'performance' }}
2743
is_performance_enabled=${{ contains(github.event.pull_request.labels.*.name, 'perf_test') }}
44+
enabled=true
2845
29-
if [[ $is_pr != 'true' ]]; then
46+
if [[ $cache_exists == 'true' ]]; then
47+
echo "Already ran, skipping"
48+
enabled=false
49+
elif [[ $is_pr != 'true' ]]; then
3050
echo "Not a PR, running"
3151
elif [[ $is_performance_test == 'true' ]]; then
3252
if [[ $is_performance_enabled == 'true' ]]; then
3353
echo "Performance test enabled, running"
3454
else
3555
echo "Performance test disabled, skipping"
36-
exit 0
56+
enabled=false
3757
fi
3858
else
3959
echo "Validation test, running"
4060
fi
4161
62+
echo "enabled=$enabled" >> $GITHUB_OUTPUT
63+
4264
- name: Get binaries
4365
id: cache-build-binaries
4466
uses: actions/cache/restore@v4
67+
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
4568
with:
4669
fail-on-cache-miss: true
47-
path: ~/.arduino/tests/*
48-
key: tests-${{ github.event.pull_request.number || github.ref }}-${{ matrix.chip }}-${{ matrix.type }}-${{ github.event.pull_request.head.sha || github.sha }}
70+
key: ${{ env.cache-binaries-key }}
71+
path: |
72+
~/.arduino/tests/**/build*.tmp/*.bin
73+
~/.arduino/tests/**/build*.tmp/*.elf
74+
~/.arduino/tests/**/build*.tmp/*.json
4975
5076
- uses: actions/setup-python@v5
77+
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
5178
with:
5279
cache: 'pip'
5380
python-version: '3.10'
5481

5582
- name: Checkout repository
83+
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
5684
uses: actions/checkout@v4
85+
with:
86+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
5787

5888
- name: Install dependencies
89+
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
5990
run: |
6091
pip install -U pip
6192
pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi
6293
6394
- name: Run Tests
95+
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
6496
run: |
6597
bash .github/scripts/tests_run.sh -type ${{ matrix.type }} -t ${{ matrix.chip }} -e
6698
67-
- name: Upload test result artifacts
68-
uses: actions/upload-artifact@v4
69-
if: ${{ always() }}
99+
- name: Upload ${{ matrix.chip }}-${{ matrix.type }} results as cache
100+
uses: actions/cache/save@v4
101+
if: ${{ always() && steps.check-tests.outputs.enabled == 'true' }}
70102
with:
71-
name: hw_results-${{ matrix.chip }}-${{ matrix.type }}}
72-
if-no-files-found: error
103+
key: ${{ env.cache-results-key }}
73104
path: |
74105
tests/**/*.xml
75106
tests/**/result_*.json

.github/workflows/tests.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ jobs:
2222
name: Run tests on hardware
2323
uses: ./.github/workflows/hw.yml
2424
needs: call-build-tests
25-
if: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'hil_test') }}
25+
if: false
26+
#if: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'hil_test') }}
2627

2728
# call-wokwi-tests:
2829
# uses: ./.github/workflows/wokwi.yml
@@ -45,7 +46,7 @@ jobs:
4546

4647
call-clean:
4748
name: Clean objects
48-
needs: [call-build-tests, call-hardware-tests]
49+
needs: [call-hardware-tests]
4950
uses: ./.github/workflows/clean.yml
5051
if: github.event_name != 'pull_request' || github.event.action == 'closed'
5152
permissions:

.github/workflows/wokwi.yml

Lines changed: 37 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,50 @@
1-
name: Run tests in wokwi on PR
1+
name: Wokwi tests
22

33
on:
4-
workflow_run:
5-
workflows: [Run tests]
6-
types:
7-
- completed
4+
workflow_call:
85

9-
permissions:
10-
statuses: write
6+
concurrency:
7+
group: tests-wokwi-${{ github.event.pull_request.number || github.ref }}
8+
cancel-in-progress: true
119

1210
env:
13-
MAX_CHUNKS: 15
1411
WOKWI_TIMEOUT: 600000 # Milliseconds
1512
WOKWI_CLI_TOKEN: ${{ secrets.WOKWI_CLI_TOKEN }}
16-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1713

1814
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-
6915
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
7517
strategy:
7618
fail-fast: false
7719
matrix:
7820
chip: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32c6', 'esp32h2']
79-
chunks: ${{fromJson(needs.gen_chunks.outputs.chunks)}}
21+
type: ['validation']
8022
runs-on: ubuntu-latest
8123
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
8428
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
8632

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
8945
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'
9448

9549
- name: Install Wokwi CLI
9650
run: curl -L https://wokwi.com/ci/install.sh | sh
@@ -99,58 +53,17 @@ jobs:
9953
run: |
10054
pip install -U pip
10155
pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi
102-
sudo apt update && sudo apt install -y -qq jq
10356
10457
- name: Run Tests
10558
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}}
10760
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' }}
12064
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

Comments
 (0)