aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/release.yml
blob: 3f44f408b935102f6f8586f2a25ae949ebba90f7 (plain) (blame)
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
name: release

on:
  workflow_dispatch:
    inputs:
      version:
        description: Version impact (the first release is 0.1.0 or X.0.0)
        required: true
        default: patch
        type: choice
        options: [minor, patch]
      dry_run:
        description: Build and test artifacts without pushing or publishing
        required: true
        default: true
        type: boolean

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

permissions:
  contents: read

defaults:
  run:
    shell: bash

env:
  RELEASE_RUST: stable

jobs:
  prepare:
    runs-on: ubuntu-24.04
    timeout-minutes: 15
    outputs:
      version: ${{ steps.version.outputs.version }}
      tag: ${{ steps.version.outputs.tag }}
      commit: ${{ steps.version.outputs.commit }}
      base: ${{ steps.version.outputs.base }}
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
        with:
          fetch-depth: 0
          persist-credentials: false
      - name: Require a release branch
        env:
          REF_TYPE: ${{ github.ref_type }}
          RELEASE_BRANCH: ${{ github.ref_name }}
        run: |
          test "$REF_TYPE" = branch
          python3 -B -c 'import sys; sys.path.insert(0, "scripts"); from release import branch_major; branch_major(sys.argv[1])' "$RELEASE_BRANCH"
      - name: Install Rust
        run: rustup toolchain install "$RELEASE_RUST" --profile minimal
      - name: Select release toolchain
        run: rustup override set "$RELEASE_RUST"
      - name: Test release automation
        run: python3 -B -m unittest discover -s scripts -p 'test_*.py'
      - name: Prepare version and source bundle
        id: version
        env:
          RELEASE_BRANCH: ${{ github.ref_name }}
          IMPACT: ${{ inputs.version }}
        run: |
          python3 -B scripts/release.py prepare --branch "$RELEASE_BRANCH" --impact "$IMPACT" \
            --bundle target/release-source.bundle --output "$GITHUB_OUTPUT"
      - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
        with:
          name: release-source
          path: target/release-source.bundle
          if-no-files-found: error
          retention-days: 7
          overwrite: true

  build:
    needs: prepare
    runs-on: ${{ matrix.os }}
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-24.04
            target: x86_64-unknown-linux-musl
            binary: aif
          - os: macos-15
            target: aarch64-apple-darwin
            binary: aif
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            binary: aif.exe
    env:
      TARGET: ${{ matrix.target }}
      BINARY: ${{ matrix.binary }}
      VERSION: ${{ needs.prepare.outputs.version }}
      RELEASE_COMMIT: ${{ needs.prepare.outputs.commit }}
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
        with:
          persist-credentials: false
      - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
        with:
          name: release-source
          path: target/release-input
      - name: Check out versioned source
        run: |
          git fetch target/release-input/release-source.bundle HEAD
          test "$(git rev-parse FETCH_HEAD)" = "$RELEASE_COMMIT"
          git checkout --detach "$RELEASE_COMMIT"
      - name: Install Rust
        run: rustup toolchain install "$RELEASE_RUST" --profile minimal --target "$TARGET"
      - name: Select release toolchain
        run: rustup override set "$RELEASE_RUST"
      - name: Set macOS deployment target
        if: runner.os == 'macOS'
        run: echo 'MACOSX_DEPLOYMENT_TARGET=11.0' >> "$GITHUB_ENV"
      - name: Test release target
        run: |
          cargo test --locked --target "$TARGET"
          cargo test --locked --target "$TARGET" --features serde_json/arbitrary_precision
          cargo test --release --locked --target "$TARGET"
      - name: Build and check CLI
        run: |
          cargo build --release --locked --target "$TARGET"
          binary="target/$TARGET/release/$BINARY"
          test "$("$binary" --version)" = "aif $VERSION"
          printf '{"n":1}\n{"n":2}\n' | "$binary" 'n > 1' > target/smoke.jsonl
          printf '{"n":2}\n' > target/expected.jsonl
          cmp target/expected.jsonl target/smoke.jsonl
      - name: Verify static Linux executable
        if: runner.os == 'Linux'
        run: |
          readelf -l "target/$TARGET/release/aif" > target/elf-headers
          if grep -q INTERP target/elf-headers; then
            echo 'The Linux executable requires a dynamic loader.' >&2
            exit 1
          fi
      - name: Archive CLI
        if: runner.os != 'Windows'
        run: |
          mkdir -p target/release-dist
          COPYFILE_DISABLE=1 tar -czf "target/release-dist/aif-v$VERSION-$TARGET.tar.gz" \
            -C "target/$TARGET/release" aif -C "$GITHUB_WORKSPACE" LICENSE README.md
      - name: Archive Windows CLI
        if: runner.os == 'Windows'
        run: |
          mkdir -p target/release-dist
          python -m zipfile -c "target/release-dist/aif-v$VERSION-$TARGET.zip" \
            "target/$TARGET/release/$BINARY" LICENSE README.md
      - name: Verify library package
        if: runner.os == 'Linux'
        run: |
          cargo package --locked
          cargo test --locked --manifest-path "target/package/aif-$VERSION/Cargo.toml"
          cp "target/package/aif-$VERSION.crate" target/release-dist/
      - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
        with:
          name: release-assets-${{ matrix.target }}
          path: target/release-dist/*
          if-no-files-found: error
          retention-days: 7
          compression-level: 0
          overwrite: true

  publish:
    needs: [prepare, build]
    runs-on: ubuntu-24.04
    timeout-minutes: 15
    permissions:
      contents: write
    env:
      RELEASE_BRANCH: ${{ github.ref_name }}
      VERSION: ${{ needs.prepare.outputs.version }}
      TAG: ${{ needs.prepare.outputs.tag }}
      BASE: ${{ needs.prepare.outputs.base }}
      RELEASE_COMMIT: ${{ needs.prepare.outputs.commit }}
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
        with:
          fetch-depth: 0
      - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
        with:
          name: release-source
          path: target/release-input
      - name: Check out tested source
        run: |
          git fetch target/release-input/release-source.bundle HEAD
          test "$(git rev-parse FETCH_HEAD)" = "$RELEASE_COMMIT"
          git checkout --detach "$RELEASE_COMMIT"
      - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
        with:
          pattern: release-assets-*
          merge-multiple: true
          path: target/release-dist
      - name: Verify asset set and generate checksums
        run: |
          test -f "target/release-dist/aif-v$VERSION-x86_64-unknown-linux-musl.tar.gz"
          test -f "target/release-dist/aif-v$VERSION-aarch64-apple-darwin.tar.gz"
          test -f "target/release-dist/aif-v$VERSION-x86_64-pc-windows-msvc.zip"
          test -f "target/release-dist/aif-$VERSION.crate"
          test "$(find target/release-dist -maxdepth 1 -type f | wc -l)" -eq 4
          cd target/release-dist
          sha256sum *.tar.gz *.zip *.crate > SHA256SUMS
          sha256sum --check SHA256SUMS
      - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
        with:
          name: release-downloads
          path: target/release-dist/*
          if-no-files-found: error
          retention-days: 7
          compression-level: 0
          overwrite: true
      - name: Push tested release references
        if: ${{ !inputs.dry_run }}
        run: |
          python3 -B scripts/release.py push --branch "$RELEASE_BRANCH" \
            --version "$VERSION" --base "$BASE" --commit "$RELEASE_COMMIT"
      - name: Publish GitHub release
        if: ${{ !inputs.dry_run }}
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          if draft=$(gh release view "$TAG" --json isDraft --jq '.isDraft'); then
            if test "$draft" != true; then
              echo 'The release is already public; refusing to replace its assets.' >&2
              exit 1
            fi
          else
            gh release create "$TAG" --verify-tag --draft --generate-notes --title "$TAG" --target "$RELEASE_COMMIT"
          fi
          gh release upload "$TAG" target/release-dist/* --clobber
          # REST release-by-tag lookups exclude draft releases.
          release_id=$(gh release view "$TAG" --json databaseId --jq '.databaseId')
          gh api --method PATCH "repos/$GITHUB_REPOSITORY/releases/$release_id" \
            -F draft=false -f make_latest=legacy > /dev/null
      - name: Record result
        env:
          DRY_RUN: ${{ inputs.dry_run }}
        run: |
          printf 'Version: `%s`\n\nCommit: `%s`\n\nDry run: `%s`\n\nDownload the `release-downloads` artifact for the CLI archives, Cargo source package, and SHA256SUMS.\n' \
            "$TAG" "$RELEASE_COMMIT" "$DRY_RUN" >> "$GITHUB_STEP_SUMMARY"