fiasto 0.2.7

High-performance modern Wilkinson's formula parsing for statistical models. Parses R-style formulas into structured JSON metadata supporting linear models, mixed effects, and complex statistical specifications.
Documentation
name: Release

on:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: write

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          
      - name: Authenticate GitHub CLI
        run: |
          echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
          
      - name: Extract version from CHANGELOG.md
        id: version
        run: |
          # Extract the latest version from CHANGELOG.md
          VERSION=$(grep -m 1 '^## \[' CHANGELOG.md | sed 's/^## \[\([^]]*\)\].*/\1/')
          
          # Validate version format (semver)
          if [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
            echo "Error: Invalid version format '$VERSION'. Expected semver format (e.g., 1.0.0)"
            exit 1
          fi
          
          echo "version=$VERSION" >> $GITHUB_OUTPUT
          echo "Extracted version: $VERSION"
          
      - name: Check if version tag exists
        id: tag-check
        run: |
          VERSION="${{ steps.version.outputs.version }}"
          if git rev-parse "v$VERSION" >/dev/null 2>&1; then
            echo "exists=true" >> $GITHUB_OUTPUT
            echo "Tag v$VERSION already exists"
          else
            echo "exists=false" >> $GITHUB_OUTPUT
            echo "Tag v$VERSION does not exist"
          fi
          
      - name: Check if version exists on crates.io
        id: crates-check
        run: |
          VERSION="${{ steps.version.outputs.version }}"
          # Check if version already exists on crates.io
          if curl -s "https://crates.io/api/v1/crates/fiasto" | grep -q "\"version\":\"$VERSION\""; then
            echo "exists=true" >> $GITHUB_OUTPUT
            echo "Version $VERSION already exists on crates.io"
          else
            echo "exists=false" >> $GITHUB_OUTPUT
            echo "Version $VERSION does not exist on crates.io"
          fi
          
      - name: Update Cargo.toml version
        if: steps.tag-check.outputs.exists == 'false'
        run: |
          VERSION="${{ steps.version.outputs.version }}"
          # Update Cargo.toml version to match changelog
          sed -i "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml
          echo "Updated Cargo.toml to version $VERSION"
          
      - name: Commit version update
        if: steps.tag-check.outputs.exists == 'false'
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git add Cargo.toml
          
          # Only commit if there are changes
          if git diff --staged --quiet; then
            echo "No changes to commit - Cargo.toml already at correct version"
          else
            git commit -m "Bump version to ${{ steps.version.outputs.version }}"
            git push origin main
          fi
          
      - name: Create git tag
        if: steps.tag-check.outputs.exists == 'false'
        run: |
          VERSION="${{ steps.version.outputs.version }}"
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git tag "v$VERSION"
          git push origin "v$VERSION"
          
      - name: Create GitHub release
        if: steps.tag-check.outputs.exists == 'false'
        run: |
          VERSION="${{ steps.version.outputs.version }}"
          
          # Extract changelog content for this version
          CHANGELOG_CONTENT=$(awk '/^## \['$VERSION'\]/{p=1;next}/^## \[/{p=0}p' CHANGELOG.md | sed '/^$/d' | sed 's/^### /#### /')
          
          # If no changelog content, use a default message
          if [ -z "$CHANGELOG_CONTENT" ]; then
            CHANGELOG_CONTENT="Release v$VERSION"
          fi
          
          # Create GitHub release using GitHub CLI
          gh release create "v$VERSION" \
            --title "Release v$VERSION" \
            --notes "$CHANGELOG_CONTENT"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          
      - name: Skip release if tag exists
        if: steps.tag-check.outputs.exists == 'true'
        run: |
          echo "Release v${{ steps.version.outputs.version }} already exists, skipping"
          
      - name: Skip release if version exists on crates.io
        if: steps.crates-check.outputs.exists == 'true'
        run: |
          echo "Version ${{ steps.version.outputs.version }} already exists on crates.io, skipping"
          
      - name: Setup Rust toolchain
        if: steps.crates-check.outputs.exists == 'false'
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
          
      - name: Cache dependencies
        if: steps.crates-check.outputs.exists == 'false'
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-
            
      - name: Build and test
        if: steps.crates-check.outputs.exists == 'false'
        run: |
          cargo build --release
          cargo test
          
      - name: Verify package
        if: steps.crates-check.outputs.exists == 'false'
        run: |
          echo "Verifying package contents..."
          cargo package --list --allow-dirty
          echo "Package verification complete"
          
      - name: Publish to crates.io
        if: steps.crates-check.outputs.exists == 'false'
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: |
          echo "Publishing version ${{ steps.version.outputs.version }} to crates.io"
          # Commit any changes to Cargo.lock that may have occurred during build
          if ! git diff --quiet Cargo.lock; then
            git config --local user.email "action@github.com"
            git config --local user.name "GitHub Action"
            git add Cargo.lock
            git commit -m "Update Cargo.lock for version ${{ steps.version.outputs.version }}"
            git push origin main
          fi
          cargo publish --token $CARGO_REGISTRY_TOKEN