pkg-checker 0.7.3

A Rust tool for checking and updating globally installed Cargo packages with interactive mode and smart prerelease detection
name: Publish to Crates.io

on:
  push:
    tags:
      - "v*" # 当推送以 v 开头的标签时触发

jobs:
  publish:
    name: Publish to Crates.io
    runs-on: ubuntu-latest
    environment: release # Optional: for enhanced security
    permissions:
      id-token: write # Required for OIDC token exchange
      contents: read # Required for reading repository contents
      actions: write # Required for triggering workflows

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

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable

      - name: Authenticate with Crates.io
        uses: rust-lang/crates-io-auth-action@v1
        id: auth

      - name: Publish to Crates.io
        run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

      - name: Success message
        run: |
          echo "✅ Package published to crates.io successfully!"
          echo "📦 Package: pkg-checker"
          echo "🏷️  Tag: ${{ github.ref_name }}"
          echo "🔗 URL: https://crates.io/crates/pkg-checker"

      - name: Trigger GitHub Release
        if: success()
        run: |
          echo "Triggering GitHub Release workflow..."
          echo "Repository: ${{ github.repository }}"
          echo "Ref: main"

          VERSION=${GITHUB_REF#refs/tags/v}
          echo "Triggering release for version: $VERSION"

          RESPONSE=$(curl -s -w "HTTPSTATUS:%{http_code}" -X POST \
            -H "Accept: application/vnd.github.v3+json" \
            -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
            -H "Content-Type: application/json" \
            https://api.github.com/repos/${{ github.repository }}/actions/workflows/release.yml/dispatches \
            -d "{\"ref\":\"main\",\"inputs\":{\"version\":\"$VERSION\"}}")

          HTTP_STATUS=$(echo $RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
          BODY=$(echo $RESPONSE | sed -e 's/HTTPSTATUS:.*//g')

          echo "HTTP Status: $HTTP_STATUS"
          echo "Response: $BODY"

          if [ $HTTP_STATUS -eq 204 ]; then
            echo "✅ Successfully triggered GitHub Release workflow"
          else
            echo "❌ Failed to trigger GitHub Release workflow"
            exit 1
          fi