filelift 0.2.4

A small CLI for lifting local files to S3-compatible object storage.
name: Release

on:
  push:
    tags:
      - "v*"
  release:
    types:
      - published
  workflow_dispatch:
    inputs:
      tag:
        description: Release tag to publish, for example v0.2.4.
        required: true
        type: string

permissions:
  contents: write

concurrency:
  group: release-${{ github.event.release.tag_name || inputs.tag || github.ref_name }}
  cancel-in-progress: false

jobs:
  build:
    name: Build ${{ matrix.asset_name }}
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            asset_name: filelift-x86_64-unknown-linux-gnu.tar.gz
            binary_name: filelift
            archive_kind: tar
          - os: macos-13
            target: x86_64-apple-darwin
            asset_name: filelift-x86_64-apple-darwin.tar.gz
            binary_name: filelift
            archive_kind: tar
          - os: macos-14
            target: aarch64-apple-darwin
            asset_name: filelift-aarch64-apple-darwin.tar.gz
            binary_name: filelift
            archive_kind: tar
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            asset_name: filelift-x86_64-pc-windows-msvc.zip
            binary_name: filelift.exe
            archive_kind: zip

    steps:
      - name: Checkout release ref
        uses: actions/checkout@v6
        with:
          ref: ${{ github.event.release.tag_name || inputs.tag || github.ref }}

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Cache cargo artifacts
        uses: Swatinem/rust-cache@v2

      - name: Build release binary
        run: cargo build --release --locked --target ${{ matrix.target }}

      - name: Stage release files
        shell: pwsh
        run: |
          New-Item -ItemType Directory -Path dist/filelift | Out-Null
          Copy-Item "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" "dist/filelift/${{ matrix.binary_name }}"
          Copy-Item README.md dist/filelift/README.md
          Copy-Item LICENSE dist/filelift/LICENSE

      - name: Create tar archive
        if: matrix.archive_kind == 'tar'
        shell: bash
        run: tar -czf "${{ matrix.asset_name }}" -C dist/filelift .

      - name: Create zip archive
        if: matrix.archive_kind == 'zip'
        shell: pwsh
        run: Compress-Archive -Path dist/filelift/* -DestinationPath "${{ matrix.asset_name }}" -Force

      - name: Upload release asset
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ github.event.release.tag_name || inputs.tag || github.ref_name }}
          files: ${{ matrix.asset_name }}

  cargo-publish:
    name: Publish crate
    runs-on: ubuntu-latest
    needs: build

    steps:
      - name: Checkout release ref
        uses: actions/checkout@v6
        with:
          ref: ${{ github.event.release.tag_name || inputs.tag || github.ref }}

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Verify release tag matches Cargo version
        shell: bash
        run: |
          set -euo pipefail

          version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')"
          tag="${GITHUB_REF_NAME}"
          if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
            tag="${{ github.event.release.tag_name }}"
          elif [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
            tag="${{ inputs.tag }}"
          fi

          expected="v${version}"
          if [[ "${tag}" != "${expected}" ]]; then
            echo "Release tag ${tag} does not match Cargo.toml version ${version}; expected ${expected}." >&2
            exit 1
          fi

      - name: Publish to crates.io
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        shell: bash
        run: |
          set -euo pipefail

          if [[ -z "${CARGO_REGISTRY_TOKEN:-}" ]]; then
            echo "Missing CARGO_REGISTRY_TOKEN repository secret." >&2
            exit 1
          fi

          cargo publish --locked