|
1 | 1 | name: Release |
2 | 2 |
|
3 | 3 | on: |
4 | | - workflow_dispatch: |
5 | | - inputs: |
6 | | - tag: |
7 | | - description: Release tag, for example v0.1.0 |
8 | | - required: true |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
9 | 7 |
|
10 | | -permissions: |
11 | | - contents: write |
| 8 | +permissions: {} |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: release-${{ github.ref }} |
| 12 | + cancel-in-progress: false |
12 | 13 |
|
13 | 14 | jobs: |
14 | | - build: |
15 | | - name: Build release artifacts |
16 | | - runs-on: ubuntu-latest |
| 15 | + create-release: |
| 16 | + name: Create draft release |
| 17 | + runs-on: ubuntu-24.04 |
| 18 | + permissions: |
| 19 | + contents: write |
17 | 20 | steps: |
18 | 21 | - name: Checkout |
19 | | - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 |
| 22 | + uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 |
20 | 23 | with: |
21 | 24 | persist-credentials: false |
22 | | - - name: Install Rust |
23 | | - run: rustup toolchain install 1.85.0 --profile minimal |
24 | | - - name: Test |
25 | | - run: cargo +1.85.0 test --workspace --all-targets --all-features |
26 | | - - name: Build |
27 | | - run: cargo +1.85.0 build --release --locked |
28 | | - - name: Checksums |
29 | | - run: shasum -a 256 target/release/model-routing > SHA256SUMS |
30 | | - - name: Upload draft release |
| 25 | + - name: Verify release contract |
| 26 | + env: |
| 27 | + TAG: ${{ github.ref_name }} |
| 28 | + run: | |
| 29 | + crate_version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)" |
| 30 | + package_version="$(jq -r .version package.json)" |
| 31 | + test "v$crate_version" = "$TAG" |
| 32 | + test "$package_version" = "$crate_version" |
| 33 | + grep -q "^## \[$crate_version\]" CHANGELOG.md |
| 34 | + - name: Create draft release |
31 | 35 | env: |
32 | 36 | GH_TOKEN: ${{ github.token }} |
33 | | - RELEASE_TAG: ${{ inputs.tag }} |
| 37 | + TAG: ${{ github.ref_name }} |
34 | 38 | run: | |
35 | | - gh release create "$RELEASE_TAG" \ |
| 39 | + prerelease_flag="" |
| 40 | + case "$TAG" in *-*) prerelease_flag="--prerelease" ;; esac |
| 41 | + gh release create "$TAG" \ |
| 42 | + --repo "$GITHUB_REPOSITORY" \ |
36 | 43 | --draft \ |
37 | | - --title "$RELEASE_TAG" \ |
38 | | - target/release/model-routing \ |
39 | | - SHA256SUMS |
| 44 | + $prerelease_flag \ |
| 45 | + --title "Switchloom $TAG" \ |
| 46 | + --generate-notes |
| 47 | +
|
| 48 | + build: |
| 49 | + name: Build ${{ matrix.target }} |
| 50 | + needs: create-release |
| 51 | + strategy: |
| 52 | + fail-fast: false |
| 53 | + matrix: |
| 54 | + include: |
| 55 | + - target: darwin-arm64 |
| 56 | + rust_target: aarch64-apple-darwin |
| 57 | + runner: macos-14 |
| 58 | + - target: darwin-x86_64 |
| 59 | + rust_target: x86_64-apple-darwin |
| 60 | + runner: macos-14 |
| 61 | + - target: linux-x86_64 |
| 62 | + rust_target: x86_64-unknown-linux-gnu |
| 63 | + runner: ubuntu-24.04 |
| 64 | + - target: linux-arm64 |
| 65 | + rust_target: aarch64-unknown-linux-gnu |
| 66 | + runner: ubuntu-24.04-arm |
| 67 | + runs-on: ${{ matrix.runner }} |
| 68 | + permissions: |
| 69 | + contents: write |
| 70 | + steps: |
| 71 | + - name: Checkout |
| 72 | + uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 |
| 73 | + with: |
| 74 | + persist-credentials: false |
| 75 | + - name: Install Rust target |
| 76 | + run: rustup target add ${{ matrix.rust_target }} |
| 77 | + - name: Build release archive |
| 78 | + env: |
| 79 | + SWITCHLOOM_TARGET: ${{ matrix.target }} |
| 80 | + SWITCHLOOM_CARGO_TARGET: ${{ matrix.rust_target }} |
| 81 | + run: scripts/build-release.sh |
| 82 | + - name: Smoke-test native binary |
| 83 | + if: matrix.target != 'darwin-x86_64' |
| 84 | + run: ./target/${{ matrix.rust_target }}/release/model-routing --version |
| 85 | + - name: Upload release archive |
| 86 | + env: |
| 87 | + GH_TOKEN: ${{ github.token }} |
| 88 | + TAG: ${{ github.ref_name }} |
| 89 | + run: | |
| 90 | + gh release upload "$TAG" \ |
| 91 | + --repo "$GITHUB_REPOSITORY" \ |
| 92 | + --clobber \ |
| 93 | + "dist/switchloom-${{ matrix.target }}.tar.gz" |
| 94 | +
|
| 95 | + finalize: |
| 96 | + name: Publish checksums and release |
| 97 | + needs: build |
| 98 | + runs-on: ubuntu-24.04 |
| 99 | + permissions: |
| 100 | + contents: write |
| 101 | + steps: |
| 102 | + - name: Download release archives |
| 103 | + env: |
| 104 | + GH_TOKEN: ${{ github.token }} |
| 105 | + TAG: ${{ github.ref_name }} |
| 106 | + run: | |
| 107 | + mkdir assets |
| 108 | + gh release download "$TAG" \ |
| 109 | + --repo "$GITHUB_REPOSITORY" \ |
| 110 | + --pattern 'switchloom-*.tar.gz' \ |
| 111 | + --dir assets |
| 112 | + - name: Generate aggregate checksums |
| 113 | + run: | |
| 114 | + cd assets |
| 115 | + sha256sum switchloom-*.tar.gz > SHA256SUMS |
| 116 | + cat SHA256SUMS |
| 117 | + - name: Publish release |
| 118 | + env: |
| 119 | + GH_TOKEN: ${{ github.token }} |
| 120 | + TAG: ${{ github.ref_name }} |
| 121 | + run: | |
| 122 | + gh release upload "$TAG" \ |
| 123 | + --repo "$GITHUB_REPOSITORY" \ |
| 124 | + --clobber \ |
| 125 | + assets/SHA256SUMS |
| 126 | + gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --draft=false |
0 commit comments