|
| 1 | +# Release workflow for cargo-rail |
| 2 | +# |
| 3 | +# Triggered by pushing a version tag (v1.0.0, v1.2.3, etc.) |
| 4 | +# |
| 5 | +# This workflow: |
| 6 | +# 1. Creates a GitHub Release with CHANGELOG content |
| 7 | +# 2. Builds pre-built binaries for 9 targets |
| 8 | +# 3. Uploads binaries to the release |
| 9 | +# |
| 10 | +# The actual version bump, changelog generation, and tagging is done locally |
| 11 | +# using `cargo rail release run cargo-rail --bump <version>`. |
| 12 | +# |
| 13 | +# Workflow: |
| 14 | +# LOCAL: cargo rail release run cargo-rail --bump 1.0.0 |
| 15 | +# git push origin main --follow-tags |
| 16 | +# CI: This workflow triggers, builds binaries, creates release |
| 17 | + |
| 18 | +name: Release |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + |
| 23 | +on: |
| 24 | + push: |
| 25 | + tags: |
| 26 | + - v[0-9]+.* |
| 27 | + |
| 28 | +env: |
| 29 | + CARGO_INCREMENTAL: 0 |
| 30 | + CARGO_TERM_COLOR: always |
| 31 | + RUST_BACKTRACE: 1 |
| 32 | + |
| 33 | +jobs: |
| 34 | + # ========================================================================== |
| 35 | + # Job 1: Create GitHub Release |
| 36 | + # ========================================================================== |
| 37 | + create-release: |
| 38 | + name: Create Release |
| 39 | + runs-on: ubuntu-latest |
| 40 | + permissions: |
| 41 | + contents: write |
| 42 | + outputs: |
| 43 | + version: ${{ steps.version.outputs.version }} |
| 44 | + steps: |
| 45 | + - name: Checkout |
| 46 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 47 | + with: |
| 48 | + persist-credentials: false |
| 49 | + |
| 50 | + - name: Extract version from tag |
| 51 | + id: version |
| 52 | + run: echo "version=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT" |
| 53 | + |
| 54 | + - name: Create GitHub Release |
| 55 | + uses: taiki-e/create-gh-release-action@b7abb0cf5e72cb5500307b577f9ca3fd4c5be9d2 # v1.8.4 |
| 56 | + with: |
| 57 | + changelog: CHANGELOG.md |
| 58 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + |
| 60 | + # ========================================================================== |
| 61 | + # Job 2: Build and upload pre-built binaries |
| 62 | + # ========================================================================== |
| 63 | + upload-assets: |
| 64 | + name: Build (${{ matrix.target }}) |
| 65 | + needs: create-release |
| 66 | + strategy: |
| 67 | + fail-fast: false |
| 68 | + matrix: |
| 69 | + include: |
| 70 | + # ---------------------------------------------------------------- |
| 71 | + # Linux |
| 72 | + # ---------------------------------------------------------------- |
| 73 | + # x86_64 glibc - most common Linux target |
| 74 | + - target: x86_64-unknown-linux-gnu |
| 75 | + os: ubuntu-22.04 |
| 76 | + |
| 77 | + # x86_64 musl - static binary, maximum portability |
| 78 | + - target: x86_64-unknown-linux-musl |
| 79 | + os: ubuntu-latest |
| 80 | + |
| 81 | + # ARM64 glibc - AWS Graviton, modern ARM servers |
| 82 | + - target: aarch64-unknown-linux-gnu |
| 83 | + os: ubuntu-22.04 |
| 84 | + |
| 85 | + # ARM64 musl - static binary for ARM |
| 86 | + - target: aarch64-unknown-linux-musl |
| 87 | + os: ubuntu-latest |
| 88 | + |
| 89 | + # ---------------------------------------------------------------- |
| 90 | + # macOS |
| 91 | + # ---------------------------------------------------------------- |
| 92 | + # Intel Macs |
| 93 | + - target: x86_64-apple-darwin |
| 94 | + os: macos-14 |
| 95 | + |
| 96 | + # Apple Silicon (M1/M2/M3) |
| 97 | + - target: aarch64-apple-darwin |
| 98 | + os: macos-14 |
| 99 | + |
| 100 | + # Universal binary (both architectures) |
| 101 | + - target: universal-apple-darwin |
| 102 | + os: macos-14 |
| 103 | + |
| 104 | + # ---------------------------------------------------------------- |
| 105 | + # Windows |
| 106 | + # ---------------------------------------------------------------- |
| 107 | + # x86_64 Windows |
| 108 | + - target: x86_64-pc-windows-msvc |
| 109 | + os: windows-2022 |
| 110 | + |
| 111 | + # ARM64 Windows (Surface Pro X, etc.) |
| 112 | + - target: aarch64-pc-windows-msvc |
| 113 | + os: windows-2022 |
| 114 | + |
| 115 | + runs-on: ${{ matrix.os }} |
| 116 | + timeout-minutes: 60 |
| 117 | + permissions: |
| 118 | + contents: write |
| 119 | + steps: |
| 120 | + - name: Checkout |
| 121 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 122 | + with: |
| 123 | + persist-credentials: false |
| 124 | + |
| 125 | + - name: Install Rust |
| 126 | + uses: dtolnay/rust-toolchain@0b1efabc08b657293548b77fb76cc02d26091c7e # master |
| 127 | + with: |
| 128 | + toolchain: stable |
| 129 | + |
| 130 | + - name: Setup cross-compilation |
| 131 | + uses: taiki-e/setup-cross-toolchain-action@bdeb9ca6f0f909ea36bb94e1e3ec916b2ceb35fc # v1.26.0 |
| 132 | + with: |
| 133 | + target: ${{ matrix.target }} |
| 134 | + |
| 135 | + # Static linking for musl targets (portable binaries) |
| 136 | + - name: Configure static linking (musl) |
| 137 | + if: contains(matrix.target, '-linux-musl') |
| 138 | + run: echo "RUSTFLAGS=${RUSTFLAGS} -C target-feature=+crt-static -C link-self-contained=yes" >> "$GITHUB_ENV" |
| 139 | + shell: bash |
| 140 | + |
| 141 | + # Static linking for Windows (no MSVC runtime dependency) |
| 142 | + - name: Configure static linking (Windows) |
| 143 | + if: contains(matrix.target, '-windows-msvc') |
| 144 | + run: echo "RUSTFLAGS=${RUSTFLAGS} -C target-feature=+crt-static" >> "$GITHUB_ENV" |
| 145 | + shell: bash |
| 146 | + |
| 147 | + # macOS deployment targets for compatibility |
| 148 | + - name: Set macOS deployment target (Intel) |
| 149 | + if: matrix.target == 'x86_64-apple-darwin' |
| 150 | + run: echo "MACOSX_DEPLOYMENT_TARGET=10.12" >> "$GITHUB_ENV" |
| 151 | + |
| 152 | + - name: Set macOS deployment target (ARM/Universal) |
| 153 | + if: matrix.target == 'aarch64-apple-darwin' || matrix.target == 'universal-apple-darwin' |
| 154 | + run: echo "MACOSX_DEPLOYMENT_TARGET=11.0" >> "$GITHUB_ENV" |
| 155 | + |
| 156 | + - name: Build and upload binary |
| 157 | + uses: taiki-e/upload-rust-binary-action@e7953b6078194a4ae5f5619632e3715db6275561 # v1.24.0 |
| 158 | + with: |
| 159 | + bin: cargo-rail |
| 160 | + target: ${{ matrix.target }} |
| 161 | + # tar for all platforms, zip additionally for Windows |
| 162 | + tar: all |
| 163 | + zip: windows |
| 164 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 165 | + |
| 166 | + # ========================================================================== |
| 167 | + # Job 3: Publish to crates.io (after binaries are built) |
| 168 | + # ========================================================================== |
| 169 | + publish: |
| 170 | + name: Publish to crates.io |
| 171 | + needs: [create-release, upload-assets] |
| 172 | + runs-on: ubuntu-latest |
| 173 | + steps: |
| 174 | + - name: Checkout |
| 175 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 176 | + with: |
| 177 | + persist-credentials: false |
| 178 | + |
| 179 | + - name: Install Rust |
| 180 | + uses: dtolnay/rust-toolchain@0b1efabc08b657293548b77fb76cc02d26091c7e # master |
| 181 | + with: |
| 182 | + toolchain: stable |
| 183 | + |
| 184 | + - name: Publish to crates.io |
| 185 | + run: cargo publish --token "${{ secrets.CARGO_REGISTRY_TOKEN }}" |
0 commit comments