summaryrefslogtreecommitdiff
path: root/.github/workflows/public-release.yml
blob: 14d4e611de989d4fef7ab0a46e2e10c849c9d3e2 (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
name: Build and Publish Public Release

on:
  push:
    tags: ["v*"]

permissions:
  contents: read

concurrency:
  group: public-release-${{ github.ref }}
  cancel-in-progress: false

jobs:
  prepare:
    if: github.repository == 'WSJTX/wsjtx'
    runs-on: ubuntu-latest
    timeout-minutes: 10
    outputs:
      version: ${{ steps.identity.outputs.version }}
      release_channel: ${{ steps.identity.outputs.channel }}
      rc_number: ${{ steps.identity.outputs.rc_number }}
      macos_sign_mode: ${{ steps.identity.outputs.macos_sign_mode }}
      windows_signing: ${{ steps.identity.outputs.windows_signing }}
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - name: Validate public release tag and source identity
        id: identity
        env:
          MACOS_DISTRIBUTION_SIGNING_ENABLED: ${{ vars.MACOS_DISTRIBUTION_SIGNING_ENABLED }}
        run: |
          set -euo pipefail
          if [[ ! "$GITHUB_REF_NAME" =~ ^v(.+)$ ]]; then
            echo "::error::Expected vX.Y.Z or vX.Y.Z-rcN"
            exit 1
          fi
          VERSION="${GITHUB_REF_NAME#v}"
          IDENTITY=$(python3 .github/scripts/release-policy.py validate-source "$VERSION")
          {
            echo "version=$(jq -r .version <<<"$IDENTITY")"
            echo "channel=$(jq -r .channel <<<"$IDENTITY")"
            echo "rc_number=$(jq -r .rc_number <<<"$IDENTITY")"
            echo "windows_signing=$(jq -r .windows_signing <<<"$IDENTITY")"
          } >> "$GITHUB_OUTPUT"
          if [ "$MACOS_DISTRIBUTION_SIGNING_ENABLED" = true ]; then
            echo "macos_sign_mode=distribution" >> "$GITHUB_OUTPUT"
          else
            echo "macos_sign_mode=validation" >> "$GITHUB_OUTPUT"
            echo "::notice::macOS distribution signing is disabled. Validated packages will be published for manual replacement."
          fi

  linux-images:
    needs: prepare
    uses: ./.github/workflows/publish-linux-ci-images.yml
    permissions:
      contents: read
      packages: write
    with:
      publication_target: public-release
      mode: refresh
      promote: false
      image_set: normal
      include_armhf: true

  macos:
    needs: prepare
    uses: ./.github/workflows/build-macos.yml
    permissions:
      actions: read
      contents: read
    with:
      version: ${{ needs.prepare.outputs.version }}
      hamlib_branch: "4.7.2"
      arch: arm64
      runner: macos-15
      deployment_target: "11.0"
      release_channel: ${{ needs.prepare.outputs.release_channel }}
      rc_number: ${{ needs.prepare.outputs.rc_number }}
      signing_mode: ${{ needs.prepare.outputs.macos_sign_mode }}

  macos-intel:
    needs: prepare
    uses: ./.github/workflows/build-macos.yml
    permissions:
      actions: read
      contents: read
    with:
      version: ${{ needs.prepare.outputs.version }}
      hamlib_branch: "4.7.2"
      arch: x86_64
      runner: macos-15-intel
      deployment_target: "10.13"
      release_channel: ${{ needs.prepare.outputs.release_channel }}
      rc_number: ${{ needs.prepare.outputs.rc_number }}
      signing_mode: ${{ needs.prepare.outputs.macos_sign_mode }}

  linux:
    needs: [prepare, linux-images]
    uses: ./.github/workflows/build-linux.yml
    permissions:
      actions: read
      contents: read
      packages: read
    with:
      version: ${{ needs.prepare.outputs.version }}
      hamlib_branch: "4.7.2"
      arch: x86_64
      image_source: public-release
      image_tag: ${{ needs.linux-images.outputs.image_tag }}
      image_digest: ${{ needs.linux-images.outputs.x86_64_digest }}
      build_packages: true
      release_channel: ${{ needs.prepare.outputs.release_channel }}
      rc_number: ${{ needs.prepare.outputs.rc_number }}

  linux-arm:
    needs: [prepare, linux-images]
    uses: ./.github/workflows/build-linux.yml
    permissions:
      actions: read
      contents: read
      packages: read
    with:
      version: ${{ needs.prepare.outputs.version }}
      hamlib_branch: "4.7.2"
      arch: aarch64
      image_source: public-release
      image_tag: ${{ needs.linux-images.outputs.image_tag }}
      image_digest: ${{ needs.linux-images.outputs.aarch64_digest }}
      build_packages: true
      release_channel: ${{ needs.prepare.outputs.release_channel }}
      rc_number: ${{ needs.prepare.outputs.rc_number }}

  linux-armhf:
    needs: [prepare, linux-images]
    uses: ./.github/workflows/build-linux.yml
    permissions:
      actions: read
      contents: read
      packages: read
    with:
      version: ${{ needs.prepare.outputs.version }}
      hamlib_branch: "4.7.2"
      arch: armhf
      image_source: public-release
      image_tag: ${{ needs.linux-images.outputs.image_tag }}
      image_digest: ${{ needs.linux-images.outputs.armhf_digest }}
      armhf_cross_image_digest: ${{ needs.linux-images.outputs.armhf_cross_digest }}
      build_packages: true
      release_channel: ${{ needs.prepare.outputs.release_channel }}
      rc_number: ${{ needs.prepare.outputs.rc_number }}

  windows:
    needs: prepare
    uses: ./.github/workflows/sign-windows-release.yml
    permissions:
      actions: read
      contents: read
    with:
      version: ${{ needs.prepare.outputs.version }}
      release_channel: ${{ needs.prepare.outputs.release_channel }}
      rc_number: ${{ needs.prepare.outputs.rc_number }}
      windows_signing: ${{ needs.prepare.outputs.windows_signing }}

  assemble:
    needs: [prepare, linux-images, macos, macos-intel, linux, linux-arm, linux-armhf, windows]
    runs-on: ubuntu-latest
    timeout-minutes: 30
    permissions:
      actions: read
      contents: read
      packages: read
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - uses: actions/download-artifact@v8
        with:
          path: artifacts
      - name: Build corresponding source archive
        env:
          VERSION: ${{ needs.prepare.outputs.version }}
        run: |
          set -euo pipefail
          git archive --format=tar --prefix="wsjtx-$VERSION/" "$GITHUB_SHA" |
            gzip -n > "artifacts/wsjtx-$VERSION-src.tar.gz"
          test -s "artifacts/wsjtx-$VERSION-src.tar.gz"
          python3 .github/scripts/release-policy.py validate-archive "$VERSION" \
            "artifacts/wsjtx-$VERSION-src.tar.gz" --commit "$GITHUB_SHA"
      - name: Verify GitHub automatic source archives
        env:
          VERSION: ${{ needs.prepare.outputs.version }}
        run: |
          set -euo pipefail
          curl --fail --location --retry 3 \
            "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/archive/refs/tags/$GITHUB_REF_NAME.tar.gz" \
            --output "$RUNNER_TEMP/github-source.tar.gz"
          curl --fail --location --retry 3 \
            "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/archive/refs/tags/$GITHUB_REF_NAME.zip" \
            --output "$RUNNER_TEMP/github-source.zip"
          python3 .github/scripts/release-policy.py validate-archive "$VERSION" \
            "$RUNNER_TEMP/github-source.tar.gz" --commit "$GITHUB_SHA"
          python3 .github/scripts/release-policy.py validate-archive "$VERSION" \
            "$RUNNER_TEMP/github-source.zip" --commit "$GITHUB_SHA"
      - name: Verify public artifacts and signing reports
        env:
          VERSION: ${{ needs.prepare.outputs.version }}
          MACOS_MODE: ${{ needs.prepare.outputs.macos_sign_mode }}
          WINDOWS_MODE: ${{ needs.prepare.outputs.windows_signing }}
        run: |
          set -euo pipefail
          python3 .github/scripts/release-policy.py verify-assets "$VERSION" artifacts \
            --macos-mode "$MACOS_MODE" --windows-mode "$WINDOWS_MODE"
          python3 .github/scripts/release-policy.py verify-signing-reports "$VERSION" artifacts \
            --commit "$GITHUB_SHA" --tag "$GITHUB_REF_NAME" \
            --macos-mode "$MACOS_MODE" --windows-mode "$WINDOWS_MODE"
      - name: Generate checksums and release manifest
        env:
          VERSION: ${{ needs.prepare.outputs.version }}
          MACOS_MODE: ${{ needs.prepare.outputs.macos_sign_mode }}
          WINDOWS_MODE: ${{ needs.prepare.outputs.windows_signing }}
        run: |
          python3 .github/scripts/release-policy.py write-manifest "$VERSION" artifacts \
            --repository "$GITHUB_REPOSITORY" \
            --commit "$GITHUB_SHA" \
            --run-id "$GITHUB_RUN_ID" \
            --linux-x86-64-digest "${{ needs.linux-images.outputs.x86_64_digest }}" \
            --linux-aarch64-digest "${{ needs.linux-images.outputs.aarch64_digest }}" \
            --linux-armhf-cross-digest "${{ needs.linux-images.outputs.armhf_cross_digest }}" \
            --linux-armhf-digest "${{ needs.linux-images.outputs.armhf_digest }}" \
            --macos-mode "$MACOS_MODE" --windows-mode "$WINDOWS_MODE"
      - name: Assemble publication bundle
        env:
          VERSION: ${{ needs.prepare.outputs.version }}
          MACOS_MODE: ${{ needs.prepare.outputs.macos_sign_mode }}
          WINDOWS_MODE: ${{ needs.prepare.outputs.windows_signing }}
        run: |
          set -euo pipefail
          mkdir -p release-bundle/verification
          while IFS= read -r file; do
            cp "$file" release-bundle/
          done < <(python3 .github/scripts/release-policy.py release-files "$VERSION" artifacts \
            --macos-mode "$MACOS_MODE" --windows-mode "$WINDOWS_MODE")
          cp artifacts/SHA256SUMS artifacts/release-manifest.json release-bundle/
          cp -R artifacts/macos-signing-report-* release-bundle/verification/
          if [ "$WINDOWS_MODE" = signpath ]; then
            cp -R artifacts/wsjtx-*-windows-signing-request \
              artifacts/wsjtx-*-windows-signing-verification \
              release-bundle/verification/
          fi
      - name: Upload publication bundle for approval
        uses: actions/upload-artifact@v7
        with:
          name: release-bundle-${{ needs.prepare.outputs.version }}
          path: release-bundle
          if-no-files-found: error
          retention-days: 30

  publish:
    needs: [prepare, assemble]
    runs-on: ubuntu-latest
    timeout-minutes: 20
    environment: public-release
    permissions:
      actions: read
      contents: write
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - uses: actions/download-artifact@v8
        with:
          name: release-bundle-${{ needs.prepare.outputs.version }}
          path: release-bundle
      - name: Recheck bundle and immutable public tag
        env:
          VERSION: ${{ needs.prepare.outputs.version }}
          MACOS_MODE: ${{ needs.prepare.outputs.macos_sign_mode }}
          WINDOWS_MODE: ${{ needs.prepare.outputs.windows_signing }}
        run: |
          set -euo pipefail
          (cd release-bundle && sha256sum --check SHA256SUMS)
          test "$(jq -r .repository release-bundle/release-manifest.json)" = "$GITHUB_REPOSITORY"
          test "$(jq -r .tag release-bundle/release-manifest.json)" = "$GITHUB_REF_NAME"
          test "$(jq -r .commit release-bundle/release-manifest.json)" = "$GITHUB_SHA"
          test "$(jq -r '.assets | length' release-bundle/release-manifest.json)" -gt 0
          EXPECTED_MACOS_MODE=distribution
          if [ "$MACOS_MODE" = validation ]; then
            EXPECTED_MACOS_MODE=manual
          fi
          test "$(jq -r .macos_signing.mode release-bundle/release-manifest.json)" = "$EXPECTED_MACOS_MODE"
          test "$(jq -r .windows_signing.mode release-bundle/release-manifest.json)" = "$WINDOWS_MODE"
          python3 .github/scripts/release-policy.py classify "$VERSION" >/dev/null
          TAG_SHA=$(git ls-remote origin "refs/tags/$GITHUB_REF_NAME" | awk '{print $1}')
          if [ "$TAG_SHA" != "$GITHUB_SHA" ]; then
            echo "::error::$GITHUB_REF_NAME now resolves to ${TAG_SHA:-missing}, expected $GITHUB_SHA"
            exit 1
          fi
      - name: Publish public GitHub Release
        env:
          GH_TOKEN: ${{ github.token }}
          VERSION: ${{ needs.prepare.outputs.version }}
          CHANNEL: ${{ needs.prepare.outputs.release_channel }}
          MACOS_MODE: ${{ needs.prepare.outputs.macos_sign_mode }}
        run: |
          set -euo pipefail
          mapfile -t FILES < <(find release-bundle -maxdepth 1 -type f -print | sort)
          mapfile -t EXPECTED_NAMES < <(printf '%s\n' "${FILES[@]}" | xargs -n1 basename | sort)
          CREATED=false
          if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
            RELEASE=$(gh release view "$GITHUB_REF_NAME" --json isDraft,isPrerelease,assets)
            if [ "$(jq -r .isDraft <<<"$RELEASE")" != false ]; then
              echo "::error::Existing release $GITHUB_REF_NAME is unexpectedly a draft."
              exit 1
            fi
            EXPECTED_PRERELEASE=false
            if [ "$CHANNEL" = RC ]; then
              EXPECTED_PRERELEASE=true
            fi
            if [ "$(jq -r .isPrerelease <<<"$RELEASE")" != "$EXPECTED_PRERELEASE" ]; then
              echo "::error::Existing release $GITHUB_REF_NAME has the wrong prerelease state."
              exit 1
            fi
            mapfile -t ACTUAL_NAMES < <(jq -r '.assets[].name' <<<"$RELEASE" | sort)
            EXTRA=$(comm -13 \
              <(printf '%s\n' "${EXPECTED_NAMES[@]}") \
              <(printf '%s\n' "${ACTUAL_NAMES[@]}") || true)
            if [ -n "$EXTRA" ]; then
              echo "::error::Existing release contains assets outside the publication bundle:"
              printf '%s\n' "$EXTRA"
              exit 1
            fi
            mkdir -p "$RUNNER_TEMP/existing-assets"
            MISSING=()
            for file in "${FILES[@]}"; do
              name=$(basename "$file")
              if [ "$MACOS_MODE" = validation ] && [[ "$name" == wsjtx-*-macOS.pkg ]]; then
                if printf '%s\n' "${ACTUAL_NAMES[@]}" | grep -Fxq "$name"; then
                  echo "Preserving manually replaceable macOS asset: $name"
                else
                  MISSING+=("$file")
                fi
                continue
              fi
              if gh release download "$GITHUB_REF_NAME" --pattern "$name" --dir "$RUNNER_TEMP/existing-assets"; then
                cmp "$file" "$RUNNER_TEMP/existing-assets/$name" || {
                  echo "::error::Published asset $name differs; automatic replacement is forbidden."
                  exit 1
                }
              else
                MISSING+=("$file")
              fi
            done
            if [ "${#MISSING[@]}" -gt 0 ]; then
              gh release upload "$GITHUB_REF_NAME" "${MISSING[@]}"
            fi
            mapfile -t FINAL_NAMES < <(gh release view "$GITHUB_REF_NAME" --json assets --jq '.assets[].name' | sort)
            if ! diff -u \
              <(printf '%s\n' "${EXPECTED_NAMES[@]}") \
              <(printf '%s\n' "${FINAL_NAMES[@]}"); then
              echo "::error::Published asset set does not match the publication bundle."
              exit 1
            fi
            echo "Existing assets satisfy the publication bundle policy."
          else
            FLAGS=()
            if [ "$CHANNEL" = RC ]; then
              FLAGS+=(--prerelease)
            fi
            gh release create "$GITHUB_REF_NAME" \
              --verify-tag \
              --title "WSJT-X $VERSION" \
              --generate-notes \
              "${FLAGS[@]}" \
              "${FILES[@]}"
            CREATED=true
          fi
          if [ "$CREATED" = true ]; then
            QUICK_DOWNLOADS=$(python3 .github/scripts/generate-quick-downloads.py \
              "$GITHUB_REPOSITORY" "$GITHUB_REF_NAME" "${FILES[@]}" || true)
            if [ -n "$QUICK_DOWNLOADS" ]; then
              GENERATED_NOTES=$(gh release view "$GITHUB_REF_NAME" --json body --jq .body)
              printf '%s\n\n---\n\n%s\n' "$QUICK_DOWNLOADS" "$GENERATED_NOTES" > "$RUNNER_TEMP/release-notes.md"
              gh release edit "$GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/release-notes.md"
            else
              echo "::warning::Quick Downloads picker was empty; generated notes were left unchanged."
            fi
          fi