# Build musl release tarballs on tag pushes (v*) for Linux x86_64 and aarch64.
# Users can also build the same artifacts locally with scripts/package-release.sh.
name: release

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:

permissions:
  contents: write

jobs:
  package:
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
          - target: aarch64-unknown-linux-musl
            # Native ARM runner so we do not need a musl cross-linker on x86.
            os: ubuntu-24.04-arm
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - name: musl tools
        run: sudo apt-get update && sudo apt-get install -y musl-tools
      - name: package
        env:
          # Host tests already run on PRs; packaging job focuses on the artifact.
          SKIP_TEST: "1"
        run: ./scripts/package-release.sh ${{ matrix.target }}
      - name: upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: rtrash-${{ matrix.target }}
          path: dist/*.tar.gz
      - name: upload release assets (tags only)
        if: startsWith(github.ref, 'refs/tags/')
        uses: softprops/action-gh-release@v2
        with:
          files: dist/*.tar.gz
          generate_release_notes: true
          fail_on_unmatched_files: true
