sphinx-ultra 0.3.0

High-performance Rust-based Sphinx documentation builder for large codebases
Documentation
name: Release

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  validate-version:
    name: Validate Version Consistency
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v5

    - name: Get tag version
      id: tag_version
      shell: bash
      run: |
        VERSION=${GITHUB_REF#refs/tags/v}
        echo "version=$VERSION" >> $GITHUB_OUTPUT
        echo "Tag version: $VERSION"

    - name: Get Cargo.toml version
      id: cargo_version
      shell: bash
      run: |
        CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -n1 | sed 's/version = "\(.*\)"/\1/')
        echo "version=$CARGO_VERSION" >> $GITHUB_OUTPUT
        echo "Cargo.toml version: $CARGO_VERSION"

    - name: Validate version consistency
      shell: bash
      run: |
        TAG_VERSION="${{ steps.tag_version.outputs.version }}"
        CARGO_VERSION="${{ steps.cargo_version.outputs.version }}"
        
        echo "Comparing versions:"
        echo "  Tag version: $TAG_VERSION"
        echo "  Cargo.toml version: $CARGO_VERSION"
        
        if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
          echo "❌ ERROR: Version mismatch detected!"
          echo "The git tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
          echo ""
          echo "To fix this:"
          echo "1. Update Cargo.toml version to match the tag, OR"
          echo "2. Delete this tag and create a new one with the correct version"
          echo "3. Use scripts/release.sh to automate releases safely"
          exit 1
        fi
        
        echo "✅ Version consistency check passed!"

  build-release:
    name: Build Release
    needs: validate-version
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
        - os: ubuntu-latest
          target: x86_64-unknown-linux-gnu
          binary_name: sphinx-ultra
        - os: ubuntu-latest
          target: x86_64-unknown-linux-musl
          binary_name: sphinx-ultra
        - os: windows-latest
          target: x86_64-pc-windows-msvc
          binary_name: sphinx-ultra.exe
        - os: macos-latest
          target: x86_64-apple-darwin
          binary_name: sphinx-ultra
        - os: macos-latest
          target: aarch64-apple-darwin
          binary_name: sphinx-ultra

    steps:
    - name: Checkout repository
      uses: actions/checkout@v5

    - name: Get the release version from the tag
      shell: bash
      run: |
        VERSION=${GITHUB_REF#refs/tags/v}
        echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV

    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: ${{ matrix.target }}

    - name: Install musl tools
      if: matrix.target == 'x86_64-unknown-linux-musl'
      run: |
        sudo apt-get update
        sudo apt-get install -y musl-tools musl-dev

    - name: Build release binary
      run: cargo build --release --target ${{ matrix.target }}

    - name: Strip release binary (linux and macos)
      if: matrix.os != 'windows-latest'
      run: strip "target/${{ matrix.target }}/release/${{ matrix.binary_name }}"

    - name: Build archive
      shell: bash
      run: |
        staging="sphinx-ultra-${{ env.RELEASE_VERSION }}-${{ matrix.target }}"
        mkdir -p "$staging"

        cp "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" "$staging/"
        cp {README.md,LICENSE,CHANGELOG.md} "$staging/"

        if [ "${{ matrix.os }}" = "windows-latest" ]; then
          7z a "$staging.zip" "$staging"
          echo "ASSET=$staging.zip" >> $GITHUB_ENV
        else
          tar czf "$staging.tar.gz" "$staging"
          echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
        fi

    - name: Upload release archive
      uses: softprops/action-gh-release@v2
      with:
        files: ${{ env.ASSET }}

  publish-crate:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5

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

    - name: Check for crates.io token
      id: check_token
      run: |
        if [ -z "${{ secrets.CARGO_REGISTRY_TOKEN }}" ]; then
          echo "has_token=false" >> $GITHUB_OUTPUT
          echo "::notice::Skipping crates.io publishing - CARGO_REGISTRY_TOKEN not set"
        else
          echo "has_token=true" >> $GITHUB_OUTPUT
        fi

    - name: Publish to crates.io
      if: steps.check_token.outputs.has_token == 'true'
      run: cargo publish
      env:
        CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

    - name: Show crates.io setup instructions
      if: steps.check_token.outputs.has_token == 'false'
      run: |
        echo "ℹ️ Skipping crates.io publishing because CARGO_REGISTRY_TOKEN is not set"
        echo ""
        echo "To enable automatic crates.io publishing:"
        echo "1. Generate a token at https://crates.io/me"
        echo "2. Add it as a secret named CARGO_REGISTRY_TOKEN in your GitHub repository"
        echo "3. Go to: Settings → Secrets and variables → Actions → New repository secret"
        echo ""
        echo "For now, you can publish manually with:"
        echo "  cargo publish"