Skip to content

Commit c8f1035

Browse files
committed
Merge branch 'ci/hw_gitlab'
2 parents 5c8cc7a + ad5489e commit c8f1035

File tree

7 files changed

+288
-159
lines changed

7 files changed

+288
-159
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,8 @@ jobs:
8989
type: ${{ matrix.type }}
9090
chip: ${{ matrix.chip }}
9191

92-
call-hardware-tests:
93-
name: Hardware
94-
uses: ./.github/workflows/tests_hw.yml
95-
needs: [gen-matrix, call-build-tests]
96-
if: |
97-
github.repository == 'espressif/arduino-esp32' &&
98-
(github.event_name != 'pull_request' ||
99-
contains(github.event.pull_request.labels.*.name, 'hil_test'))
100-
strategy:
101-
fail-fast: false
102-
matrix:
103-
type: ${{ fromJson(needs.gen-matrix.outputs.hw-types) }}
104-
chip: ${{ fromJson(needs.gen-matrix.outputs.targets) }}
105-
with:
106-
type: ${{ matrix.type }}
107-
chip: ${{ matrix.chip }}
92+
# Hardware tests now run via workflow_run trigger in tests_hw_wokwi.yml
93+
# This provides secure access to GitLab secrets while maintaining the same functionality
10894

10995
# This job is disabled for now
11096
call-qemu-tests:

.github/workflows/tests_hw.yml

Lines changed: 0 additions & 122 deletions
This file was deleted.

.github/workflows/tests_wokwi.yml renamed to .github/workflows/tests_hw_wokwi.yml

Lines changed: 208 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Wokwi tests
1+
name: Hardware and Wokwi tests
22

33
on:
44
workflow_run:
@@ -188,6 +188,213 @@ jobs:
188188
})).data;
189189
core.info(`${name} is ${state}`);
190190
191+
hardware-test:
192+
name: Hardware ${{ matrix.chip }} ${{ matrix.type }} tests
193+
if: |
194+
(github.event.workflow_run.conclusion == 'success' ||
195+
github.event.workflow_run.conclusion == 'failure' ||
196+
github.event.workflow_run.conclusion == 'timed_out')
197+
runs-on: ubuntu-latest
198+
needs: get-artifacts
199+
env:
200+
id: ${{ needs.get-artifacts.outputs.ref }}-${{ github.event.workflow_run.head_sha || github.sha }}-${{ matrix.chip }}-${{ matrix.type }}
201+
permissions:
202+
actions: read
203+
statuses: write
204+
strategy:
205+
fail-fast: false
206+
matrix:
207+
type: ${{ fromJson(needs.get-artifacts.outputs.types) }}
208+
chip: ${{ fromJson(needs.get-artifacts.outputs.targets) }}
209+
steps:
210+
- name: Report pending
211+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
212+
with:
213+
script: |
214+
const owner = '${{ github.repository_owner }}';
215+
const repo = '${{ github.repository }}'.split('/')[1];
216+
const sha = '${{ github.event.workflow_run.head_sha }}';
217+
core.debug(`owner: ${owner}`);
218+
core.debug(`repo: ${repo}`);
219+
core.debug(`sha: ${sha}`);
220+
const { context: name, state } = (await github.rest.repos.createCommitStatus({
221+
context: 'Runtime Tests / Hardware (${{ matrix.type }}, ${{ matrix.chip }}) / Hardware ${{ matrix.chip }} ${{ matrix.type }} tests (${{ github.event.workflow_run.event }} -> workflow_run)',
222+
owner: owner,
223+
repo: repo,
224+
sha: sha,
225+
state: 'pending',
226+
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
227+
})).data;
228+
core.info(`${name} is ${state}`);
229+
230+
- name: Check if already passed
231+
id: get-cache-results
232+
if: needs.get-artifacts.outputs.pr_num
233+
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
234+
with:
235+
key: test-${{ env.id }}-results-hw
236+
path: |
237+
tests/**/*.xml
238+
tests/**/result_*.json
239+
240+
- name: Download parent artifacts to check conditions
241+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
242+
with:
243+
github-token: ${{ secrets.GITHUB_TOKEN }}
244+
run-id: ${{ github.event.workflow_run.id }}
245+
name: parent-artifacts
246+
path: parent-artifacts
247+
248+
- name: Evaluate if tests should be run
249+
id: check-tests
250+
run: |
251+
cache_exists=${{ steps.get-cache-results.outputs.cache-hit == 'true' }}
252+
enabled=true
253+
254+
# Check cache first
255+
if [[ $cache_exists == 'true' ]]; then
256+
echo "Already ran, skipping GitLab pipeline trigger"
257+
enabled=false
258+
else
259+
echo "Cache miss, checking if hardware tests should run..."
260+
261+
# Check if it's a PR and if it has the hil_test label
262+
if [ -f "parent-artifacts/event_file/event.json" ]; then
263+
event_name=$(jq -r '.event_name // empty' parent-artifacts/event_file/event.json 2>/dev/null || echo "")
264+
is_pr=$(jq -r '.pull_request.number // empty' parent-artifacts/event_file/event.json 2>/dev/null || echo "")
265+
266+
echo "Event name: $event_name"
267+
echo "Is PR: $is_pr"
268+
269+
if [[ -n "$is_pr" ]]; then
270+
# This is a PR, check for hil_test label
271+
has_hil_label=$(jq -r '.pull_request.labels[]?.name' parent-artifacts/event_file/event.json 2>/dev/null | grep -q "hil_test" && echo "true" || echo "false")
272+
echo "Has hil_test label: $has_hil_label"
273+
274+
if [[ "$has_hil_label" != "true" ]]; then
275+
echo "PR does not have hil_test label, skipping hardware tests"
276+
enabled=false
277+
fi
278+
else
279+
echo "Not a PR, hardware tests will run"
280+
fi
281+
else
282+
echo "Could not find event file, defaulting to enabled"
283+
fi
284+
fi
285+
286+
echo "Final decision - enabled=$enabled"
287+
echo "enabled=$enabled" >> $GITHUB_OUTPUT
288+
289+
- name: Checkout repository
290+
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
291+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
292+
with:
293+
ref: ${{ needs.get-artifacts.outputs.base || github.ref }}
294+
295+
- name: Get test binaries
296+
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
297+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
298+
with:
299+
github-token: ${{ secrets.GITHUB_TOKEN }}
300+
run-id: ${{ github.event.workflow_run.id }}
301+
name: test-bin-${{ matrix.chip }}-${{ matrix.type }}
302+
path: test-binaries
303+
304+
- name: Trigger GitLab Pipeline and Download Artifacts
305+
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
306+
uses: digital-blueprint/[email protected]
307+
id: gitlab-trigger
308+
with:
309+
host: ${{ secrets.GITLAB_URL }}
310+
id: ${{ secrets.GITLAB_PROJECT_ID }}
311+
ref: 'ci/hw_gitlab'
312+
#ref: 'master'
313+
trigger_token: ${{ secrets.GITLAB_TRIGGER_TOKEN }}
314+
access_token: ${{ secrets.GITLAB_ACCESS_TOKEN }}
315+
download_artifacts: 'true'
316+
download_artifacts_on_failure: 'true'
317+
download_path: './gitlab-artifacts'
318+
variables: |
319+
'{
320+
"TEST_TYPE":"${{ matrix.type }}",
321+
"TEST_CHIP":"${{ matrix.chip }}",
322+
"PIPELINE_ID":"${{ env.id }}",
323+
"BINARIES_RUN_ID":"${{ github.event.workflow_run.id }}",
324+
"GITHUB_REPOSITORY":"${{ github.repository }}"
325+
}'
326+
327+
- name: Process Downloaded Artifacts
328+
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
329+
run: |
330+
echo "GitLab Pipeline Status: ${{ steps.gitlab-trigger.outputs.status }}"
331+
echo "Artifacts Downloaded: ${{ steps.gitlab-trigger.outputs.artifacts_downloaded }}"
332+
333+
# Create tests directory structure expected by GitHub caching
334+
mkdir -p tests
335+
336+
# Process downloaded GitLab artifacts
337+
if [ "${{ steps.gitlab-trigger.outputs.artifacts_downloaded }}" = "true" ]; then
338+
echo "Processing downloaded GitLab artifacts..."
339+
340+
# The action downloads artifacts organized by job:
341+
# gitlab-artifacts/job_123_job_name_1/artifacts/...
342+
# gitlab-artifacts/job_124_job_name_2/artifacts/...
343+
344+
# Print the contents of the gitlab-artifacts directory to debug
345+
echo "Contents of gitlab-artifacts directory:"
346+
ls -la ./gitlab-artifacts/
347+
348+
# Find and copy test result files
349+
find ./gitlab-artifacts -name "*.xml" -exec cp {} tests/ \;
350+
find ./gitlab-artifacts -name "result_*.json" -exec cp {} tests/ \;
351+
352+
echo "Test results found:"
353+
ls -la tests/ || echo "No test results found"
354+
else
355+
echo "No artifacts were downloaded from GitLab"
356+
fi
357+
358+
- name: Upload ${{ matrix.chip }} ${{ matrix.type }} hardware results as cache
359+
uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
360+
if: steps.check-tests.outputs.enabled == 'true' && needs.get-artifacts.outputs.pr_num
361+
with:
362+
key: test-${{ env.id }}-results-hw
363+
path: |
364+
tests/**/*.xml
365+
tests/**/result_*.json
366+
367+
- name: Upload ${{ matrix.chip }} ${{ matrix.type }} hardware results as artifacts
368+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
369+
if: always()
370+
with:
371+
name: test-results-hw-${{ matrix.chip }}-${{ matrix.type }}
372+
overwrite: true
373+
path: |
374+
tests/**/*.xml
375+
tests/**/result_*.json
376+
377+
- name: Report conclusion
378+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
379+
if: always()
380+
with:
381+
script: |
382+
const owner = '${{ github.repository_owner }}';
383+
const repo = '${{ github.repository }}'.split('/')[1];
384+
const sha = '${{ github.event.workflow_run.head_sha }}';
385+
core.debug(`owner: ${owner}`);
386+
core.debug(`repo: ${repo}`);
387+
core.debug(`sha: ${sha}`);
388+
const { context: name, state } = (await github.rest.repos.createCommitStatus({
389+
context: 'Runtime Tests / Hardware (${{ matrix.type }}, ${{ matrix.chip }}) / Hardware ${{ matrix.chip }} ${{ matrix.type }} tests (${{ github.event.workflow_run.event }} -> workflow_run)',
390+
owner: owner,
391+
repo: repo,
392+
sha: sha,
393+
state: '${{ job.status }}',
394+
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
395+
})).data;
396+
core.info(`${name} is ${state}`);
397+
191398
wokwi-test:
192399
name: Wokwi ${{ matrix.chip }} ${{ matrix.type }} tests
193400
if: |

.github/workflows/tests_results.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Publish and clean test results
22

33
on:
44
workflow_run:
5-
workflows: ["Wokwi tests"]
5+
workflows: ["Hardware and Wokwi tests"]
66
types:
77
- completed
88

@@ -80,8 +80,8 @@ jobs:
8080
8181
- name: Print links to other runs
8282
run: |
83-
echo "Build, Hardware and QEMU tests: https://github.com/${{ github.repository }}/actions/runs/${{ env.original_run_id }}"
84-
echo "Wokwi tests: https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}"
83+
echo "Build and QEMU tests: https://github.com/${{ github.repository }}/actions/runs/${{ env.original_run_id }}"
84+
echo "Hardware and Wokwi tests: https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}"
8585
8686
- name: Publish Unit Test Results
8787
uses: EnricoMi/publish-unit-test-result-action@170bf24d20d201b842d7a52403b73ed297e6645b # v2.18.0

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ workflow:
2222

2323
include:
2424
- ".gitlab/workflows/common.yml"
25-
- ".gitlab/workflows/sample.yml"
25+
- ".gitlab/workflows/hardware_tests.yml"

0 commit comments

Comments
 (0)