ls-plus 0.0.1

Enhanced ls command with modern features - supports both cargo and npm installation
name: Build and Release

on:
  push:
    tags: ['v*']
  workflow_dispatch:

jobs:
  build-binaries:
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            name: ls-plus-x86_64-unknown-linux-gnu
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            name: ls-plus-aarch64-unknown-linux-gnu
          - target: x86_64-apple-darwin
            os: macos-latest
            name: ls-plus-x86_64-apple-darwin
          - target: aarch64-apple-darwin
            os: macos-latest
            name: ls-plus-aarch64-apple-darwin
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            name: ls-plus-x86_64-pc-windows-msvc.exe

    runs-on: ${{ matrix.os }}
    
    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: ${{ matrix.target }}
    
    - name: Install cross-compilation tools (Linux ARM64)
      if: matrix.target == 'aarch64-unknown-linux-gnu'
      run: |
        sudo apt-get update
        sudo apt-get install -y gcc-aarch64-linux-gnu
        echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
    
    - name: Build binary
      run: cargo build --release --target ${{ matrix.target }}
    
    - name: Prepare artifact (Unix)
      if: matrix.os != 'windows-latest'
      run: |
        cp target/${{ matrix.target }}/release/ls-plus ${{ matrix.name }}
        chmod +x ${{ matrix.name }}
    
    - name: Prepare artifact (Windows)
      if: matrix.os == 'windows-latest'
      run: |
        cp target/${{ matrix.target }}/release/ls-plus.exe ${{ matrix.name }}
    
    - name: Upload artifact
      uses: actions/upload-artifact@v4
      with:
        name: ${{ matrix.name }}
        path: ${{ matrix.name }}

  create-release:
    needs: build-binaries
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v4
    
    - name: Download all artifacts
      uses: actions/download-artifact@v4
      with:
        path: ./artifacts
    
    - name: Create GitHub Release
      id: create_release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ github.ref_name }}
        release_name: Release ${{ github.ref_name }}
        draft: false
        prerelease: false
    
    - name: Upload Release Assets
      run: |
        for dir in ./artifacts/*/; do
          file=$(find "$dir" -type f -executable 2>/dev/null | head -1)
          if [ -z "$file" ]; then
            file=$(find "$dir" -type f | head -1)
          fi
          if [ -n "$file" ]; then
            filename=$(basename "$file")
            echo "Uploading $filename"
            curl -X POST \
              -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
              -H "Content-Type: application/octet-stream" \
              --data-binary @"$file" \
              "${{ steps.create_release.outputs.upload_url }}?name=$filename"
          fi
        done

  publish-cargo:
    needs: create-release
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
    
    - name: Publish to crates.io
      run: cargo publish
      env:
        CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  publish-npm:
    needs: create-release
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v4
    
    - name: Setup Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '18'
        registry-url: 'https://registry.npmjs.org'
    
    - name: Install dependencies
      run: npm install
    
    - name: Publish to npm
      run: npm publish
      env:
        NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}