commando 1.1.0

An interactive CLI tool to help you write conventional commit messages with ease.
name: Release

on:
  workflow_dispatch: # Manual trigger only

permissions:
  contents: write

jobs:
  publish-crates-io:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          fetch-depth: 0

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

      - name: Install cargo-release
        run: cargo install cargo-release

      - name: Configure Git
        run: |
          git config --global user.name "GitHub Actions"
          git config --global user.email "github-actions@github.com"
          git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git

      - name: Run cargo release
        env:
          CARGO_TERM_COLOR: always
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo release --execute --no-confirm

  create-release:
    name: Create Release
    needs: publish-crates-io
    runs-on: ubuntu-latest
    outputs:
      upload_url: ${{ steps.create_release.outputs.upload_url }}
      version: ${{ steps.get_version.outputs.version }}
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Get latest tag
        id: get_version
        run: |
          git fetch --tags
          LATEST_TAG=$(git describe --tags --abbrev=0)
          echo "version=${LATEST_TAG#v}" >> $GITHUB_OUTPUT
          echo "tag=${LATEST_TAG}" >> $GITHUB_OUTPUT

      - name: Create Release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ steps.get_version.outputs.tag }}
          release_name: Commando ${{ steps.get_version.outputs.tag }}
          draft: false
          prerelease: false
          body: |
            ## Installation

            ### Quick Install (Linux/macOS)
            ```bash
            curl -sSfL https://raw.githubusercontent.com/tgenericx/commando/main/install.sh | sh
            ```

            ### Quick Install (Windows)
            ```powershell
            irm https://raw.githubusercontent.com/tgenericx/commando/main/install.ps1 | iex
            ```

            ### Manual Download
            Download the appropriate binary for your platform below.

            ---

            ## Changes
            See [CHANGELOG.md](https://github.com/tgenericx/commando/blob/main/CHANGELOG.md) for details.

  build:
    name: Build ${{ matrix.target }}
    needs: create-release
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux x86_64
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            artifact_name: commando
            asset_name: commando-linux-x86_64

          # Linux ARM64
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            artifact_name: commando
            asset_name: commando-linux-aarch64
            use_cross: true

          # macOS x86_64 (Intel)
          - os: macos-latest
            target: x86_64-apple-darwin
            artifact_name: commando
            asset_name: commando-macos-x86_64

          # macOS ARM64 (Apple Silicon)
          - os: macos-latest
            target: aarch64-apple-darwin
            artifact_name: commando
            asset_name: commando-macos-aarch64

          # Windows x86_64
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            artifact_name: commando.exe
            asset_name: commando-windows-x86_64.exe

    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

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

      - name: Install cross (if needed)
        if: matrix.use_cross
        run: cargo install cross --git https://github.com/cross-rs/cross

      - name: Build binary
        run: |
          if [ "${{ matrix.use_cross }}" = "true" ]; then
            cross build --release --target ${{ matrix.target }}
          else
            cargo build --release --target ${{ matrix.target }}
          fi
        shell: bash

      - name: Strip binary (Linux/macOS)
        if: matrix.os != 'windows-latest'
        run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }}

      - name: Upload binary to release
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ needs.create-release.outputs.upload_url }}
          asset_path: target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
          asset_name: ${{ matrix.asset_name }}
          asset_content_type: application/octet-stream

  publish-checksums:
    name: Publish checksums
    needs: [create-release, build]
    runs-on: ubuntu-latest
    steps:
      - name: Download all artifacts
        uses: actions/download-artifact@v7

      - name: Generate checksums
        run: |
          for file in */commando*; do
            if [ -f "$file" ]; then
              sha256sum "$file" >> SHA256SUMS
            fi
          done

      - name: Upload checksums
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ needs.create-release.outputs.upload_url }}
          asset_path: SHA256SUMS
          asset_name: SHA256SUMS
          asset_content_type: text/plain