alman 0.1.2

A command-line tool and TUI for managing shell aliases with intelligent suggestions
name: Cross-compile and Upload Release Assets for alman

on:
  push:
    tags:
      - 'v*'  # Triggers the workflow on tag pushes like v1.0, v2.1.1, etc.

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  build-and-upload:
    name: Build and Upload Release Assets
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
            ext: tar.gz
          - target: aarch64-unknown-linux-musl
            os: ubuntu-latest
            ext: tar.gz
          - target: armv7-unknown-linux-musleabihf
            os: ubuntu-latest
            ext: tar.gz
          - target: x86_64-apple-darwin
            os: macos-latest
            ext: tar.gz
          - target: aarch64-apple-darwin
            os: macos-latest
            ext: tar.gz

    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout code at the pushed tag
        uses: actions/checkout@v4

      - name: Install cross (if needed)
        if: runner.os == 'Linux'
        run: |
          cargo install cross --git https://github.com/cross-rs/cross

      - name: Build with cross/cargo
        uses: houseabsolute/actions-rust-cross@v1
        with:
          command: build
          target: ${{ matrix.target }}
          args: --locked --release
          strip: true

      - name: Package binary (tar.gz/zip)
        shell: bash
        run: |
          set -e
          NAME="alman"
          TARGET="${{ matrix.target }}"
          EXT="${{ matrix.ext }}"
          OUTDIR="release"
          mkdir -p "$OUTDIR"
          if [[ "$TARGET" == *windows* ]]; then
            BIN="${NAME}.exe"
            cp "target/${TARGET}/release/${BIN}" "${BIN}"
            7z a -tzip "$OUTDIR/${NAME}-${TARGET}.zip" "${BIN}" LICENSE README.md || \
              zip "$OUTDIR/${NAME}-${TARGET}.zip" "${BIN}" LICENSE README.md
          else
            BIN="${NAME}"
            cp "target/${TARGET}/release/${BIN}" "${BIN}"
            tar czf "$OUTDIR/${NAME}-${TARGET}.tar.gz" "${BIN}" LICENSE README.md
          fi

      - name: List packaged files
        shell: bash
        run: ls -lh release/

      - name: Get release info
        id: get_release
        uses: bruceadams/get-release@v1.3.2
        with:
          tag_name: ${{ github.ref_name }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Upload release asset
        uses: shogo82148/actions-upload-release-asset@v1
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: release/alman-${{ matrix.target }}.${{ matrix.ext }}