|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: ["v*.*.*"] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: ${{ github.workflow }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +env: |
| 15 | + CARGO_TERM_COLOR: always |
| 16 | + |
| 17 | +jobs: |
| 18 | + tag-check: |
| 19 | + name: Tag Check |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 23 | + with: |
| 24 | + persist-credentials: false |
| 25 | + |
| 26 | + - name: Validate tag matches package version |
| 27 | + env: |
| 28 | + TAG_NAME: ${{ github.ref_name }} |
| 29 | + run: | |
| 30 | + python3 - <<'PY' |
| 31 | + import os |
| 32 | + import pathlib |
| 33 | + import tomllib |
| 34 | +
|
| 35 | + tag_name = os.environ["TAG_NAME"] |
| 36 | + if not tag_name.startswith("v"): |
| 37 | + raise SystemExit(f"expected v-prefixed tag, got {tag_name}") |
| 38 | + tag_version = tag_name[1:] |
| 39 | + cargo = tomllib.loads(pathlib.Path("Cargo.toml").read_text()) |
| 40 | + package_version = cargo["package"]["version"] |
| 41 | + if tag_version != package_version: |
| 42 | + raise SystemExit( |
| 43 | + f"tag version {tag_version} does not match package version {package_version}" |
| 44 | + ) |
| 45 | + PY |
| 46 | +
|
| 47 | + build: |
| 48 | + needs: tag-check |
| 49 | + name: Build (${{ matrix.target }}) |
| 50 | + runs-on: ${{ matrix.runner }} |
| 51 | + permissions: |
| 52 | + contents: read |
| 53 | + strategy: |
| 54 | + fail-fast: false |
| 55 | + matrix: |
| 56 | + include: |
| 57 | + - target: aarch64-apple-darwin |
| 58 | + runner: macos-14 |
| 59 | + - target: x86_64-apple-darwin |
| 60 | + runner: macos-latest |
| 61 | + - target: aarch64-unknown-linux-gnu |
| 62 | + runner: ubuntu-24.04-arm |
| 63 | + - target: x86_64-unknown-linux-gnu |
| 64 | + runner: ubuntu-latest |
| 65 | + - target: x86_64-pc-windows-msvc |
| 66 | + runner: windows-latest |
| 67 | + |
| 68 | + steps: |
| 69 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 70 | + with: |
| 71 | + persist-credentials: false |
| 72 | + |
| 73 | + - uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 |
| 74 | + with: |
| 75 | + toolchain: stable |
| 76 | + targets: ${{ matrix.target }} |
| 77 | + |
| 78 | + - uses: Swatinem/rust-cache@bc2d2e71bd35c5549942babaa51a89c586b981d1 # v2.8.1 |
| 79 | + with: |
| 80 | + key: release-${{ matrix.target }} |
| 81 | + |
| 82 | + - name: Build |
| 83 | + run: cargo build --release --locked --target ${{ matrix.target }} |
| 84 | + |
| 85 | + - name: Prepare asset (Unix) |
| 86 | + if: runner.os != 'Windows' |
| 87 | + shell: bash |
| 88 | + run: | |
| 89 | + ASSET="dispatch-courier-seren-cloud-${{ matrix.target }}" |
| 90 | + cp "target/${{ matrix.target }}/release/dispatch-courier-seren-cloud" "$ASSET" |
| 91 | + chmod +x "$ASSET" |
| 92 | + echo "ASSET=$ASSET" >> "$GITHUB_ENV" |
| 93 | +
|
| 94 | + - name: Prepare asset (Windows) |
| 95 | + if: runner.os == 'Windows' |
| 96 | + shell: pwsh |
| 97 | + run: | |
| 98 | + $ASSET = "dispatch-courier-seren-cloud-${{ matrix.target }}.exe" |
| 99 | + Copy-Item "target/${{ matrix.target }}/release/dispatch-courier-seren-cloud.exe" $ASSET |
| 100 | + echo "ASSET=$ASSET" | Out-File -FilePath $env:GITHUB_ENV -Append |
| 101 | +
|
| 102 | + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 103 | + with: |
| 104 | + name: dist-${{ matrix.target }} |
| 105 | + path: ${{ env.ASSET }} |
| 106 | + |
| 107 | + release: |
| 108 | + name: Release |
| 109 | + needs: build |
| 110 | + runs-on: ubuntu-latest |
| 111 | + permissions: |
| 112 | + contents: write |
| 113 | + steps: |
| 114 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 115 | + with: |
| 116 | + persist-credentials: false |
| 117 | + |
| 118 | + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 |
| 119 | + with: |
| 120 | + path: dist |
| 121 | + pattern: dist-* |
| 122 | + merge-multiple: true |
| 123 | + |
| 124 | + - name: Generate checksums |
| 125 | + working-directory: dist |
| 126 | + run: sha256sum * > SHA256SUMS.txt |
| 127 | + |
| 128 | + - name: Create release |
| 129 | + env: |
| 130 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 131 | + TAG_NAME: ${{ github.ref_name }} |
| 132 | + run: | |
| 133 | + gh release create "$TAG_NAME" \ |
| 134 | + --title "$TAG_NAME" \ |
| 135 | + --generate-notes \ |
| 136 | + dist/* |
0 commit comments