ilo 0.10.1

ilo — a programming language for AI agents
Documentation
name: Release

on:
  push:
    tags: ["v*"]

permissions:
  contents: write

jobs:
  build:
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            cross: true
          - target: x86_64-apple-darwin
            os: macos-latest
          - target: aarch64-apple-darwin
            os: macos-latest
          - target: x86_64-pc-windows-msvc
            os: windows-latest

    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout: |
            src
            build.rs
            SPEC.md
            Cargo.toml
            Cargo.lock

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

      - name: Install cross
        if: matrix.cross
        run: cargo install cross --git https://github.com/cross-rs/cross

      - name: Build
        run: |
          if [ "${{ matrix.cross }}" = "true" ]; then
            cross build --release --target ${{ matrix.target }}
          else
            cargo build --release --target ${{ matrix.target }}
          fi
        shell: bash

      - name: Rename binary (unix)
        if: runner.os != 'Windows'
        run: mv target/${{ matrix.target }}/release/ilo ilo-${{ matrix.target }}

      - name: Rename binary (windows)
        if: runner.os == 'Windows'
        run: mv target/${{ matrix.target }}/release/ilo.exe ilo-${{ matrix.target }}.exe
        shell: bash

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ilo-${{ matrix.target }}
          path: ilo-${{ matrix.target }}*

  build-wasm:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout: |
            src
            build.rs
            SPEC.md
            Cargo.toml
            Cargo.lock

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-wasip1

      - name: Build WASM
        run: cargo build --release --target wasm32-wasip1 --no-default-features

      - name: Upload WASM artifact
        uses: actions/upload-artifact@v4
        with:
          name: ilo-wasm
          path: target/wasm32-wasip1/release/ilo.wasm

  release:
    needs: [build, build-wasm]
    runs-on: ubuntu-latest

    steps:
      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          merge-multiple: true

      - name: Generate checksums
        run: sha256sum ilo-* > checksums-sha256.txt

      - name: Create release
        uses: softprops/action-gh-release@v2
        with:
          generate_release_notes: true
          files: |
            ilo-*
            checksums-sha256.txt

  publish-crates:
    needs: [release]
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

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

      - name: Publish to crates.io
        run: |
          output=$(cargo publish 2>&1) && echo "$output" || {
            echo "$output"
            echo "$output" | grep -q "already exists" || exit 1
          }
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  publish-npm:
    needs: [build-wasm]
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout: |
            npm
            README.md

      - name: Copy README to npm package
        run: cp README.md npm/README.md

      - name: Download WASM artifact
        uses: actions/download-artifact@v4
        with:
          name: ilo-wasm
          path: npm/

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "20"
          registry-url: "https://registry.npmjs.org"

      - name: Set npm version from tag
        working-directory: npm
        run: npm version ${GITHUB_REF_NAME#v} --no-git-tag-version

      - name: Publish to npm
        working-directory: npm
        run: |
          output=$(npm publish --access public 2>&1) && echo "$output" || {
            echo "$output"
            echo "$output" | grep -q "previously published" || exit 1
          }
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}