name: Version Check

on:
  pull_request:
  push:
    branches:
      - main

jobs:
  check-versions:
    name: Check version consistency
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Extract versions
        id: versions
        run: |
          CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
          PLUGIN_VERSION=$(grep '"version":' .claude-plugin/plugin.json | head -1 | sed 's/.*"version": "\(.*\)".*/\1/')

          echo "cargo=$CARGO_VERSION" >> $GITHUB_OUTPUT
          echo "plugin=$PLUGIN_VERSION" >> $GITHUB_OUTPUT

          echo "Cargo.toml version: $CARGO_VERSION"
          echo "plugin.json version: $PLUGIN_VERSION"

      - name: Verify versions match
        run: |
          if [ "${{ steps.versions.outputs.cargo }}" != "${{ steps.versions.outputs.plugin }}" ]; then
            echo "❌ Version mismatch detected!"
            echo "   Cargo.toml: ${{ steps.versions.outputs.cargo }}"
            echo "   plugin.json: ${{ steps.versions.outputs.plugin }}"
            echo ""
            echo "Please update both files to have the same version number."
            exit 1
          fi
          echo "✅ All versions match: ${{ steps.versions.outputs.cargo }}"
