cargo-upkeep 0.1.7

Unified Rust project maintenance CLI (cargo subcommand)
name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write

jobs:
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            archive_ext: tar.gz
            bin_ext: ""
            use_cross: false
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            archive_ext: tar.gz
            bin_ext: ""
            use_cross: true
          - target: x86_64-apple-darwin
            os: macos-latest
            archive_ext: tar.gz
            bin_ext: ""
            use_cross: false
          - target: aarch64-apple-darwin
            os: macos-latest
            archive_ext: tar.gz
            bin_ext: ""
            use_cross: false
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            archive_ext: zip
            bin_ext: ".exe"
            use_cross: false
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - name: Install cross
        if: matrix.use_cross
        uses: taiki-e/install-action@v2
        with:
          tool: cross
      - name: Build
        shell: bash
        run: |
          if [ "${{ matrix.use_cross }}" = "true" ]; then
            cross build --release --target "${{ matrix.target }}"
          else
            cargo build --release --target "${{ matrix.target }}"
          fi
      - name: Package (Unix)
        if: runner.os != 'Windows'
        shell: bash
        run: |
          mkdir -p dist
          archive="cargo-upkeep-${{ matrix.target }}.${{ matrix.archive_ext }}"
          tar -czf "dist/${archive}" -C "target/${{ matrix.target }}/release" "cargo-upkeep"
          (cd dist && shasum -a 256 "${archive}" > "${archive}.sha256")
      - name: Package (Windows)
        if: runner.os == 'Windows'
        shell: pwsh
        run: |
          New-Item -ItemType Directory -Force dist | Out-Null
          New-Item -ItemType Directory -Force staging | Out-Null
          $archive = "cargo-upkeep-${{ matrix.target }}.${{ matrix.archive_ext }}"
          $binary = "target/${{ matrix.target }}/release/cargo-upkeep${{ matrix.bin_ext }}"
          Copy-Item $binary -Destination "staging/cargo-upkeep${{ matrix.bin_ext }}"
          Compress-Archive -Path "staging/cargo-upkeep${{ matrix.bin_ext }}" -DestinationPath "dist/$archive"
          $hash = (Get-FileHash -Algorithm SHA256 "dist/$archive").Hash.ToLower()
          "$hash  $archive" | Out-File -Encoding ascii "dist/$archive.sha256"
      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: cargo-upkeep-${{ matrix.target }}
          path: dist/*

  release:
    name: Publish Release
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          path: dist
          merge-multiple: true
      - name: Generate changelog
        uses: orhun/git-cliff-action@v4
        id: changelog
        with:
          config: cliff.toml
          args: --latest --strip header
        env:
          OUTPUT: CHANGELOG.md
      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          files: dist/**
          body: ${{ steps.changelog.outputs.content }}
          draft: false
          prerelease: false

  publish-crate:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    needs: release
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
      - name: Publish to crates.io
        run: cargo publish --locked
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}