|
1 |
| -name: Wokwi tests |
| 1 | +name: Hardware and Wokwi tests |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | workflow_run:
|
@@ -188,6 +188,213 @@ jobs:
|
188 | 188 | })).data;
|
189 | 189 | core.info(`${name} is ${state}`);
|
190 | 190 |
|
| 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 | +
|
191 | 398 | wokwi-test:
|
192 | 399 | name: Wokwi ${{ matrix.chip }} ${{ matrix.type }} tests
|
193 | 400 | if: |
|
|
0 commit comments