playr 0.5.1

A minimal TUI music player that plays local files and contacts nothing
Documentation
# Builds playr for each platform when a version tag is pushed, and publishes
# the archives to a GitHub release whose notes are that version's CHANGELOG.md
# section. Tags are bare versions, such as 0.5.0.
name: release

on:
  push:
    tags: ["[0-9]+.[0-9]+.[0-9]+"]
  # To release a tag pushed before this workflow existed.
  workflow_dispatch:
    inputs:
      tag:
        description: Existing tag to release, such as 0.5.0
        required: true

permissions:
  contents: read

env:
  TAG: ${{ inputs.tag || github.ref_name }}
  CARGO_TERM_COLOR: always

jobs:
  check:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v7
        with:
          ref: ${{ env.TAG }}

      - name: The tag matches the version in Cargo.toml
        run: |
          version=$(sed -n 's/^version = "\(.*\)"$/\1/p' Cargo.toml | head -1)
          if [ "$version" != "$TAG" ]; then
            echo "tag $TAG does not match version $version in Cargo.toml"
            exit 1
          fi

      - name: Release notes from CHANGELOG.md
        run: |
          awk -v v="$TAG" '$0 == "## [" v "]" {found = 1; next} found && /^## \[/ {exit} found' CHANGELOG.md > notes.md
          if ! grep -q '[^[:space:]]' notes.md; then
            echo "CHANGELOG.md has no ## [$TAG] section"
            exit 1
          fi

      - uses: actions/upload-artifact@v7
        with:
          name: notes
          path: notes.md

      - name: Install ALSA headers
        run: sudo apt-get update && sudo apt-get install -y libasound2-dev

      - uses: dtolnay/rust-toolchain@stable

      - name: Test, with and without Opus
        run: make test

  build:
    needs: check
    strategy:
      fail-fast: false
      matrix:
        include:
          # 22.04, so the binaries run on glibc 2.35 and later.
          - { target: x86_64-unknown-linux-gnu, os: ubuntu-22.04 }
          - { target: aarch64-unknown-linux-gnu, os: ubuntu-22.04-arm }
          - { target: aarch64-apple-darwin, os: macos-latest }
          - { target: x86_64-apple-darwin, os: macos-latest }
          - { target: x86_64-pc-windows-msvc, os: windows-latest }
    runs-on: ${{ matrix.os }}
    env:
      MACOSX_DEPLOYMENT_TARGET: "11.0"
    steps:
      - uses: actions/checkout@v7
        with:
          ref: ${{ env.TAG }}

      - name: Install ALSA headers
        if: runner.os == 'Linux'
        run: sudo apt-get update && sudo apt-get install -y libasound2-dev

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

      # Opus needs cmake, which every runner image has.
      - name: Build
        run: cargo build --release --locked --features opus --target ${{ matrix.target }}

      - name: Package
        shell: bash
        run: |
          name="playr-$TAG-${{ matrix.target }}"
          mkdir "$name"
          cp README.md CHANGELOG.md LICENSE "$name/"
          if [ "$RUNNER_OS" = Windows ]; then
            cp "target/${{ matrix.target }}/release/playr.exe" "$name/"
            7z a "$name.zip" "$name"
          else
            cp "target/${{ matrix.target }}/release/playr" "$name/"
            tar czf "$name.tar.gz" "$name"
          fi

      - uses: actions/upload-artifact@v7
        with:
          name: playr-${{ matrix.target }}
          path: playr-${{ env.TAG }}-${{ matrix.target }}.*

  release:
    needs: build
    runs-on: ubuntu-22.04
    permissions:
      contents: write
    steps:
      - uses: actions/download-artifact@v8
        with:
          path: dist
          merge-multiple: true

      - name: Checksums
        working-directory: dist
        run: sha256sum playr-* > SHA256SUMS

      - name: Publish the release
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          gh release create "$TAG" dist/playr-* dist/SHA256SUMS \
            --repo "${{ github.repository }}" \
            --verify-tag \
            --title "$TAG" \
            --notes-file dist/notes.md