── .github/workflows/build-binaries.yml ──
# Builds cross-platform binaries and uploads to GitHub Releases.
# Binaries are discoverable by cargo-binstall (https://github.com/cargo-bins/cargo-binstall).
# Triggered automatically when release-plz publishes a release.
# Requires the trusted-publishing template. Add a RELEASE_PLZ_TOKEN PAT
# (contents:write + pull-requests:write) as a repo secret so release events
# trigger this workflow.
# https://github.com/settings/personal-access-tokens/new
name: Build Binaries

on:
  release:
    types: [published]

permissions:
  contents: write

jobs:
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    if: ${{ github.repository_owner == 'test-owner' }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            archive: tar.gz
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-24.04-arm
            archive: tar.gz
          - target: x86_64-apple-darwin
            os: macos-latest
            archive: tar.gz
          - target: aarch64-apple-darwin
            os: macos-latest
            archive: tar.gz
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            archive: zip

    steps:
      - uses: actions/checkout@[..] # v[..]
        with:
          persist-credentials: false
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - run: cargo build --release --target ${{ matrix.target }} -p test-project

      - name: Determine version
        id: version
        shell: bash
        run: |
          TAG="${{ github.event.release.tag_name }}"
          # Strip package name prefix (e.g. "my-crate-v0.1.0" -> "v0.1.0")
          VERSION="${TAG##*-v}"
          echo "version=v${VERSION}" >> "$GITHUB_OUTPUT"

      - name: Package (Unix)
        if: ${{ matrix.archive == 'tar.gz' }}
        shell: bash
        run: |
          cd target/${{ matrix.target }}/release
          tar -czvf ../../../test-project-${{ matrix.target }}-${{ steps.version.outputs.version }}.tar.gz test-project

      - name: Package (Windows)
        if: ${{ matrix.archive == 'zip' }}
        shell: pwsh
        run: |
          cd target/${{ matrix.target }}/release
          Compress-Archive -Path test-project.exe -DestinationPath ../../../test-project-${{ matrix.target }}-${{ steps.version.outputs.version }}.zip

      - name: Upload release asset
        uses: softprops/action-gh-release@[..] # v[..]
        with:
          files: test-project-${{ matrix.target }}-${{ steps.version.outputs.version }}.${{ matrix.archive }}
── Cargo.toml ──
[package]
name = "test-project"
version = "0.1.0"
edition = "2024"

[[bin]]
name = "test-project"
path = "src/main.rs"

[package.metadata.binstall]
pkg-url = "{ repo }/releases/download/{ name }-v{ version }/{ name }-{ target }-v{ version }{ archive-suffix }"
── cargo-bin-section.toml ──

[[bin]]
name = "test-project"
path = "src/main.rs"

[package.metadata.binstall]
pkg-url = "{ repo }/releases/download/{ name }-v{ version }/{ name }-{ target }-v{ version }{ archive-suffix }"
── src/main.rs ──
fn main() {
    println!("Hello from {}!", env!("CARGO_PKG_NAME"));
}
