spotatui 0.30.1

A Spotify client for the terminal written in Rust, powered by Ratatui
name: Continuous Deployment

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

env:
  CARGO_TERM_COLOR: always
  BINARY_NAME: spotatui

jobs:
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            artifact_prefix: linux-x86_64 # most Linux distros
            binary_postfix: ""
            audio_features: "audio-viz"
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            artifact_prefix: linux-alpine-x86_64 # Alpine / musl
            binary_postfix: ""
            audio_features: ""  # No audio-viz for musl (pkg-config cross-compilation not supported)
          - os: macos-latest
            target: x86_64-apple-darwin
            artifact_prefix: macos-x86_64
            binary_postfix: ""
            audio_features: "audio-viz-cpal"
          - os: macos-latest
            target: aarch64-apple-darwin
            artifact_prefix: macos-aarch64
            binary_postfix: ""
            audio_features: "audio-viz-cpal"
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            artifact_prefix: windows-x86_64
            binary_postfix: ".exe"
            audio_features: "audio-viz-cpal"

    steps:
      - name: Checkout sources
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ 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 Linux dependencies
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libpipewire-0.3-dev libspa-0.2-dev

      - name: Install macOS dependencies
        if: runner.os == 'macOS'
        run: brew install openssl@3

      - name: Build release binary
        run: |
          if [ -z "${{ matrix.audio_features }}" ]; then
            cargo build --release --target ${{ matrix.target }} --no-default-features --features telemetry
          else
            cargo build --release --target ${{ matrix.target }} --no-default-features --features telemetry,${{ matrix.audio_features }}
          fi
        shell: bash

      - name: Package binary (Unix)
        if: runner.os != 'Windows'
        shell: bash
        run: |
          cd target/${{ matrix.target }}/release
          BINARY=${{ env.BINARY_NAME }}${{ matrix.binary_postfix }}
          strip $BINARY || true
          RELEASE_NAME=${{ env.BINARY_NAME }}-${{ matrix.artifact_prefix }}
          tar czvf ../../../$RELEASE_NAME.tar.gz $BINARY
          cd ../../..
          shasum -a 256 $RELEASE_NAME.tar.gz > $RELEASE_NAME.tar.gz.sha256

      - name: Package binary (Windows)
        if: runner.os == 'Windows'
        shell: bash
        run: |
          cd target/${{ matrix.target }}/release
          BINARY=${{ env.BINARY_NAME }}${{ matrix.binary_postfix }}
          RELEASE_NAME=${{ env.BINARY_NAME }}-${{ matrix.artifact_prefix }}
          7z a ../../../$RELEASE_NAME.zip $BINARY
          cd ../../..
          certutil -hashfile $RELEASE_NAME.zip sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.zip.sha256

      - name: Upload artifact (Unix)
        if: runner.os != 'Windows'
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-${{ matrix.artifact_prefix }}
          path: |
            ${{ env.BINARY_NAME }}-${{ matrix.artifact_prefix }}.tar.gz
            ${{ env.BINARY_NAME }}-${{ matrix.artifact_prefix }}.tar.gz.sha256

      - name: Upload artifact (Windows)
        if: runner.os == 'Windows'
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-${{ matrix.artifact_prefix }}
          path: |
            ${{ env.BINARY_NAME }}-${{ matrix.artifact_prefix }}.zip
            ${{ env.BINARY_NAME }}-${{ matrix.artifact_prefix }}.zip.sha256

  release:
    name: Create GitHub Release
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - name: Checkout sources
        uses: actions/checkout@v4

      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts
          merge-multiple: true

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          files: artifacts/*
          generate_release_notes: true
          body: |
            ## Downloads

            - On **Windows 10/11 (64-bit)** → `spotatui-windows-x86_64.zip`
            - On **Linux (Ubuntu, Arch, Fedora, etc.)** → `spotatui-linux-x86_64.tar.gz`
            - On **Linux (Alpine / musl)** → `spotatui-linux-alpine-x86_64.tar.gz`
            - On **macOS with Intel CPU** → `spotatui-macos-x86_64.tar.gz`
            - On **macOS with Apple Silicon (M1/M2/M3)** → `spotatui-macos-aarch64.tar.gz`

            Checksums (`.sha256`) are optional and only needed if you want to verify the download.
          draft: false
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  publish-cargo:
    name: Publish to crates.io
    needs: release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Install Linux dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev

      - name: Publish to crates.io
        run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} --allow-dirty