name: Release

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: write

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

  build-portable-linux:
    name: Build Fount Portable (Linux MUSL)
    needs: publish-crates-io
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Install MUSL Tools
        run: sudo apt-get update && sudo apt-get install -y musl-tools
        
      - name: Install Rust MUSL Target
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: x86_64-unknown-linux-musl
          
      - name: Build Portable Binary
        run: cargo build --release --target x86_64-unknown-linux-musl
        
      - name: Package Binary
        run: |
          cd target/x86_64-unknown-linux-musl/release
          tar -czf ../../../fount-portable-linux-x86_64.tar.gz fount
          
      - name: Upload to GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          files: fount-portable-linux-x86_64.tar.gz
          generate_release_notes: true
          name: Fount Portable v${{ github.ref_name }}
