minigraf 1.0.0

Zero-config, single-file, embedded graph database with bi-temporal Datalog queries
Documentation
name: WASM Release Artifacts

on:
  push:
    tags:
      - '**[0-9]+.[0-9]+.[0-9]+*'
  workflow_dispatch:
    inputs:
      tag:
        description: 'Release tag to upload artifacts to (e.g. v0.21.0)'
        required: true

permissions:
  contents: write

jobs:
  build-wasm-wasi:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-wasip1
      - name: Build WASI binary
        run: cargo build --target wasm32-wasip1 --release --bin minigraf
      - name: Stage artifact
        run: |
          mkdir -p target/wasm-artifacts
          cp target/wasm32-wasip1/release/minigraf.wasm target/wasm-artifacts/minigraf-wasi.wasm
      - uses: actions/upload-artifact@v6
        with:
          name: artifacts-wasm-wasi
          path: target/wasm-artifacts/

  build-wasm-browser:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-unknown-unknown
      - name: Install wasm-pack
        run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
      - name: Build browser WASM
        run: wasm-pack build --target web --features browser
      - name: Rename pkg/ → minigraf-wasm/
        run: mv pkg minigraf-wasm
      - name: Package minigraf-wasm/ directory
        run: |
          mkdir -p target/wasm-artifacts
          tar -czf target/wasm-artifacts/minigraf-browser-wasm.tar.gz -C . minigraf-wasm/
      - uses: actions/upload-artifact@v6
        with:
          name: artifacts-wasm-browser
          path: target/wasm-artifacts/

  release-upload-wasm:
    needs: [build-wasm-wasi, build-wasm-browser]
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/download-artifact@v7
        with:
          pattern: artifacts-wasm-*
          path: wasm-artifacts/
          merge-multiple: true
      - name: Wait for GitHub Release to exist, then upload
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TAG: ${{ inputs.tag || github.ref_name }}
        run: |
          echo "Waiting for release $TAG to be created by cargo-dist..."
          for i in $(seq 1 40); do
            if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
              echo "Release found on attempt $i"
              break
            fi
            echo "Attempt $i/40: release not yet available, waiting 15s..."
            sleep 15
          done
          if ! gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
            echo "ERROR: Release $TAG not found after 40 attempts (10 minutes). Aborting."
            exit 1
          fi
          gh release upload "$TAG" wasm-artifacts/* \
            --repo "$GITHUB_REPOSITORY" \
            --clobber

  publish-npm:
    name: Publish @minigraf/browser to npm
    needs: [build-wasm-browser]
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-unknown-unknown
      - name: Install wasm-pack
        run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          registry-url: 'https://registry.npmjs.org'
      - name: Build browser WASM
        run: wasm-pack build --target web --features browser
      - name: Rename pkg/ → minigraf-wasm/
        run: mv pkg minigraf-wasm
      - name: Stamp package name and version
        env:
          TAG: ${{ inputs.tag || github.ref_name }}
        run: |
          VERSION="${TAG#v}"
          # Only publish stable releases; pre-release tags (e.g. v1.0.0-rc.1) are rejected here intentionally.
          if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
            echo "ERROR: VERSION '$VERSION' does not look like a semver string. Aborting."
            exit 1
          fi
          export VERSION
          node -e "
            const fs = require('fs');
            const p = 'minigraf-wasm/package.json';
            const pkg = JSON.parse(fs.readFileSync(p, 'utf8'));
            pkg.name = '@minigraf/browser';
            pkg.version = process.env.VERSION;
            fs.writeFileSync(p, JSON.stringify(pkg, null, 2) + '\n');
          "
      - name: Publish to npm
        working-directory: minigraf-wasm
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: npm publish --access public

  publish-npm-wasi:
    name: Publish @minigraf/wasi to npm
    needs: [build-wasm-wasi]
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-wasip1
      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          registry-url: 'https://registry.npmjs.org'
      - name: Build WASI binary
        run: cargo build --target wasm32-wasip1 --release --bin minigraf
      - name: Stage WASI npm package
        run: cp target/wasm32-wasip1/release/minigraf.wasm minigraf-wasi/minigraf-wasi.wasm
      - name: Stamp package version
        env:
          TAG: ${{ inputs.tag || github.ref_name }}
        run: |
          VERSION="${TAG#v}"
          # Only publish stable releases; pre-release tags (e.g. v1.0.0-rc.1) are rejected here intentionally.
          if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
            echo "ERROR: VERSION '$VERSION' does not look like a semver string. Aborting."
            exit 1
          fi
          export VERSION
          node -e "
            const fs = require('fs');
            const p = 'minigraf-wasi/package.json';
            const pkg = JSON.parse(fs.readFileSync(p, 'utf8'));
            pkg.name = '@minigraf/wasi';
            pkg.version = process.env.VERSION;
            fs.writeFileSync(p, JSON.stringify(pkg, null, 2) + '\n');
          "
      - name: Test npm package
        working-directory: minigraf-wasi
        run: npm test
      - name: Publish to npm
        working-directory: minigraf-wasi
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: npm publish --access public