bevy_octopus 0.8.0

ECS based networking library for Bevy
Documentation
name: Release WebSocket

on:
  push:
    tags: ["v*"]
  workflow_dispatch:
    inputs:
      version:
        description: "Version to release (without 'v' prefix)"
        required: true
        type: string
      publish:
        description: "Publish to crates.io"
        required: false
        default: true
        type: boolean

env:
  CARGO_TERM_COLOR: always

jobs:
  release:
    name: Release WebSocket
    runs-on: ubuntu-latest
    permissions:
      contents: write
      packages: write
    defaults:
      run:
        working-directory: ./bevy_octopus_websocket
    steps:
      - name: Checkout sources
        uses: actions/checkout@v4.2.2
        with:
          fetch-depth: 0

      - name: Install stable toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy, rustfmt

      - name: Cache cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
          key: ${{ runner.os }}-cargo-release-websocket-${{ hashFiles('bevy_octopus_websocket/**/Cargo.toml') }}
          restore-keys: |
            ${{ runner.os }}-cargo-release-websocket-

      - name: Cache cargo build
        uses: actions/cache@v4
        with:
          path: bevy_octopus_websocket/target/
          key: ${{ runner.os }}-cargo-release-build-websocket-${{ hashFiles('bevy_octopus_websocket/**/Cargo.toml') }}
          restore-keys: |
            ${{ runner.os }}-cargo-release-build-websocket-

      - name: Determine version (tag or manual)
        id: version
        run: |
          if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
            echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
          else
            # Extract version from tag, filtering out websocket suffix if present
            VERSION=${GITHUB_REF#refs/tags/v}
            echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
          fi

      - name: Verify version matches Cargo.toml
        run: |
          CARGO_VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "//' | sed 's/"//g')
          if [ "$CARGO_VERSION" != "${{ steps.version.outputs.VERSION }}" ]; then
            echo "Version mismatch: tag v${{ steps.version.outputs.VERSION }} vs Cargo.toml $CARGO_VERSION"
            exit 1
          fi
          echo "✅ Version verified: $CARGO_VERSION"

      - name: Run tests before release
        run: cargo test

      - name: Run clippy before release
        run: cargo clippy -- -D warnings

      - name: Check formatting before release
        run: cargo fmt --all -- --check

      - name: Check if this is a pre-release
        id: prerelease_check
        run: |
          VERSION="${{ steps.version.outputs.VERSION }}"
          if [[ "$VERSION" =~ (alpha|beta|rc) ]]; then
            echo "prerelease=true" >> $GITHUB_OUTPUT
          else
            echo "prerelease=false" >> $GITHUB_OUTPUT
          fi

      - name: Generate release notes
        id: release_notes
        run: |
          # Simple release notes for websocket library
          cat > release_notes.md << 'EOF'
          ## 🚀 bevy_octopus_websocket v${{ steps.version.outputs.VERSION }}

          WebSocket transport for [bevy_octopus](https://crates.io/crates/bevy_octopus).

          ### 📦 Installation
          \`\`\`toml
          [dependencies]
          bevy_octopus_websocket = "${{ steps.version.outputs.VERSION }}"
          bevy_octopus = { version = "0.8", features = ["serde_json", "bincode"] }
          \`\`\`

          ### ⚙️ Compatible Versions
          - bevy_octopus: 0.8.0
          - bevy: 0.19

          ---
          *WebSocket transport built with ❤️ using Bevy ECS*
          EOF

      - name: Create tag for manual run
        if: github.event_name == 'workflow_dispatch'
        run: |
          git config user.name github-actions
          git config user.email github-actions@github.com
          git tag -a v${{ steps.version.outputs.VERSION }} -m "chore(release): v${{ steps.version.outputs.VERSION }}" || true
          git push origin v${{ steps.version.outputs.VERSION }} || true

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2.1.0
        with:
          tag_name: v${{ steps.version.outputs.VERSION }}
          name: bevy_octopus_websocket v${{ steps.version.outputs.VERSION }}
          body_path: bevy_octopus_websocket/release_notes.md
          draft: false
          prerelease: ${{ steps.prerelease_check.outputs.prerelease }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Clean up generated files before publish
        run: rm -f release_notes.md

      - name: Build release artifacts
        run: cargo build --release

      - name: Publish to crates.io
        if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true')
        run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - name: Wait for crates.io index (with timeout)
        run: |
          echo "⏳ Waiting for crates.io to index the new version..."
          timeout 300 bash -c 'until cargo search bevy_octopus_websocket --limit 1 | grep -q "${{ steps.version.outputs.VERSION }}"; do sleep 10; done' || echo "⚠️ Timeout waiting for crates.io indexing, but release should still be successful"