summaryrefslogtreecommitdiff
path: root/.github/workflows/build-linux.yml
blob: 43578a82fbdd11a71c75c75fef1cda1ec0381424 (plain)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
name: Build Linux

on:
  workflow_call:
    inputs:
      version:
        description: "WSJT-X version string"
        required: true
        type: string
      hamlib_branch:
        description: "Hamlib branch to build"
        required: false
        type: string
        default: "4.7.2"
      arch:
        description: "Linux target architecture: x86_64, aarch64, or armhf"
        required: false
        type: string
        default: "x86_64"
      recache:
        description: "Force ccache to recompile and refresh cached objects"
        required: false
        type: boolean
        default: false
      image_tag:
        description: "Immutable GHCR image tag; empty resolves the current validated generation"
        required: false
        type: string
        default: ""
      image_source:
        description: "Builder image source: internal or prepared public-release"
        required: false
        type: string
        default: "internal"
      image_digest:
        description: "Required sha256 digest for a prepared public builder image"
        required: false
        type: string
        default: ""
      armhf_cross_image_digest:
        description: "Required sha256 digest for the public-release ARMHF cross-builder"
        required: false
        type: string
        default: ""
      allow_stale_image:
        description: "Allow a previously promoted image when a dependency refresh changed the recipe"
        required: false
        type: boolean
        default: false
      save_ccache:
        description: "Save compiled objects for trusted builds"
        required: false
        type: boolean
        default: false
      validate_fortran_fallback:
        description: "Build the x86_64 non-OpenMP common-library sentinel graph"
        required: false
        type: boolean
        default: false
      build_packages:
        description: "Build, validate, and upload Linux packages and executable artifacts"
        required: false
        type: boolean
        default: true
      armhf_build_only:
        description: "Compile and audit ARMHF production and test targets without runtime tests or packaging"
        required: false
        type: boolean
        default: false
  # Also runnable on its own ("Run workflow" / gh workflow run) to build a single
  # Linux arch without dispatching the full ci.yml matrix. GitHub only exposes
  # workflow_dispatch when the trigger is on the default branch (develop), so this
  # must be merged before it can be dispatched. This entry point supports focused
  # single-architecture diagnosis and candidate-image validation; ARMHF also joins
  # ci.yml's opt-in full-ci matrix. Inputs mirror workflow_call with standalone
  # defaults: hamlib_branch matches what ci.yml / release.yml pass (4.7.2), and
  # version is overridable via `-f version=...`. release_channel and
  # prerelease_number exist only here, to override release-state.txt.
  workflow_dispatch:
    inputs:
      version:
        description: "WSJT-X version string (artifact + package names)"
        required: false
        type: string
        default: "3.2.0-devel"
      hamlib_branch:
        description: "Hamlib branch to build"
        required: false
        type: string
        default: "4.7.2"
      arch:
        description: "Linux target architecture"
        required: false
        type: choice
        options:
          - x86_64
          - aarch64
          - armhf
        default: "x86_64"
      recache:
        description: "Force ccache to recompile and refresh cached objects"
        required: false
        type: boolean
        default: false
      image_tag:
        description: "Immutable GHCR image tag; empty resolves the current validated generation"
        required: false
        type: string
        default: ""
      image_source:
        description: "Builder image source"
        required: false
        type: choice
        options:
          - internal
          - public-release
        default: internal
      image_digest:
        description: "sha256 digest required with public-release image source"
        required: false
        type: string
        default: ""
      armhf_cross_image_digest:
        description: "sha256 digest required for the public-release ARMHF cross-builder"
        required: false
        type: string
        default: ""
      allow_stale_image:
        description: "Allow a previously promoted image when a dependency refresh changed the recipe"
        required: false
        type: boolean
        default: false
      save_ccache:
        description: "Save compiled objects"
        required: false
        type: boolean
        default: false
      validate_fortran_fallback:
        description: "Build the x86_64 non-OpenMP common-library sentinel graph"
        required: false
        type: boolean
        default: false
      build_packages:
        description: "Build, validate, and upload Linux packages and executable artifacts"
        required: false
        type: boolean
        default: true
      armhf_build_only:
        description: "Compile and audit ARMHF production and test targets without runtime tests or packaging"
        required: false
        type: boolean
        default: false
      release_channel:
        description: "Build release channel"
        required: false
        type: choice
        options:
          - DEVEL
          - BETA
          - RC
          - GA
        default: "DEVEL"
      prerelease_number:
        description: "Prerelease number when release_channel is BETA or RC"
        required: false
        type: string
        default: ""

# Architecture jobs are gated on `inputs.arch`. Each call from ci.yml /
# release.yml passes a single target, so exactly one build job runs per call.
# Splitting on arch
# keeps the per-arch runtime profile explicit at the job level:
#
#   x86_64 — validated Noble container on ubuntu-24.04.
#   aarch64 — validated GCC 13.4 Bookworm container on ubuntu-24.04-arm. This keeps the
#            Bookworm glibc 2.36 + pre-t64 library baseline while using GCC 13
#            (issue #49).
#   armhf  — native x86_64-to-ARMHF GCC 13.4 cross-build, then target tests
#            and packaging in a Bookworm arm/v7 container on ubuntu-24.04-arm,
#            which runs 32-bit ARM code natively (issue #51). DigiPi / Pi Zero
#            2W class.
#
# The native jobs use the build-linux-payload composite action. ARMHF needs
# separate host-build and target-runtime phases, but shares their artifact
# validators and external artifact contracts.

permissions:
  contents: read
  packages: read

jobs:
  resolve-image:
    runs-on: ubuntu-24.04
    timeout-minutes: 10
    outputs:
      image_tag: ${{ steps.resolve.outputs.image_tag }}
      image_reference: ${{ steps.resolve.outputs.image_reference }}
      cross_image_reference: ${{ steps.resolve.outputs.cross_image_reference }}
    steps:
      - uses: actions/checkout@v7
      - id: resolve
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          REQUESTED_TAG: ${{ inputs.image_tag }}
          ARMHF_BUILD: ${{ inputs.arch == 'armhf' }}
          ARCH: ${{ inputs.arch }}
          ARMHF_BUILD_ONLY: ${{ inputs.armhf_build_only }}
          IMAGE_SOURCE: ${{ inputs.image_source }}
          IMAGE_DIGEST: ${{ inputs.image_digest }}
          ARMHF_CROSS_IMAGE_DIGEST: ${{ inputs.armhf_cross_image_digest }}
          REQUEST_REPOSITORY: ${{ github.repository }}
          ALLOW_STALE_IMAGE: ${{ inputs.allow_stale_image }}
        shell: bash
        run: |
          if [ "$ARMHF_BUILD_ONLY" = true ] && [ "$ARCH" != armhf ]; then
            echo "::error::armhf_build_only is valid only for ARMHF builds"
            exit 2
          fi
          case "$ARCH" in
            x86_64) package=linux-noble; cross_package= ;;
            aarch64) package=linux-arm64-bookworm; cross_package= ;;
            armhf) package=linux-armv7-bookworm; cross_package=linux-armhf-cross-bookworm ;;
            *)
              echo "::error::Unsupported Linux architecture: $ARCH"
              exit 2
              ;;
          esac

          case "$IMAGE_SOURCE" in
            internal)
              if [ -n "$IMAGE_DIGEST" ] || [ -n "$ARMHF_CROSS_IMAGE_DIGEST" ]; then
                echo "::error::image digests are valid only for public-release images"
                exit 2
              fi
              package_root=ghcr.io/wsjtx/wsjtx-internal
              ;;
            public-release)
              case "$REQUEST_REPOSITORY:$GITHUB_REF" in
                WSJTX/wsjtx:refs/tags/v*|WSJTX/wsjtx-internal:refs/heads/release/*) ;;
                *)
                  echo "::error::Prepared public images require a public release tag or private release branch"
                  exit 2
                  ;;
              esac
              if [ "$ALLOW_STALE_IMAGE" = true ]; then
                echo "::error::Prepared public images require strict recipe verification"
                exit 2
              fi
              if [[ ! "$IMAGE_DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]]; then
                echo "::error::public-release images require an immutable sha256 digest"
                exit 2
              fi
              if [ "$ARCH" = armhf ]; then
                if [[ ! "$ARMHF_CROSS_IMAGE_DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]]; then
                  echo "::error::public-release ARMHF builds require an immutable cross-builder sha256 digest"
                  exit 2
                fi
              elif [ -n "$ARMHF_CROSS_IMAGE_DIGEST" ]; then
                echo "::error::armhf_cross_image_digest is valid only for ARMHF builds"
                exit 2
              fi
              if [ -z "$REQUESTED_TAG" ]; then
                echo "::error::public-release images require their validated generation tag"
                exit 2
              fi
              package_root=ghcr.io/wsjtx/wsjtx
              ;;
            *)
              echo "::error::Unsupported image_source: $IMAGE_SOURCE"
              exit 2
              ;;
          esac

          if [ -n "$REQUESTED_TAG" ]; then
            IMAGE_TAG="$REQUESTED_TAG" .github/scripts/validate-ci-inputs.sh
            echo "image_tag=$REQUESTED_TAG" >> "$GITHUB_OUTPUT"
          elif [ "$ARMHF_BUILD" = true ]; then
            RESOLVE_ARMHF=true .github/scripts/resolve-linux-ci-image-tag.py
          else
            .github/scripts/resolve-linux-ci-image-tag.py
          fi

          if [ "$IMAGE_SOURCE" = public-release ]; then
            echo "image_reference=${package_root}/${package}@${IMAGE_DIGEST}" >> "$GITHUB_OUTPUT"
            if [ "$ARCH" = armhf ]; then
              echo "cross_image_reference=${package_root}/${cross_package}@${ARMHF_CROSS_IMAGE_DIGEST}" >> "$GITHUB_OUTPUT"
            fi
          else
            image_tag="$(awk -F= '$1 == "image_tag" { print $2 }' "$GITHUB_OUTPUT" | tail -n 1)"
            echo "image_reference=${package_root}/${package}:${image_tag}" >> "$GITHUB_OUTPUT"
            if [ "$ARCH" = armhf ]; then
              echo "cross_image_reference=${package_root}/${cross_package}:${image_tag}" >> "$GITHUB_OUTPUT"
            fi
          fi

  build-x86_64:
    needs: resolve-image
    if: inputs.arch == 'x86_64'
    runs-on: ubuntu-24.04
    timeout-minutes: 65
    container:
      image: ${{ needs.resolve-image.outputs.image_reference }}
      options: --shm-size=1g
      credentials:
        username: ${{ github.actor }}
        password: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - uses: actions/checkout@v7
      - name: Validate workflow inputs
        env:
          WSJTX_VERSION: ${{ inputs.version }}
          HAMLIB_BRANCH: ${{ inputs.hamlib_branch }}
          WSJT_RELEASE_CHANNEL: ${{ inputs.release_channel }}
          WSJT_PRERELEASE_NUMBER: ${{ inputs.prerelease_number }}
          ARCH: ${{ inputs.arch }}
          IMAGE_TAG: ${{ needs.resolve-image.outputs.image_tag }}
          VALIDATE_FORTRAN_FALLBACK: ${{ inputs.validate_fortran_fallback }}
        run: .github/scripts/validate-ci-inputs.sh
      - uses: ./.github/actions/build-linux-payload
        with:
          arch: x86_64
          version: ${{ inputs.version }}
          hamlib_branch: ${{ inputs.hamlib_branch }}
          runtime_base: host
          recache: ${{ inputs.recache }}
          save_ccache: ${{ inputs.save_ccache }}
          validate_fortran_fallback: ${{ inputs.validate_fortran_fallback }}
          build_packages: ${{ inputs.build_packages }}
          release_channel: ${{ inputs.release_channel }}
          prerelease_number: ${{ inputs.prerelease_number }}
          allow_stale_image: ${{ inputs.allow_stale_image }}

  build-aarch64:
    needs: resolve-image
    if: inputs.arch == 'aarch64'
    runs-on: ubuntu-24.04-arm
    timeout-minutes: 45
    # The official GCC image adds GCC 13.4 without moving off the Bookworm
    # glibc 2.36 and pre-t64 runtime baseline (issue #49).
    container:
      image: ${{ needs.resolve-image.outputs.image_reference }}
      options: --shm-size=1g
      credentials:
        username: ${{ github.actor }}
        password: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - uses: actions/checkout@v7
      - name: Validate workflow inputs
        env:
          WSJTX_VERSION: ${{ inputs.version }}
          HAMLIB_BRANCH: ${{ inputs.hamlib_branch }}
          WSJT_RELEASE_CHANNEL: ${{ inputs.release_channel }}
          WSJT_PRERELEASE_NUMBER: ${{ inputs.prerelease_number }}
          ARCH: ${{ inputs.arch }}
          IMAGE_TAG: ${{ needs.resolve-image.outputs.image_tag }}
          VALIDATE_FORTRAN_FALLBACK: ${{ inputs.validate_fortran_fallback }}
        run: .github/scripts/validate-ci-inputs.sh
      - uses: ./.github/actions/build-linux-payload
        with:
          arch: aarch64
          version: ${{ inputs.version }}
          hamlib_branch: ${{ inputs.hamlib_branch }}
          runtime_base: bookworm-gcc13.4
          recache: ${{ inputs.recache }}
          save_ccache: ${{ inputs.save_ccache }}
          validate_fortran_fallback: ${{ inputs.validate_fortran_fallback }}
          build_packages: ${{ inputs.build_packages }}
          release_channel: ${{ inputs.release_channel }}
          prerelease_number: ${{ inputs.prerelease_number }}
          allow_stale_image: ${{ inputs.allow_stale_image }}

  build-armhf:
    needs: resolve-image
    if: inputs.arch == 'armhf'
    runs-on: ubuntu-24.04
    timeout-minutes: 60
    # Compile natively on x86_64 with a pinned GCC 13.4 cross-toolchain;
    # test-armhf then runs the target tests and packaging on an ARM runner.
    #
    # Keep JavaScript actions on the host: the runner's x86_64 Node runtime
    # cannot execute in the ARMv7 container. Every explicit container mounts
    # the checkout at /work so CTest paths stay valid in test-armhf.
    env:
      VERSION: ${{ inputs.version }}
      HAMLIB_BRANCH: ${{ inputs.hamlib_branch }}
      WSJT_RELEASE_CHANNEL: ${{ inputs.release_channel }}
      WSJT_PRERELEASE_NUMBER: ${{ inputs.prerelease_number }}
    steps:
      # setup-qemu-action runs on the host (job has no `container:`),
      # mutating the host kernel's binfmt_misc table, so the image pair
      # check below can run the ARMv7 runtime image's smoke programs.
      - uses: docker/setup-qemu-action@v4
        with:
          image: tonistiigi/binfmt:qemu-v10.2.3-68@sha256:400a4873b838d1b89194d982c45e5fb3cda4593fbfd7e08a02e76b03b21166f0
          platforms: linux/arm/v7
      - uses: actions/checkout@v7
      - name: Validate workflow inputs
        env:
          WSJTX_VERSION: ${{ inputs.version }}
          HAMLIB_BRANCH: ${{ inputs.hamlib_branch }}
          WSJT_RELEASE_CHANNEL: ${{ inputs.release_channel }}
          WSJT_PRERELEASE_NUMBER: ${{ inputs.prerelease_number }}
          ARCH: armhf
          IMAGE_TAG: ${{ needs.resolve-image.outputs.image_tag }}
          VALIDATE_FORTRAN_FALLBACK: ${{ inputs.validate_fortran_fallback }}
        run: .github/scripts/validate-ci-inputs.sh

      - uses: docker/login-action@v4
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Inspect ARMHF image pair
        id: image
        env:
          CROSS_BUILDER_IMAGE: ${{ needs.resolve-image.outputs.cross_image_reference }}
          RUNTIME_IMAGE: ${{ needs.resolve-image.outputs.image_reference }}
          ALLOW_STALE_IMAGE: ${{ inputs.allow_stale_image }}
          HAMLIB_BRANCH: ${{ inputs.hamlib_branch }}
        run: |
          docker pull --platform linux/amd64 "$CROSS_BUILDER_IMAGE"
          docker pull --platform linux/arm/v7 "$RUNTIME_IMAGE"
          output_file=.armhf-image-verification-output
          trap 'rm -f "$output_file"' EXIT
          docker run --rm --platform linux/amd64 \
            -v "${GITHUB_WORKSPACE}:/work" \
            -w /work \
            -e GITHUB_OUTPUT=/work/$output_file \
            -e WSJTX_CI_OUTPUT_PREFIX=cross_ \
            -e WSJTX_CI_IMAGE_ALLOW_RECIPE_MISMATCH="$ALLOW_STALE_IMAGE" \
            "$CROSS_BUILDER_IMAGE" \
            bash .github/scripts/verify-armhf-ci-image.sh cross-builder armhf "$HAMLIB_BRANCH"
          docker run --rm --platform linux/arm/v7 \
            -v "${GITHUB_WORKSPACE}:/work" \
            -w /work \
            -e GITHUB_OUTPUT=/work/$output_file \
            -e WSJTX_CI_OUTPUT_PREFIX=runtime_ \
            -e WSJTX_CI_IMAGE_ALLOW_RECIPE_MISMATCH="$ALLOW_STALE_IMAGE" \
            "$RUNTIME_IMAGE" \
            bash .github/scripts/verify-armhf-ci-image.sh runtime armhf "$HAMLIB_BRANCH"

          cross_generation=$(awk -F= '$1 == "cross_generation" { print $2 }' "$output_file")
          runtime_generation=$(awk -F= '$1 == "runtime_generation" { print $2 }' "$output_file")
          cross_toolchain_id=$(awk -F= '$1 == "cross_toolchain_id" { print $2 }' "$output_file")
          runtime_toolchain_id=$(awk -F= '$1 == "runtime_toolchain_id" { print $2 }' "$output_file")
          if [ "$cross_generation" != "$runtime_generation" ]; then
            echo "ARMHF image generation mismatch: $cross_generation != $runtime_generation" >&2
            exit 1
          fi
          if [ "$cross_toolchain_id" != "$runtime_toolchain_id" ]; then
            echo "ARMHF toolchain identity mismatch: $cross_toolchain_id != $runtime_toolchain_id" >&2
            exit 1
          fi
          cross_recipe_match=$(awk -F= '$1 == "cross_recipe_match" { print $2 }' "$output_file")
          runtime_recipe_match=$(awk -F= '$1 == "runtime_recipe_match" { print $2 }' "$output_file")
          recipe_match=false
          if [ "$cross_recipe_match" = true ] && [ "$runtime_recipe_match" = true ]; then
            recipe_match=true
          fi
          ccache_compatibility_id=$(awk -F= '$1 == "cross_ccache_compatibility_id" { print $2 }' "$output_file")
          ccache_compiler_check=$(awk -F= '$1 == "cross_ccache_compiler_check" { print $2 }' "$output_file")
          # Empty manifest values could coalesce caches from incompatible
          # toolchains, so reject them before constructing any cache key.
          if [ -z "$ccache_compatibility_id" ] || [ -z "$ccache_compiler_check" ]; then
            echo "ARMHF image verification returned incomplete ccache identity" >&2
            exit 1
          fi
          {
            echo "generation=$cross_generation"
            echo "recipe_match=$recipe_match"
            echo "ccache_compatibility_id=$ccache_compatibility_id"
            echo "ccache_compiler_check=$ccache_compiler_check"
          } >> "$GITHUB_OUTPUT"

      - name: Select armhf ccache key
        id: ccache-key
        env:
          RECACHE: ${{ inputs.recache }}
        run: .github/scripts/select-ccache-key-suffix.sh

      - name: Restore armhf ccache
        id: ccache
        uses: actions/cache/restore@v6
        with:
          path: .ccache-armhf
          key: ccache-linux-armhf-${{ steps.image.outputs.ccache_compatibility_id }}-${{ steps.image.outputs.generation }}-${{ github.sha }}${{ steps.ccache-key.outputs.suffix }}
          restore-keys: |
            ccache-linux-armhf-${{ steps.image.outputs.ccache_compatibility_id }}-${{ steps.image.outputs.generation }}-
            ccache-linux-armhf-${{ steps.image.outputs.ccache_compatibility_id }}-

      - name: Cross-build ARMHF binaries
        id: cross-build
        env:
          ARCH: armhf
          CROSS_BUILDER_IMAGE: ${{ needs.resolve-image.outputs.cross_image_reference }}
          RECACHE: ${{ inputs.recache }}
          ARMHF_BUILD_ONLY: ${{ inputs.armhf_build_only }}
          CCACHE_COMPILERCHECK: ${{ steps.image.outputs.ccache_compiler_check }}
          WSJTX_CI_IMAGE_ALLOW_RECIPE_MISMATCH: ${{ inputs.allow_stale_image }}
        run: |
          ccache_args=()
          if [ "$RECACHE" = true ]; then
            ccache_args=(-e CCACHE_RECACHE=1)
          fi
          docker run --rm --platform linux/amd64 \
            -v "${GITHUB_WORKSPACE}:/work" \
            -w /work \
            -e VERSION \
            -e HAMLIB_BRANCH \
            -e ARCH \
            -e WSJT_RELEASE_CHANNEL \
            -e WSJT_PRERELEASE_NUMBER \
            -e CCACHE_DIR=/work/.ccache-armhf \
            -e CCACHE_COMPILERCHECK \
            -e ARMHF_BUILD_ONLY \
            -e WSJTX_CI_IMAGE_ALLOW_RECIPE_MISMATCH \
            "${ccache_args[@]}" \
            "$CROSS_BUILDER_IMAGE" \
            bash .github/scripts/build-linux-armhf-cross.sh

      - name: Report suppressed armhf ccache save
        if: inputs.save_ccache && steps.image.outputs.recipe_match != 'true'
        run: echo "::notice::Not saving armhf ccache because this build used a stale Linux CI image recipe"

      - name: Save armhf ccache
        id: save-ccache
        if: inputs.save_ccache && (!inputs.armhf_build_only || github.ref == 'refs/heads/develop') && steps.image.outputs.recipe_match == 'true' && steps.ccache.outputs.cache-hit != 'true'
        uses: actions/cache/save@v6
        with:
          path: .ccache-armhf
          key: ${{ steps.ccache.outputs.cache-primary-key }}

      # test-armhf runs the tests and packaging on an ARM runner from this
      # tree. tar keeps the modes, links and times upload-artifact drops;
      # objects and static libraries are only needed to link.
      - name: Pack ARMHF build tree
        if: ${{ !inputs.armhf_build_only }}
        run: |
          sudo tar --create --file armhf-build-tree.tar --exclude='wsjtx-build/*.o' --exclude='wsjtx-build/*.a' wsjtx-build AppDir
          ls -l armhf-build-tree.tar

      # Kept one day: re-running test-armhf alone works within that window.
      - name: Upload ARMHF build tree
        if: ${{ !inputs.armhf_build_only }}
        uses: actions/upload-artifact@v7
        with:
          name: armhf-build-tree
          path: armhf-build-tree.tar
          if-no-files-found: error
          retention-days: 1

      - name: Summarize ARMHF compiler cache
        if: always()
        env:
          CACHE_STEPS: ${{ toJSON(steps) }}
          SAVE_CCACHE: ${{ inputs.save_ccache }}
          ARMHF_BUILD_ONLY: ${{ inputs.armhf_build_only }}
        run: |
          python3 - <<'PY' >> "$GITHUB_STEP_SUMMARY"
          import json
          import os
          from pathlib import Path

          steps = json.loads(os.environ["CACHE_STEPS"])
          cache = steps.get("ccache", {})
          outputs = cache.get("outputs", {})
          restore = "exact hit" if outputs.get("cache-hit") == "true" else "fallback restore" if outputs.get("cache-matched-key") else "miss"
          if cache.get("outcome") != "success":
              restore = cache.get("outcome", "not run")
          image = steps.get("image", {}).get("outputs", {})
          build_only = os.environ["ARMHF_BUILD_ONLY"] == "true"
          save = steps.get("save-ccache", {}).get("outcome", "skipped")
          timing = Path("wsjtx-build/armhf-cross-build-timing.env")
          duration = "unavailable"
          if timing.exists():
              duration = dict(line.split("=", 1) for line in timing.read_text().splitlines()).get("duration_seconds", duration)
          if os.environ["SAVE_CCACHE"] != "true":
              publication = "disabled"
          elif build_only and os.environ["GITHUB_REF"] != "refs/heads/develop":
              publication = "skipped: build-only cache writes require develop"
          elif image.get("recipe_match") == "false":
              publication = "skipped: image recipe mismatch"
          elif save != "skipped":
              publication = f"attempted (step: {save}); see cache action log for upload confirmation"
          elif any(step.get("outcome") in ("failure", "cancelled") for step in steps.values()):
              publication = "skipped: preceding failure or cancellation"
          elif outputs.get("cache-hit") == "true":
              publication = "skipped: exact cache already exists"
          else:
              publication = "not attempted"
          print("### ARMHF compiler cache\n")
          print("| Field | Value |\n| --- | --- |")
          rows = {
              "Source SHA": os.environ["GITHUB_SHA"],
              "Image generation": image.get("generation", "unavailable"),
              "Requested/save key": outputs.get("cache-primary-key", "unavailable"),
              "Matched key": outputs.get("cache-matched-key") or "none",
              "Restore": restore,
              "Compilation and binary audits": steps.get("cross-build", {}).get("outcome", "not run"),
              "Compilation duration (seconds)": duration,
              "Cache publication": publication,
          }
          for label, value in rows.items():
              print(f"| {label} | {value} |")
          PY

  test-armhf:
    needs: [resolve-image, build-armhf]
    if: inputs.arch == 'armhf' && !inputs.armhf_build_only
    # ubuntu-24.04-arm executes 32-bit ARM code natively, so the runtime
    # image runs here without QEMU.
    runs-on: ubuntu-24.04-arm
    timeout-minutes: 90
    env:
      VERSION: ${{ inputs.version }}
      HAMLIB_BRANCH: ${{ inputs.hamlib_branch }}
      WSJT_RELEASE_CHANNEL: ${{ inputs.release_channel }}
      WSJT_PRERELEASE_NUMBER: ${{ inputs.prerelease_number }}
    steps:
      - uses: actions/checkout@v7

      - uses: docker/login-action@v4
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      # A CPU without 32-bit ARM support cannot run the image, and a registered
      # qemu-arm handler would run it emulated without saying so.
      - name: Require native 32-bit ARM execution
        env:
          RUNTIME_IMAGE: ${{ needs.resolve-image.outputs.image_reference }}
        run: |
          lscpu | grep -E '^(Model name|CPU op-mode)'
          if ! lscpu | grep -Eq '^CPU op-mode\(s\):.*32-bit'; then
            echo "::error::This runner cannot execute 32-bit ARM code"
            exit 1
          fi
          if [ -e /proc/sys/fs/binfmt_misc/qemu-arm ]; then
            echo "::error::A qemu-arm binfmt handler is registered, so ARMHF would run emulated"
            exit 1
          fi
          bits=$(docker run --rm --platform linux/arm/v7 "$RUNTIME_IMAGE" getconf LONG_BIT)
          if [ "$bits" != 32 ]; then
            echo "::error::The ARMHF runtime image reports LONG_BIT=${bits}"
            exit 1
          fi

      - name: Download ARMHF build tree
        uses: actions/download-artifact@v8
        with:
          name: armhf-build-tree

      - name: Unpack ARMHF build tree
        run: |
          sudo tar --extract --file armhf-build-tree.tar
          rm armhf-build-tree.tar

      - name: Test and package on native ARMv7
        id: armhf-runtime
        env:
          ARCH: armhf
          RUNTIME_IMAGE: ${{ needs.resolve-image.outputs.image_reference }}
          WSJTX_CI_IMAGE_ALLOW_RECIPE_MISMATCH: ${{ inputs.allow_stale_image }}
          ARMHF_RUNTIME_PHASE: ${{ inputs.build_packages && 'all' || 'test' }}
        run: |
          GITHUB_TOKEN="${{ github.token }}" docker run --rm --platform linux/arm/v7 \
            --shm-size=1g \
            -v "${GITHUB_WORKSPACE}:/work" \
            -w /work \
            -e VERSION \
            -e HAMLIB_BRANCH \
            -e ARCH \
            -e GITHUB_TOKEN \
            -e ARMHF_RUNTIME_PHASE \
            -e WSJTX_CI_IMAGE_ALLOW_RECIPE_MISMATCH \
            "$RUNTIME_IMAGE" \
            bash .github/scripts/validate-linux-armhf-runtime.sh

      - name: Test shared-memory allocation failure on native ARMv7
        env:
          RUNTIME_IMAGE: ${{ needs.resolve-image.outputs.image_reference }}
        run: |
          docker run --rm --platform linux/arm/v7 \
            --shm-size=16m \
            -v "${GITHUB_WORKSPACE}:/work" \
            -w /work \
            -e WSJTX_TEST_SMALL_SHM=1 \
            "$RUNTIME_IMAGE" \
            bash -euo pipefail -c '
              source .github/scripts/armhf-ci-image-config.sh
              LD_LIBRARY_PATH="$ARMHF_RUNTIME_PREFIX" \
                wsjtx-build/tests/unit/decoder_ipc/test_decoder_ipc_handshake insufficientLinuxSharedMemory
            '

      - name: Publish armhf test summary
        if: always()
        run: >-
          python3 .github/scripts/publish-ctest-summary.py
          "Linux armhf" wsjtx-build/ctest-results.xml
          >> "$GITHUB_STEP_SUMMARY"

      - name: Upload armhf AppImage startup diagnostics
        if: inputs.build_packages && failure() && steps.armhf-runtime.outcome == 'failure'
        uses: actions/upload-artifact@v7
        with:
          name: wsjtx-startup-smoke-linux-armhf
          path: wsjtx-build/appimage-startup-smoke.log
          if-no-files-found: ignore
          retention-days: 7

      # Artifacts produced inside the container land in $GITHUB_WORKSPACE
      # via the bind-mount. Upload from the host where actions/upload-
      # artifact runs natively. Same artifact names as the composite
      # action's uploads so release.yml's all-platforms-ready gate
      # pattern works unchanged.
      - name: Upload .deb
        if: inputs.build_packages
        uses: actions/upload-artifact@v7
        with:
          name: wsjtx-${{ inputs.version }}-linux-armhf-deb
          path: wsjtx-build/wsjtx-${{ inputs.version }}-linux-armhf.deb
          if-no-files-found: error
          compression-level: 0
      - name: Upload RPM
        if: inputs.build_packages
        uses: actions/upload-artifact@v7
        with:
          name: wsjtx-${{ inputs.version }}-linux-armhf-rpm
          path: wsjtx-build/*.rpm
          if-no-files-found: error
          compression-level: 0
      - name: Upload AppImage
        if: inputs.build_packages
        uses: actions/upload-artifact@v7
        with:
          name: wsjtx-${{ inputs.version }}-linux-armhf-AppImage
          path: wsjtx-${{ inputs.version }}-linux-armhf.AppImage
          if-no-files-found: error
          compression-level: 0
      - name: Upload build artifacts
        if: inputs.build_packages
        uses: actions/upload-artifact@v7
        with:
          name: wsjtx-${{ inputs.version }}-linux-armhf
          path: |
            wsjtx-build/jt9
            wsjtx-build/wsprd
            wsjtx-build/wsjtx
      - name: Upload release tarballs
        if: inputs.build_packages
        uses: ./.github/actions/upload-release-tarballs
        with:
          version: ${{ inputs.version }}
          target: linux-armhf
          directory: release-tarballs
      - name: Upload test results
        if: always()
        uses: actions/upload-artifact@v7
        with:
          name: ctest-results-linux-armhf
          path: wsjtx-build/ctest-results.xml
          if-no-files-found: ignore