gitaccount 0.1.0

A CLI tool to manage multiple git accounts
name: Release

on:
  push:
    tags:
      - "v*"

env:
  CARGO_TERM_COLOR: always

permissions:
  contents: write

jobs:
  build-release:
    name: Build Release
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            artifact_name: gitaccount
            asset_name: gitaccount-linux-x86_64
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            artifact_name: gitaccount
            asset_name: gitaccount-linux-musl-x86_64
          - os: macos-latest
            target: x86_64-apple-darwin
            artifact_name: gitaccount
            asset_name: gitaccount-macos-x86_64
          - os: macos-latest
            target: aarch64-apple-darwin
            artifact_name: gitaccount
            asset_name: gitaccount-macos-aarch64
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            artifact_name: gitaccount.exe
            asset_name: gitaccount-windows-x86_64.exe

    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v4

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

      - name: Install musl-tools (Linux)
        if: matrix.target == 'x86_64-unknown-linux-musl'
        run: sudo apt-get update && sudo apt-get install -y musl-tools

      - name: Cache cargo registry
        uses: actions/cache@v3
        with:
          path: ~/.cargo/registry
          key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

      - name: Cache cargo index
        uses: actions/cache@v3
        with:
          path: ~/.cargo/git
          key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

      - name: Cache cargo build
        uses: actions/cache@v3
        with:
          path: target
          key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

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

      - name: Strip binary (Unix)
        if: runner.os != 'Windows'
        run: strip "target/${{ matrix.target }}/release/${{ matrix.artifact_name }}" || true

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: release-${{ matrix.asset_name }}
          path: target/${{ matrix.target }}/release/${{ matrix.artifact_name }}

  publish-release:
    name: Publish Release
    needs: build-release
    runs-on: ubuntu-latest
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts

      - name: Flatten artifacts
        run: |
          find artifacts -type f -exec mv {} . \;
          rmdir -p artifacts/* 2>/dev/null || true

      - name: Create Release with Assets
        uses: softprops/action-gh-release@v1
        with:
          files: gitaccount*
          draft: false
          prerelease: false
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  publish-crate:
    name: Publish to crates.io
    needs: build-release
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

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

      - name: Publish
        run: cargo publish --token ${{ secrets.CRATES_TOKEN }}