git-branch-status 0.1.0

A command line tool for displaying git branch colored by status
Documentation
name: Release

on:
  push:
    tags:
      - "v*.*.*"
      - "test-release-*"

permissions:
  contents: write

jobs:
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            use-cross: false
          # aarch64 requires cross-compilation since the host is x86_64. We use cross (Docker-based)
          # instead of plain cargo because cross's images ship with a pre-built OpenSSL for each
          # target, eliminating the need to manually set up a cross-compiled OpenSSL environment
          # that git2 depends on.
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            use-cross: true
          - os: macos-latest
            target: x86_64-apple-darwin
            use-cross: false
          - os: macos-latest
            target: aarch64-apple-darwin
            use-cross: false
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            use-cross: false

    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable

      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}

      # Install the target explicitly instead of relying on dtolnay/rust-toolchain's `targets`
      # parameter, which does not reliably install cross-compilation targets on macOS ARM64
      # runners (e.g. x86_64-apple-darwin on macos-latest). Not needed for cross builds since
      # cross compiles inside a Docker container that manages its own toolchain.
      - name: Add Rust target
        if: "!matrix.use-cross"
        run: rustup target add ${{ matrix.target }}

      # git2 depends on OpenSSL. For native Linux builds we install it explicitly; cross builds
      # resolve it inside the container; macOS and Windows toolchains handle it automatically.
      - name: Install system dependencies
        if: runner.os == 'Linux' && !matrix.use-cross
        run: |
          sudo apt-get update
          sudo apt-get install -y libssl-dev pkg-config

      - uses: taiki-e/install-action@v2
        if: matrix.use-cross
        with:
          tool: cross

      - name: Build (native)
        if: "!matrix.use-cross"
        run: cargo build --release --target ${{ matrix.target }}

      - name: Build (cross)
        if: matrix.use-cross
        run: cross build --release --target ${{ matrix.target }}

      - name: Strip binary (Linux x86_64)
        if: matrix.target == 'x86_64-unknown-linux-gnu'
        run: strip target/${{ matrix.target }}/release/git-branch-status

      - name: Strip binary (Linux aarch64)
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          sudo apt-get install -y binutils-aarch64-linux-gnu
          aarch64-linux-gnu-strip target/${{ matrix.target }}/release/git-branch-status

      - name: Strip binary (macOS)
        if: runner.os == 'macOS'
        run: strip target/${{ matrix.target }}/release/git-branch-status

      - name: Package (Unix)
        if: runner.os != 'Windows'
        run: |
          archive="git-branch-status-${{ github.ref_name }}-${{ matrix.target }}.tar.gz"
          tar czvf "$archive" -C target/${{ matrix.target }}/release git-branch-status
          shasum -a 256 "$archive" > "$archive.sha256"

      - name: Package (Windows)
        if: runner.os == 'Windows'
        shell: pwsh
        run: |
          $archive = "git-branch-status-${{ github.ref_name }}-${{ matrix.target }}.zip"
          Compress-Archive -Path "target\${{ matrix.target }}\release\git-branch-status.exe" -DestinationPath $archive
          (Get-FileHash $archive -Algorithm SHA256).Hash | Out-File -FilePath "$archive.sha256" -NoNewline

      - uses: softprops/action-gh-release@v2
        with:
          files: |
            git-branch-status-*.tar.gz
            git-branch-status-*.tar.gz.sha256
            git-branch-status-*.zip
            git-branch-status-*.zip.sha256

  publish-cargo:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    needs: build
    if: startsWith(github.ref, 'refs/tags/v')
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}