ccagents 0.1.0

CLI tool for managing Claude Code agents in local projects
Documentation
name: Publish to crates.io

on:
  release:
    types: [created]
  workflow_dispatch:
    inputs:
      version:
        description: 'Version to publish (e.g., 0.1.0)'
        required: true
        type: string

permissions:
  contents: write

jobs:
  verify:
    name: Verify Release
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.get_version.outputs.version }}
    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
    
    - name: Get version
      id: get_version
      run: |
        if [ "${{ github.event_name }}" == "release" ]; then
          VERSION="${{ github.event.release.tag_name }}"
          VERSION="${VERSION#v}"  # Remove 'v' prefix if present
        else
          VERSION="${{ github.event.inputs.version }}"
        fi
        echo "version=$VERSION" >> $GITHUB_OUTPUT
        
        # Verify version in Cargo.toml matches
        CARGO_VERSION=$(grep "^version" Cargo.toml | sed 's/version = "\(.*\)"/\1/')
        if [ "$CARGO_VERSION" != "$VERSION" ]; then
          echo "Error: Cargo.toml version ($CARGO_VERSION) doesn't match release version ($VERSION)"
          exit 1
        fi
        echo "✅ Version $VERSION confirmed"
    
    - name: Check crate name availability
      run: |
        if curl -s https://crates.io/api/v1/crates/ccagents | grep -q '"name":"ccagents"'; then
          echo "✅ Crate already exists, will publish new version"
        else
          echo "✅ Crate name is available for first publish"
        fi
    
    - name: Run tests
      run: |
        cargo test --all-features
        cargo clippy -- -D warnings
        cargo fmt -- --check
    
    - name: Verify package
      run: |
        cargo publish --dry-run
        echo "✅ Package verification successful"

  publish-crates:
    name: Publish to crates.io
    needs: verify
    runs-on: ubuntu-latest
    environment: crates-io
    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
    
    - name: Publish to crates.io
      env:
        CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
      run: |
        cargo publish --token "$CARGO_REGISTRY_TOKEN"
        echo "✅ Published version ${{ needs.verify.outputs.version }} to crates.io"
    
    - name: Wait for crates.io
      run: |
        echo "Waiting for crates.io to index the new version..."
        sleep 30
        
    - name: Verify publication
      run: |
        VERSION="${{ needs.verify.outputs.version }}"
        if curl -s https://crates.io/api/v1/crates/ccagents | grep -q "\"max_version\":\"$VERSION\""; then
          echo "✅ Version $VERSION successfully published to crates.io"
        else
          echo "⚠️ Version may still be indexing on crates.io"
        fi

  create-release-artifacts:
    name: Create Release Artifacts
    needs: [verify, publish-crates]
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            binary_name: ccagents
            asset_name: ccagents-linux-amd64
          
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            binary_name: ccagents
            asset_name: ccagents-linux-musl-amd64
          
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            binary_name: ccagents
            asset_name: ccagents-linux-arm64
          
          - os: macos-latest
            target: x86_64-apple-darwin
            binary_name: ccagents
            asset_name: ccagents-macos-amd64
          
          - os: macos-latest
            target: aarch64-apple-darwin
            binary_name: ccagents
            asset_name: ccagents-macos-arm64

    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: ${{ matrix.target }}
    
    - name: Install cross-compilation tools
      if: matrix.target == 'aarch64-unknown-linux-gnu'
      run: |
        sudo apt-get update
        sudo apt-get install -y gcc-aarch64-linux-gnu
    
    - name: Install musl tools
      if: matrix.target == 'x86_64-unknown-linux-musl'
      run: |
        sudo apt-get update
        sudo apt-get install -y musl-tools
    
    - name: Build
      run: cargo build --release --target ${{ matrix.target }}
    
    - name: Strip binary (Linux/macOS)
      if: matrix.os != 'windows-latest'
      run: |
        strip target/${{ matrix.target }}/release/${{ matrix.binary_name }}
    
    - name: Create archive
      run: |
        cd target/${{ matrix.target }}/release
        tar czf ../../../${{ matrix.asset_name }}.tar.gz ${{ matrix.binary_name }}
        cd ../../../
        sha256sum ${{ matrix.asset_name }}.tar.gz > ${{ matrix.asset_name }}.tar.gz.sha256
    
    - name: Upload to release
      if: github.event_name == 'release'
      uses: softprops/action-gh-release@v1
      with:
        files: |
          ${{ matrix.asset_name }}.tar.gz
          ${{ matrix.asset_name }}.tar.gz.sha256
    
    - name: Upload artifacts (manual trigger)
      if: github.event_name == 'workflow_dispatch'
      uses: actions/upload-artifact@v3
      with:
        name: binaries-${{ matrix.asset_name }}
        path: |
          ${{ matrix.asset_name }}.tar.gz
          ${{ matrix.asset_name }}.tar.gz.sha256

  create-tag:
    name: Create Git Tag
    needs: [verify, publish-crates]
    runs-on: ubuntu-latest
    if: github.event_name == 'workflow_dispatch'
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
    
    - name: Configure Git
      run: |
        git config user.name "GitHub Actions"
        git config user.email "actions@github.com"
    
    - name: Create and push tag
      run: |
        VERSION="${{ needs.verify.outputs.version }}"
        git tag -a "v$VERSION" -m "Release version $VERSION"
        git push origin "v$VERSION"
        echo "✅ Created tag v$VERSION"
    
    - name: Create GitHub Release
      uses: softprops/action-gh-release@v1
      with:
        tag_name: v${{ needs.verify.outputs.version }}
        name: v${{ needs.verify.outputs.version }}
        body: |
          ## 🚀 Released to crates.io
          
          Version ${{ needs.verify.outputs.version }} has been published to [crates.io](https://crates.io/crates/ccagents).
          
          ### Installation
          
          ```bash
          cargo install ccagents
          ```
          
          ### Changes
          
          See [CHANGELOG.md](https://github.com/Bitropy/ccagents/blob/main/CHANGELOG.md) for details.
        draft: false
        prerelease: false