spotatui 0.28.0

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: ""
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            artifact_prefix: linux-alpine-x86_64   # Alpine / musl
            binary_postfix: ""
          - os: macos-latest
            target: x86_64-apple-darwin
            artifact_prefix: macos-x86_64
            binary_postfix: ""
          - os: macos-latest
            target: aarch64-apple-darwin
            artifact_prefix: macos-aarch64
            binary_postfix: ""
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            artifact_prefix: windows-x86_64
            binary_postfix: ".exe"

    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

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

      - name: Build release binary
        run: cargo build --release --target ${{ matrix.target }}

      - 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

  publish-aur:
    name: Publish to AUR
    needs: release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v4

      - name: Update PKGBUILD version
        run: |
          VERSION=${GITHUB_REF#refs/tags/v}
          VERSION=${VERSION#refs/tags/}
          sed -i "s/^pkgver=.*/pkgver=$VERSION/" aur/PKGBUILD
          sed -i "s/^pkgrel=.*/pkgrel=1/" aur/PKGBUILD

      - name: Publish AUR package
        uses: KSXGitHub/github-actions-deploy-aur@v2.7.2
        with:
          pkgname: spotatui
          pkgbuild: ./aur/PKGBUILD
          commit_username: ${{ secrets.AUR_USERNAME }}
          commit_email: ${{ secrets.AUR_EMAIL }}
          ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
          commit_message: Update AUR package to ${{ github.ref_name }}
          updpkgsums: true