rtopm 0.1.0

A modern TUI system resource monitor with Docker and disk I/O tracking
name: Release

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: write

jobs:
  build-and-upload:
    name: Build and Upload - ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
            use-cross: true
          - target: aarch64-unknown-linux-musl
            os: ubuntu-latest
            use-cross: true
          - target: x86_64-apple-darwin
            os: macos-latest
            use-cross: false
          - target: aarch64-apple-darwin
            os: macos-latest
            use-cross: false

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

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

      - name: Install cross-compilation tools
        if: matrix.use-cross
        run: |
          cargo install cross --git https://github.com/cross-rs/cross.git

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

      - name: Package binary
        shell: bash
        run: |
          BINARY_NAME="rtop"
          RELEASE_DIR="target/${{ matrix.target }}/release"
          if [ ! -f "$RELEASE_DIR/$BINARY_NAME" ]; then
            RELEASE_DIR="target/release"
          fi
          
          PKG_NAME="$BINARY_NAME-${{ matrix.target }}.tar.gz"
          tar -czf "$PKG_NAME" -C "$RELEASE_DIR" "$BINARY_NAME"
          echo "PKG_NAME=$PKG_NAME" >> $GITHUB_ENV

      - name: Upload to GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          files: ${{ env.PKG_NAME }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}