nuclease 0.4.0

Streaming FASTQ preprocessor with a focus on extensibility
name: Release

on:
  push:
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+*'

jobs:
  # Run all CI checks before creating release.
  ci-stable:
    name: CI Stable Checks
    uses: ./.github/workflows/ci.yml

  create-release:
    name: Create Release
    needs: [ci-stable]
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install git-cliff
        uses: taiki-e/install-action@v2
        with:
          tool: git-cliff

      - name: Generate changelog
        run: git-cliff --config cliff.toml --latest --strip header -o CHANGES.md

      - name: Create Release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          PRERELEASE_FLAG=""
          if [[ "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+- ]]; then
            PRERELEASE_FLAG="--prerelease"
          fi
          gh release create "${{ github.ref_name }}" \
            --title "Release ${{ github.ref_name }}" \
            --notes-file CHANGES.md \
            $PRERELEASE_FLAG

  build-release:
    name: Build ${{ matrix.target }}
    needs: create-release
    runs-on: ${{ matrix.os }}
    permissions:
      contents: write
    strategy:
      matrix:
        include:
          # Native Linux builds on ubuntu.
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            use_cross: false
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            use_cross: false

          # ARM64 Linux builds using cross.
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            use_cross: true
          - os: ubuntu-latest
            target: aarch64-unknown-linux-musl
            use_cross: true

          # Native macOS builds.
          - os: macos-14
            target: x86_64-apple-darwin
            use_cross: false
          - os: macos-latest
            target: aarch64-apple-darwin
            use_cross: false

    steps:
      - uses: actions/checkout@v4

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

      - name: Add target
        run: rustup target add ${{ matrix.target }}

      - name: Install musl-tools (Linux musl)
        if: matrix.target == 'x86_64-unknown-linux-musl'
        run: sudo apt-get update && sudo apt-get install -y musl-tools

      - name: Install cross (for cross-compilation)
        if: matrix.use_cross
        uses: taiki-e/install-action@v2
        with:
          tool: cross

      - name: Build with cross
        if: matrix.use_cross
        run: |
          cross build --release --target ${{ matrix.target }}

      - name: Build with cargo
        if: '!matrix.use_cross'
        run: |
          cargo build --release --target ${{ matrix.target }}

      - name: Package
        run: |
          cd target/${{ matrix.target }}/release
          tar czf ../../../nuclease-${{ matrix.target }}.tar.gz nuclease
          cd ../../../
          echo "ASSET_PATH=nuclease-${{ matrix.target }}.tar.gz" >> $GITHUB_ENV

      - name: Upload Release Asset
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh release upload "${{ github.ref_name }}" "${{ env.ASSET_PATH }}" --clobber