Skip to content

Commit ea639b0

Browse files
committed
Merge branch 'master' into test
2 parents 14a7fc8 + b8d10c9 commit ea639b0

File tree

6 files changed

+142
-46
lines changed

6 files changed

+142
-46
lines changed

.github/workflows/tests.yml

+2-39
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: Runtime Tests
33
on:
44
workflow_dispatch:
55
pull_request:
6-
types: [opened, reopened, synchronize, labeled, unlabeled]
6+
types: [opened, reopened, closed, synchronize, labeled, unlabeled]
77
paths:
8-
- '.github/workflows/tests*.yml'
8+
- '.github/workflows/tests*'
99
- '.github/scripts/*.sh'
1010
- '!.github/scripts/check-cmakelists.sh'
1111
- '!.github/scripts/find_*'
@@ -115,40 +115,3 @@ jobs:
115115
with:
116116
type: ${{ matrix.type }}
117117
chip: ${{ matrix.chip }}
118-
119-
# clean:
120-
# name: Clean objects
121-
# if: always()
122-
# permissions:
123-
# actions: write
124-
# runs-on: ubuntu-latest
125-
# steps:
126-
# - name: Clean up caches
127-
# uses: actions/github-script@v7
128-
# with:
129-
# script: |
130-
# const ref = '${{ github.event.pull_request.number || github.ref }}';
131-
# const key_prefix = 'tests-' + ref + '-';
132-
133-
# if ('${{ github.event_name }}' == 'pull_request_target' && '${{ github.event.action }}' != 'closed') {
134-
# console.log('Skipping cache cleanup for open PR');
135-
# return;
136-
# }
137-
138-
# await github.paginate(github.rest.actions.getActionsCacheList, {
139-
# owner: context.repo.owner,
140-
# repo: context.repo.repo,
141-
# per_page: 100,
142-
# key: key_prefix
143-
# }).then(caches => {
144-
# if (caches) {
145-
# for (const cache of caches) {
146-
# console.log(`Deleting cache: ${cache.key}`);
147-
# github.rest.actions.deleteActionsCacheById({
148-
# owner: context.repo.owner,
149-
# repo: context.repo.repo,
150-
# cache_id: cache.id
151-
# });
152-
# }
153-
# }
154-
# });

.github/workflows/tests_build.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
steps:
2222
- name: Check if already built
2323
id: cache-build-binaries
24+
if: github.event.pull_request.number != null
2425
uses: actions/cache/restore@v4
2526
with:
2627
key: tests-${{ env.id }}-bin
@@ -67,7 +68,7 @@ jobs:
6768
6869
- name: Upload ${{ inputs.chip }} ${{ inputs.type }} binaries as cache
6970
uses: actions/cache/save@v4
70-
if: ${{ steps.check-build.outputs.enabled == 'true' }}
71+
if: steps.check-build.outputs.enabled == 'true' && github.event.pull_request.number != null
7172
with:
7273
key: tests-${{ env.id }}-bin
7374
path: |

.github/workflows/tests_hw.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
steps:
2525
- name: Check if already passed
2626
id: cache-results
27+
if: github.event.pull_request.number != null
2728
uses: actions/cache/restore@v4
2829
with:
2930
key: tests-${{ env.id }}-results-hw
@@ -79,7 +80,7 @@ jobs:
7980
8081
- name: Upload ${{ inputs.chip }} ${{ inputs.type }} hardware results as cache
8182
uses: actions/cache/save@v4
82-
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
83+
if: steps.check-tests.outputs.enabled == 'true' && github.event.pull_request.number != null
8384
with:
8485
key: tests-${{ env.id }}-results-hw
8586
path: |

.github/workflows/tests_qemu.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
steps:
2121
- name: Check if already passed
2222
id: get-cache-results
23+
if: github.event.pull_request.number != null
2324
uses: actions/cache/restore@v4
2425
with:
2526
key: tests-${{ env.id }}-results-qemu
@@ -124,7 +125,7 @@ jobs:
124125

125126
- name: Upload ${{ inputs.chip }} ${{ inputs.type }} QEMU results as cache
126127
uses: actions/cache/save@v4
127-
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
128+
if: steps.check-tests.outputs.enabled == 'true' && github.event.pull_request.number != null
128129
with:
129130
key: tests-${{ env.id }}-results-qemu
130131
path: |

.github/workflows/tests_results.yml

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Publish and clean test results
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Wokwi tests"]
6+
types:
7+
- completed
8+
9+
# No permissions by default
10+
permissions: { contents: read }
11+
12+
jobs:
13+
unit-test-results:
14+
name: Unit Test Results
15+
if: |
16+
github.event.workflow_run.conclusion == 'success' ||
17+
github.event.workflow_run.conclusion == 'failure' ||
18+
github.event.workflow_run.conclusion == 'timed_out'
19+
runs-on: ubuntu-latest
20+
permissions:
21+
actions: write
22+
statuses: write
23+
checks: write
24+
pull-requests: write
25+
steps:
26+
- name: Download and Extract Artifacts
27+
uses: dawidd6/action-download-artifact@v6
28+
with:
29+
run_id: ${{ github.event.workflow_run.id }}
30+
path: ./artifacts
31+
32+
- name: Get original info
33+
run: |
34+
original_event=$(cat ./artifacts/parent-artifacts/event.txt)
35+
original_action=$(cat ./artifacts/parent-artifacts/action.txt)
36+
original_sha=$(cat ./artifacts/parent-artifacts/sha.txt)
37+
original_ref=$(cat ./artifacts/parent-artifacts/ref.txt)
38+
echo "original_event=$original_event" >> $GITHUB_ENV
39+
echo "original_action=$original_action" >> $GITHUB_ENV
40+
echo "original_sha=$original_sha" >> $GITHUB_ENV
41+
echo "original_ref=$original_ref" >> $GITHUB_ENV
42+
43+
echo "original_event = $original_event"
44+
echo "original_action = $original_action"
45+
echo "original_sha = $original_sha"
46+
echo "original_ref = $original_ref"
47+
48+
- name: Publish Unit Test Results
49+
uses: EnricoMi/publish-unit-test-result-action@v2
50+
with:
51+
commit: ${{ env.original_sha }}
52+
event_file: ./artifacts/parent-artifacts/event_file/event.json
53+
event_name: ${{ env.original_event }}
54+
files: ./artifacts/**/*.xml
55+
action_fail: true
56+
57+
- name: Clean up caches
58+
uses: actions/github-script@v7
59+
with:
60+
script: |
61+
const ref = '${{ env.original_ref }}';
62+
const key_prefix = 'tests-' + ref + '-';
63+
64+
if ('${{ env.original_event }}' == 'pull_request' && '${{ env.original_action }}' != 'closed') {
65+
console.log('Skipping cache cleanup for open PR');
66+
return;
67+
}
68+
69+
await github.paginate(github.rest.actions.getActionsCacheList, {
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
per_page: 100,
73+
key: key_prefix
74+
}).then(caches => {
75+
if (caches) {
76+
for (const cache of caches) {
77+
console.log(`Deleting cache: ${cache.key}`);
78+
github.rest.actions.deleteActionsCacheById({
79+
owner: context.repo.owner,
80+
repo: context.repo.repo,
81+
cache_id: cache.id
82+
});
83+
}
84+
}
85+
});
86+
87+
- name: Report conclusion
88+
uses: actions/github-script@v7
89+
if: always()
90+
with:
91+
script: |
92+
const owner = '${{ github.repository_owner }}';
93+
const repo = '${{ github.repository }}'.split('/')[1];
94+
const sha = '${{ env.original_sha }}';
95+
core.debug(`owner: ${owner}`);
96+
core.debug(`repo: ${repo}`);
97+
core.debug(`sha: ${sha}`);
98+
const { context: name, state } = (await github.rest.repos.createCommitStatus({
99+
context: 'Runtime Tests / Report results (${{ env.original_event }} -> workflow_run -> workflow_run)',
100+
owner: owner,
101+
repo: repo,
102+
sha: sha,
103+
state: '${{ job.status }}',
104+
description: '${{ job.status }}' ? 'Runtime tests successful' : 'Runtime tests failed',
105+
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
106+
})).data;
107+
core.info(`${name} is ${state}`);

.github/workflows/tests_wokwi.yml

+27-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
actions: read
2121
statuses: write
2222
outputs:
23+
pr_num: ${{ steps.set-ref.outputs.pr_num }}
2324
ref: ${{ steps.set-ref.outputs.ref }}
2425
steps:
2526
- name: Report pending
@@ -53,24 +54,45 @@ jobs:
5354
- name: Try to read PR number
5455
id: set-ref
5556
run: |
56-
ref=$(jq -r '.pull_request.number' artifacts/event_file/event.json)
57+
pr_num=$(jq -r '.pull_request.number' artifacts/event_file/event.json)
58+
if [ -z "$pr_num" ] || [ "$pr_num" == "null" ]; then
59+
pr_num=""
60+
fi
61+
62+
ref=$pr_num
5763
if [ -z "$ref" ] || [ "$ref" == "null" ]; then
5864
ref=${{ github.ref }}
5965
fi
6066
61-
echo "ref = $ref"
67+
action=$(jq -r '.action' artifacts/event_file/event.json)
68+
if [ "$action" == "null" ]; then
69+
action=""
70+
fi
71+
72+
echo "pr_num = $pr_num"
73+
74+
printf "$ref" >> artifacts/ref.txt
75+
printf "Ref = "
76+
cat artifacts/ref.txt
77+
6278
printf "${{ github.event.workflow_run.event }}" >> artifacts/event.txt
63-
printf "Event name = "
79+
printf "\nEvent name = "
6480
cat artifacts/event.txt
81+
6582
printf "${{ github.event.workflow_run.head_sha || github.sha }}" >> artifacts/sha.txt
6683
printf "\nHead SHA = "
6784
cat artifacts/sha.txt
6885
86+
printf "$action" >> artifacts/action.txt
87+
printf "\nAction = "
88+
cat artifacts/action.txt
89+
6990
if [ -z "$ref" ] || [ "$ref" == "null" ]; then
7091
echo "Failed to get PR number or ref"
7192
exit 1
7293
fi
7394
95+
echo "pr_num=$pr_num" >> $GITHUB_OUTPUT
7496
echo "ref=$ref" >> $GITHUB_OUTPUT
7597
7698
- name: Download and extract parent hardware results
@@ -162,6 +184,7 @@ jobs:
162184
163185
- name: Check if already passed
164186
id: get-cache-results
187+
if: needs.get-artifacts.outputs.pr_num
165188
uses: actions/cache/restore@v4
166189
with:
167190
key: tests-${{ env.id }}-results-wokwi
@@ -227,7 +250,7 @@ jobs:
227250
228251
- name: Upload ${{ matrix.chip }} ${{ matrix.type }} Wokwi results as cache
229252
uses: actions/cache/save@v4
230-
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
253+
if: steps.check-tests.outputs.enabled == 'true' && needs.get-artifacts.outputs.pr_num
231254
with:
232255
key: tests-${{ env.id }}-results-wokwi
233256
path: |

0 commit comments

Comments
 (0)