math-sonify 1.5.1

Real-time procedural audio from mathematical dynamical systems (Lorenz, Rossler, Double Pendulum, and more)
name: Release

# Push a tag like v1.4.0 to build the desktop app for Linux, macOS and Windows
# and attach it to a GitHub Release. Publishing to crates.io stays manual.
on:
  push:
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+"
  # Build-only dry run when this workflow itself changes (nothing is released).
  pull_request:
    paths:
      - ".github/workflows/release.yml"
  workflow_dispatch:
    inputs:
      tag:
        description: "Existing tag to (re)build, e.g. v1.4.0"
        required: true

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always
  TAG: ${{ github.event_name == 'pull_request' && 'pr-test' || github.event.inputs.tag || github.ref_name }}

jobs:
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-22.04
            target: x86_64-unknown-linux-gnu
          - os: macos-latest
            target: aarch64-apple-darwin
          - os: macos-latest
            target: x86_64-apple-darwin
          - os: windows-latest
            target: x86_64-pc-windows-msvc
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event_name == 'pull_request' && github.sha || env.TAG }}

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

      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}

      - name: Install Linux audio/GUI libraries
        if: runner.os == 'Linux'
        run: |

          sudo apt-get update
          sudo apt-get install -y pkg-config libasound2-dev libjack-jackd2-dev \
            libx11-dev libx11-xcb-dev libxcb1-dev libxcb-icccm4-dev libxcb-dri2-0-dev \
            libxcursor-dev libxrandr-dev libxi-dev libxkbcommon-dev libgl1-mesa-dev libudev-dev

      - name: Build
        run: cargo build --release --locked -p math-sonify --bin math-sonify --target ${{ matrix.target }}

      - name: Package (Unix)
        if: runner.os != 'Windows'
        shell: bash
        run: |

          name="math-sonify-${TAG}-${{ matrix.target }}"
          mkdir "$name"
          cp "target/${{ matrix.target }}/release/math-sonify" README.md LICENSE config.toml collab.html "$name/"
          tar czf "$name.tar.gz" "$name"
          shasum -a 256 "$name.tar.gz" > "$name.tar.gz.sha256"

      - name: Package (Windows)
        if: runner.os == 'Windows'
        shell: pwsh
        run: |

          $name = "math-sonify-$env:TAG-${{ matrix.target }}"
          New-Item -ItemType Directory $name | Out-Null
          Copy-Item "target/${{ matrix.target }}/release/math-sonify.exe", README.md, LICENSE, config.toml, collab.html $name
          Compress-Archive -Path $name -DestinationPath "$name.zip"
          $hash = (Get-FileHash "$name.zip" -Algorithm SHA256).Hash.ToLower()
          "$hash  $name.zip" | Out-File -Encoding ascii "$name.zip.sha256"

      - name: Smoke test
        shell: bash
        run: |

          bin="target/${{ matrix.target }}/release/math-sonify"
          if [ "${{ matrix.target }}" = "x86_64-apple-darwin" ]; then exit 0; fi
          "$bin" --version
          "$bin" --help

      - uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.target }}
          path: |

            math-sonify-*.tar.gz*
            math-sonify-*.zip*

  release:
    name: Publish GitHub Release
    needs: build
    if: github.event_name != 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v4
        with:
          path: dist
          merge-multiple: true

      - name: Checksums
        run: |

          cd dist
          cat *.sha256 > SHA256SUMS.txt
          cat SHA256SUMS.txt

      - name: Create or update release
        env:
          GH_TOKEN: ${{ github.token }}
          GH_REPO: ${{ github.repository }}
        run: |

          ls -l dist
          notes="Prebuilt math-sonify desktop app for Windows, macOS (Apple Silicon and Intel) and Linux.

          Pick the file for your system: \`*-x86_64-pc-windows-msvc.zip\` (Windows), \`*-aarch64-apple-darwin.tar.gz\` (Apple Silicon Mac), \`*-x86_64-apple-darwin.tar.gz\` (Intel Mac), \`*-x86_64-unknown-linux-gnu.tar.gz\` (Linux). The binaries are unsigned, so Windows SmartScreen may warn about an unknown publisher (More info, then Run anyway) and macOS may need right-click, Open. Run with \`--help\` for the headless WAV renderer. See CHANGELOG.md for what changed."
          if gh release view "$TAG" >/dev/null 2>&1; then
            gh release upload "$TAG" dist/* --clobber
          else
            gh release create "$TAG" dist/* --title "math-sonify $TAG" --notes "$notes"
          fi