actr-cli 0.1.15

Command line tool for Actor-RTC framework projects
Documentation
name: Publish to crates.io

on:
  push:
    tags:
      - "v*"
  release:
    types: [published]
  workflow_dispatch:
    inputs:
      version:
        description: "Version to publish (e.g., 0.1.3)"
        required: false
        type: string

env:
  CARGO_TERM_COLOR: always

jobs:
  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v4

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

      - name: Install protoc
        uses: arduino/setup-protoc@v3

      - uses: Swatinem/rust-cache@v2

      - name: Check if version already exists
        id: check_version
        continue-on-error: true
        run: |
          VERSION=$(grep -E '^version\s*=' Cargo.toml | head -1 | sed -E 's/^version\s*=\s*"([^"]+)".*/\1/')
          echo "Current version: $VERSION"
          echo "version=$VERSION" >> $GITHUB_OUTPUT

          # Check if version exists on crates.io
          RESPONSE=$(curl -s "https://crates.io/api/v1/crates/actr-cli/versions" || echo "")
          if echo "$RESPONSE" | grep -q "\"num\":\"$VERSION\""; then
            echo "⚠️ Version $VERSION already exists on crates.io"
            echo "Skipping publish..."
            echo "skip_publish=true" >> $GITHUB_OUTPUT
            exit 0
          else
            echo "✅ Version $VERSION is new and can be published"
            echo "skip_publish=false" >> $GITHUB_OUTPUT
          fi

      - name: Publish to crates.io
        if: steps.check_version.outputs.skip_publish != 'true'
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish --verbose