rulesxp 0.3.1

Multi-language rules expression evaluator supporting JSONLogic and Scheme with strict typing
Documentation
name: Release

on:
  push:
    tags:
      - 'v*.*.*'

env:
  CARGO_TERM_COLOR: always

permissions:
  contents: write

jobs:
  create-release:
    name: Create Release
    runs-on: ubuntu-latest
    # Only run in non-fork repositories (e.g., the canonical repo),
    # so tags in forks don't create upstream-style releases.
    if: github.event.repository.fork == false
    outputs:
      tag_name: ${{ steps.tag_name.outputs.TAG_NAME }}

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

    - name: Get tag name
      id: tag_name
      run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

    - name: Verify tag is on main
      run: |
        git fetch origin main
        if ! git merge-base --is-ancestor $GITHUB_SHA origin/main; then
          echo "Error: Tag must point to a commit on the main branch"
          exit 1
        fi

    - name: Verify version matches tag
      run: |
        TAG_VERSION=${GITHUB_REF#refs/tags/v}
        CARGO_VERSION=$(grep -m1 '^version = ' Cargo.toml | cut -d'"' -f2)
        if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
          echo "Error: Tag version (v$TAG_VERSION) doesn't match Cargo.toml version ($CARGO_VERSION)"
          exit 1
        fi
        echo "Version check passed: $CARGO_VERSION"

    - name: Create Release
      env:
        GH_TOKEN: ${{ github.token }}
      run: gh release create ${{ steps.tag_name.outputs.TAG_NAME }} --title "Release ${{ steps.tag_name.outputs.TAG_NAME }}" --generate-notes

  publish-crate:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    # crates.io publishing is only meaningful for non-fork roots
    if: github.event.repository.fork == false
    needs: create-release
    environment: crates-io
    permissions:
      id-token: write  # Required for OIDC trusted publishing

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

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

    - name: Cache dependencies
      uses: Swatinem/rust-cache@v2

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

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

  build-binaries:
    name: Build Release Binaries
    runs-on: ${{ matrix.os }}
    # Only build and upload release binaries for non-fork repositories
    if: github.event.repository.fork == false
    needs: create-release
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            archive_name: rulesxp-linux-x64.tar.gz
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            archive_name: rulesxp-windows-x64.zip
          - os: macos-latest
            target: aarch64-apple-darwin
            archive_name: rulesxp-macos-arm64.tar.gz

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

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

    - name: Cache dependencies
      uses: Swatinem/rust-cache@v2

    - name: Build repl binary
      run: cargo build --release --example repl --all-features --target ${{ matrix.target }}

    - name: Prepare binary for packaging
      run: |
        mkdir -p staging
        if [ "${{ matrix.os }}" = "windows-latest" ]; then
          cp "target/${{ matrix.target }}/release/examples/repl.exe" staging/
        else
          cp "target/${{ matrix.target }}/release/examples/repl" staging/
        fi
      shell: bash

    - name: Package binaries (Windows)
      if: matrix.os == 'windows-latest'
      shell: pwsh
      run: |
        Compress-Archive -Path staging/* -DestinationPath ${{ matrix.archive_name }}

    - name: Package binaries (Unix)
      if: matrix.os != 'windows-latest'
      run: |
        tar -czf ${{ matrix.archive_name }} -C staging .

    - name: Upload Release Asset
      env:
        GH_TOKEN: ${{ github.token }}
      run: gh release upload ${{ needs.create-release.outputs.tag_name }} ./${{ matrix.archive_name }}