synpad 0.1.0

A full-featured Matrix chat client built with Dioxus
name: Publish Crate

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

permissions:
  contents: read

env:
  CRATE_NAME: synpad

jobs:
  version-info:
    name: Check Version
    runs-on: ubuntu-latest
    outputs:
      next_version: ${{ steps.version.outputs.next_version }}
      prev_version: ${{ steps.version.outputs.prev_version }}
      should_publish: ${{ steps.compare.outputs.should_publish }}

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

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

      - name: Read local and published versions
        id: version
        shell: bash
        run: |
          set -euo pipefail
          next_version="$(sed -nE 's/^\s*version\s*=\s*"(.*)"/\1/p' Cargo.toml | head -n 1)"
          prev_version="$(cargo search "${CRATE_NAME}" --limit 1 | sed -nE 's/^[^"]*"([^"]+)".*/\1/p')"
          echo "next_version=${next_version}" >> "${GITHUB_OUTPUT}"
          echo "prev_version=${prev_version}" >> "${GITHUB_OUTPUT}"
          echo "next version: ${next_version}"
          echo "published version: ${prev_version:-<none>}"

      - name: Validate tag version matches Cargo.toml
        if: startsWith(github.ref, 'refs/tags/v')
        shell: bash
        run: |
          set -euo pipefail
          tag_version="${GITHUB_REF_NAME#v}"
          cargo_version="${{ steps.version.outputs.next_version }}"
          if [ "${tag_version}" != "${cargo_version}" ]; then
            echo "tag version (${tag_version}) does not match Cargo.toml (${cargo_version})"
            exit 1
          fi

      - name: Decide whether publishing is needed
        id: compare
        shell: bash
        run: |
          set -euo pipefail
          if [ -z "${{ steps.version.outputs.prev_version }}" ] || [ "${{ steps.version.outputs.next_version }}" != "${{ steps.version.outputs.prev_version }}" ]; then
            echo "should_publish=true" >> "${GITHUB_OUTPUT}"
            echo "publish required"
          else
            echo "should_publish=false" >> "${GITHUB_OUTPUT}"
            echo "same version on crates.io, skipping publish"
          fi

  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    needs: version-info
    if: needs.version-info.outputs.should_publish == 'true'

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

      - name: Install Linux desktop dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libasound2-dev \
            libwebkit2gtk-4.1-dev \
            libgtk-3-dev \
            libayatana-appindicator3-dev \
            libsoup-3.0-dev \
            libxdo-dev \
            patchelf

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

      - name: Package crate tarball
        run: cargo package --locked --no-verify -p "${{ env.CRATE_NAME }}"

      - name: Publish crate
        run: cargo publish --locked --no-verify -p "${{ env.CRATE_NAME }}" --token "${{ secrets.CRATES_TOKEN }}"