hawdb 0.41.0

An embedded Rust graph database for local data-plane workloads
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
name: Native Release

# Builds the HawDB C ABI for every prebuilt target, attaches the archives and
# SHA256SUMS to a published GitHub Release, and publishes the Bun package and
# its per-platform library packages to npm through trusted publishing (OIDC).
# scripts/native-release-mode.py maps a stable release (<x.y.z>) to the npm
# `latest` dist-tag and a prerelease (<x.y.z>-dev.<n> or -nightly.<n>) to `dev`
# or `nightly`, and refuses drafts, tag/version mismatches and any other
# combination.
# Pull requests that change this pipeline build and smoke-test every archive
# without uploading or publishing. See docs/PREBUILT_LIBRARIES.md.

on:
  release:
    types: [published]
  workflow_dispatch:
    inputs:
      tag:
        description: Existing release tag (v<x.y.z>, v<x.y.z>-dev.<n> or -nightly.<n>) to build, upload or retry
        required: true
        type: string
  pull_request:
    paths:
      - ".github/workflows/native-release.yml"
      - "scripts/package-ffi-release.py"
      - "scripts/package-ffi-release.test.py"
      - "scripts/native-release-mode.py"
      - "scripts/native-release-mode.test.py"
      - "scripts/npm/**"
      - "bindings/ffi/examples/**"
      - "bindings/bun/scripts/**"
      - "bindings/bun/src/platform.ts"

permissions:
  contents: read

concurrency:
  group: native-release-${{ github.event.release.tag_name || inputs.tag || github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
  USE_BAZEL_VERSION: "9.3.1"
  BUN_VERSION: "1.4.3"

jobs:
  source:
    name: Resolve released source
    # Every other job needs this one and a release or pull-request mode from it.
    runs-on: ubuntu-24.04
    outputs:
      version: ${{ steps.release.outputs.version }}
      tag: ${{ steps.release.outputs.tag }}
      sha: ${{ steps.release.outputs.sha }}
      epoch: ${{ steps.release.outputs.epoch }}
      mode: ${{ steps.release.outputs.mode }}
      npm_tag: ${{ steps.release.outputs.npm_tag }}
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
        with:
          ref: ${{ github.event_name == 'pull_request' && github.sha || format('refs/tags/{0}', github.event.release.tag_name || inputs.tag) }}
          fetch-depth: 0
          persist-credentials: false
      - name: Validate the release mode, tag and engine versions
        id: release
        env:
          RELEASE_TAG: ${{ github.event.release.tag_name || inputs.tag }}
          EVENT: ${{ github.event_name }}
          GH_TOKEN: ${{ github.token }}
        run: |
          set -euo pipefail
          version="$(python3 -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["package"]["version"])')"
          ffi="$(python3 -c 'import tomllib; print(tomllib.load(open("bindings/ffi/Cargo.toml", "rb"))["package"]["version"])')"
          bun="$(python3 -c 'import json; print(json.load(open("bindings/bun/package.json"))["version"])')"
          bazel_versions="$(grep -Eo 'version = "[^"]+"' bindings/ffi/BUILD.bazel | sort -u)"
          test "$ffi" = "$version" && test "$bun" = "$version"
          test "$bazel_versions" = "version = \"$version\""
          if [[ "$EVENT" == pull_request ]]; then
            python3 scripts/native-release-mode.py --event "$EVENT" --version "$version" > "$RUNNER_TEMP/mode"
          else
            gh release view "$RELEASE_TAG" -R "$GITHUB_REPOSITORY" --json tagName,isDraft,isPrerelease \
              > "$RUNNER_TEMP/release.json"
            # Refuses drafts, tag mismatches and a prerelease flag that disagrees with the version.
            python3 scripts/native-release-mode.py --event "$EVENT" --tag "$RELEASE_TAG" \
              --version "$version" --release "$RUNNER_TEMP/release.json" > "$RUNNER_TEMP/mode"
            git merge-base --is-ancestor HEAD origin/main
          fi
          {
            echo "version=$version"
            cat "$RUNNER_TEMP/mode"
            echo "sha=$(git rev-parse HEAD)"
            echo "epoch=$(git log -1 --format=%ct)"
          } | tee -a "$GITHUB_OUTPUT"

  build:
    name: C ABI (${{ matrix.target }})
    needs: source
    if: needs.source.outputs.mode == 'release' || needs.source.outputs.mode == 'pull-request'
    runs-on: ${{ matrix.os }}
    timeout-minutes: 150
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-24.04
            target: x86_64-unknown-linux-gnu
            npm: linux-x64-gnu
            arch: x86_64
          - os: ubuntu-24.04-arm
            target: aarch64-unknown-linux-gnu
            npm: linux-arm64-gnu
            arch: aarch64
          - os: macos-15
            target: aarch64-apple-darwin
            npm: darwin-arm64
            arch: arm64
          - os: macos-15-intel
            target: x86_64-apple-darwin
            npm: darwin-x64
            arch: x86_64
          - os: windows-2025
            target: x86_64-pc-windows-msvc
            npm: win32-x64-msvc
            arch: x86_64
    defaults:
      run:
        shell: bash
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
        with:
          ref: ${{ needs.source.outputs.sha }}
          persist-credentials: false
      - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7
        with:
          python-version: "3.12"
      - name: Check the runner architecture
        run: test "$(uname -m)" = "${{ matrix.arch }}"
      - name: Install Bazel
        if: runner.os != 'Windows'
        uses: bazel-contrib/setup-bazel@f34d6a05eae3c24acab7fa54587492daeaeffdab # 0.19.2
        with:
          bazelisk-cache: true
          disk-cache: ${{ github.workflow }}-${{ matrix.target }}
          repository-cache: true
          external-cache: true
      - name: Restore native Windows Bazel toolchain and caches
        id: windows-bazel
        if: runner.os == 'Windows'
        uses: ./.github/actions/windows-bazel
        with:
          cache-scope: native-release
      - name: Build the release-profile C ABI libraries
        id: build
        run: |
          set -euo pipefail
          files() { bazel cquery --config=prebuilt --output=files "$1" 2>/dev/null; }
          if [[ '${{ runner.os }}' == Windows ]]; then
            bazel build --config=prebuilt //bindings/ffi:hawdb_ffi
            shared="$(files //bindings/ffi:hawdb_ffi | grep -E '\.dll$')"
            import="$(files //bindings/ffi:hawdb_ffi | grep -E '\.dll\.lib$')"
            static=""
          else
            bazel build --config=prebuilt //bindings/ffi:hawdb_ffi //bindings/ffi:hawdb_ffi_static
            shared="$(files //bindings/ffi:hawdb_ffi | grep -E '\.(so|dylib)$')"
            static="$(files //bindings/ffi:hawdb_ffi_static | grep -E '\.a$')"
            import=""
          fi
          for file in "$shared" ${static:+"$static"} ${import:+"$import"}; do test -f "$file"; done
          {
            echo "shared=$shared"
            echo "static=$static"
            echo "import=$import"
          } | tee -a "$GITHUB_OUTPUT"
      - name: Package the archive and manifest
        id: package
        env:
          VERSION: ${{ needs.source.outputs.version }}
          SHA: ${{ needs.source.outputs.sha }}
          EPOCH: ${{ needs.source.outputs.epoch }}
          SHARED: ${{ steps.build.outputs.shared }}
          STATIC: ${{ steps.build.outputs.static }}
          IMPORT: ${{ steps.build.outputs.import }}
        run: |
          set -euo pipefail
          archive="$(python scripts/package-ffi-release.py --version "$VERSION" \
            --target '${{ matrix.target }}' --revision "$SHA" --runner '${{ matrix.os }}' \
            --shared "$SHARED" ${STATIC:+--static "$STATIC"} ${IMPORT:+--import-lib "$IMPORT"} \
            --source-date-epoch "$EPOCH" --out dist)"
          echo "archive=$archive" | tee -a "$GITHUB_OUTPUT"
      - name: Unpack the archive as a downstream host would
        id: unpack
        env:
          ARCHIVE: ${{ steps.package.outputs.archive }}
          VERSION: ${{ needs.source.outputs.version }}
        run: |
          set -euo pipefail
          mkdir -p "$RUNNER_TEMP/unpacked"
          python - "$ARCHIVE" "$RUNNER_TEMP/unpacked" <<'PY'
          import shutil, sys
          shutil.unpack_archive(sys.argv[1], sys.argv[2])
          PY
          root="$RUNNER_TEMP/unpacked/hawdb-ffi-$VERSION-${{ matrix.target }}"
          python - "$root" "$VERSION" <<'PY'
          import hashlib, json, sys
          from pathlib import Path
          root, version = Path(sys.argv[1]), sys.argv[2]
          manifest = json.loads((root / "manifest.json").read_text())
          assert manifest["version"] == version, manifest["version"]
          for name, entry in manifest["files"].items():
              assert hashlib.sha256((root / name).read_bytes()).hexdigest() == entry["sha256"], name
          print(json.dumps(manifest["requirements"], indent=2))
          PY
          case '${{ runner.os }}' in
            Windows) library="$root/bin/hawdb_ffi.dll" ;;
            macOS) library="$root/lib/libhawdb_ffi.dylib" ;;
            *) library="$root/lib/libhawdb_ffi.so" ;;
          esac
          test -f "$library"
          echo "root=$root" | tee -a "$GITHUB_OUTPUT"
          echo "library=$library" | tee -a "$GITHUB_OUTPUT"
      - name: Link the C example against the shared and static libraries
        if: runner.os != 'Windows'
        env:
          ROOT: ${{ steps.unpack.outputs.root }}
          VERSION: ${{ needs.source.outputs.version }}
        run: |
          set -euo pipefail
          # Link with exactly the flags the manifest documents for hosts.
          read -r -a system_libs < <(python -c 'import json, sys; print(" ".join(json.load(open(sys.argv[1]))["requirements"]["static_link_flags"]))' "$ROOT/manifest.json")
          cc -I "$ROOT/include" bindings/ffi/examples/embed.c -L "$ROOT/lib" -lhawdb_ffi \
            -Wl,-rpath,"$ROOT/lib" -o "$RUNNER_TEMP/embed-shared"
          cc -I "$ROOT/include" bindings/ffi/examples/embed.c "$ROOT/lib/libhawdb_ffi.a" \
            "${system_libs[@]}" -o "$RUNNER_TEMP/embed-static"
          for binary in embed-shared embed-static; do
            output="$("$RUNNER_TEMP/$binary")"
            echo "$output"
            grep -qx "hawdb $VERSION" <<<"$output"
            grep -q '"answer"' <<<"$output"
          done
      - name: Set up MSVC for the Windows link check
        if: runner.os == 'Windows'
        uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
      - name: Link the C example against the Windows import library
        if: runner.os == 'Windows'
        shell: pwsh
        env:
          ROOT: ${{ steps.unpack.outputs.root }}
          VERSION: ${{ needs.source.outputs.version }}
        run: |
          $ErrorActionPreference = 'Stop'
          $out = Join-Path $env:RUNNER_TEMP 'embed.exe'
          cl /nologo /I "$env:ROOT/include" bindings/ffi/examples/embed.c "$env:ROOT/lib/hawdb_ffi.dll.lib" /Fe:$out
          if ($LASTEXITCODE -ne 0) { throw 'link failed' }
          $env:PATH = "$env:ROOT/bin;$env:PATH"
          $output = & $out
          if ($LASTEXITCODE -ne 0) { throw 'embed.exe failed' }
          $output
          if ($output[0] -ne "hawdb $env:VERSION") { throw 'unexpected version' }
          if (-not ($output -match '"answer"')) { throw 'unexpected result' }
      - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
        with:
          bun-version: ${{ env.BUN_VERSION }}
      - name: Test the Bun binding and its npm packages against the archive
        working-directory: bindings/bun
        env:
          HAWDB_LIBRARY: ${{ steps.unpack.outputs.library }}
        run: |
          set -euo pipefail
          bun install --frozen-lockfile
          bun run typecheck
          bun test
      - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
        with:
          name: ffi-${{ matrix.target }}
          path: ${{ steps.package.outputs.archive }}
          if-no-files-found: error
      - name: Save updated Windows disk actions
        if: always() && runner.os == 'Windows' && steps.windows-bazel.outputs.disk-cache-key != '' && steps.windows-bazel.outputs.disk-cache-hit != 'true'
        uses: actions/cache/save@v6
        with:
          path: D:/hawdb-bazel-disk
          key: ${{ steps.windows-bazel.outputs.disk-cache-key }}

  assets:
    name: Release assets and checksums
    needs: [source, build]
    if: needs.source.outputs.mode == 'release' || needs.source.outputs.mode == 'pull-request'
    runs-on: ubuntu-24.04
    permissions:
      contents: write
    steps:
      - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
        with:
          pattern: ffi-*
          merge-multiple: true
          path: dist
      - name: Write SHA256SUMS for the complete archive set
        working-directory: dist
        env:
          VERSION: ${{ needs.source.outputs.version }}
        run: |
          set -euo pipefail
          expected=(
            "hawdb-ffi-$VERSION-aarch64-apple-darwin.tar.gz"
            "hawdb-ffi-$VERSION-x86_64-apple-darwin.tar.gz"
            "hawdb-ffi-$VERSION-x86_64-unknown-linux-gnu.tar.gz"
            "hawdb-ffi-$VERSION-aarch64-unknown-linux-gnu.tar.gz"
            "hawdb-ffi-$VERSION-x86_64-pc-windows-msvc.zip"
          )
          test "$(find . -maxdepth 1 -type f -printf '%f\n' | sort)" = "$(printf '%s\n' "${expected[@]}" | sort)"
          sha256sum -- * > "$RUNNER_TEMP/SHA256SUMS"
          mv "$RUNNER_TEMP/SHA256SUMS" SHA256SUMS
          cat SHA256SUMS
          sha256sum --check --strict SHA256SUMS
      - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
        with:
          name: ffi-release-assets
          path: dist
          if-no-files-found: error
      - name: Upload to the GitHub Release, refusing different existing bytes
        if: needs.source.outputs.mode == 'release'
        working-directory: dist
        env:
          GH_TOKEN: ${{ github.token }}
          TAG: ${{ needs.source.outputs.tag }}
        run: |
          set -euo pipefail
          existing="$(gh release view "$TAG" -R "$GITHUB_REPOSITORY" --json assets --jq '.assets[].name')"
          mkdir -p "$RUNNER_TEMP/existing"
          upload=()
          for file in *; do
            if grep -qx -- "$file" <<<"$existing"; then
              gh release download "$TAG" -R "$GITHUB_REPOSITORY" --pattern "$file" --dir "$RUNNER_TEMP/existing" --clobber
              if ! cmp -s "$file" "$RUNNER_TEMP/existing/$file"; then
                echo "::error::$file on $TAG differs from this build; delete it deliberately before retrying"
                exit 1
              fi
              echo "$file is already attached with identical bytes"
            else
              upload+=("$file")
            fi
          done
          if (( ${#upload[@]} > 0 )); then
            gh release upload "$TAG" -R "$GITHUB_REPOSITORY" "${upload[@]}"
          fi

  npm-not-configured:
    name: npm trusted publishing not enabled
    needs: [source, assets]
    if: needs.source.outputs.mode == 'release' && vars.NPM_TRUSTED_PUBLISHING != 'enabled'
    runs-on: ubuntu-24.04
    steps:
      - name: Explain the skipped npm publish
        run: |
          echo "::notice::npm publishing skipped: set the repository variable NPM_TRUSTED_PUBLISHING=enabled after configuring trusted publishers (docs/PREBUILT_LIBRARIES.md#npm-trusted-publishing), then rerun with workflow_dispatch."

  npm:
    name: Publish npm packages (trusted publishing)
    needs: [source, assets]
    if: needs.source.outputs.mode == 'release' && vars.NPM_TRUSTED_PUBLISHING == 'enabled'
    runs-on: ubuntu-24.04
    environment:
      name: npm
      url: https://www.npmjs.com/package/@nowledge/hawdb-bun
    permissions:
      contents: read
      id-token: write
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
        with:
          ref: ${{ needs.source.outputs.sha }}
          persist-credentials: false
      - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
        with:
          # No registry-url: a generated .npmrc token placeholder must not
          # shadow the OIDC exchange npm performs for trusted publishing.
          node-version: "24"
      - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
        with:
          bun-version: ${{ env.BUN_VERSION }}
      - name: Install the npm CLI required for trusted publishing
        run: |
          npm install --global npm@11.21.1
          npm --version
      - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
        with:
          name: ffi-release-assets
          path: dist
      - name: Assemble the npm packages from the released archives
        env:
          VERSION: ${{ needs.source.outputs.version }}
        run: |
          set -euo pipefail
          (cd dist && sha256sum --check --strict SHA256SUMS)
          mkdir -p "$RUNNER_TEMP/libraries"
          for archive in dist/hawdb-ffi-*; do
            python3 -c 'import shutil, sys; shutil.unpack_archive(sys.argv[1], sys.argv[2])' "$archive" "$RUNNER_TEMP/libraries"
          done
          libs="$RUNNER_TEMP/libraries"
          bun bindings/bun/scripts/assemble-npm.ts --version "$VERSION" --out "$RUNNER_TEMP/npm" \
            --library "darwin-arm64=$libs/hawdb-ffi-$VERSION-aarch64-apple-darwin/lib/libhawdb_ffi.dylib" \
            --library "darwin-x64=$libs/hawdb-ffi-$VERSION-x86_64-apple-darwin/lib/libhawdb_ffi.dylib" \
            --library "linux-x64-gnu=$libs/hawdb-ffi-$VERSION-x86_64-unknown-linux-gnu/lib/libhawdb_ffi.so" \
            --library "linux-arm64-gnu=$libs/hawdb-ffi-$VERSION-aarch64-unknown-linux-gnu/lib/libhawdb_ffi.so" \
            --library "win32-x64-msvc=$libs/hawdb-ffi-$VERSION-x86_64-pc-windows-msvc/bin/hawdb_ffi.dll" \
            > "$RUNNER_TEMP/npm-summary.json"
          cat "$RUNNER_TEMP/npm-summary.json"
      - name: Publish platform packages, then the main package
        env:
          # latest for a stable version, dev or nightly for a prerelease.
          NPM_TAG: ${{ needs.source.outputs.npm_tag }}
        run: |
          set -euo pipefail
          bash scripts/npm/publish-assembled.sh "$RUNNER_TEMP/npm-summary.json" --tag "$NPM_TAG" --publish --provenance
      - name: Install the public package and load HawDB without a path
        env:
          VERSION: ${{ needs.source.outputs.version }}
        run: |
          set -euo pipefail
          mkdir -p "$RUNNER_TEMP/consumer" && cd "$RUNNER_TEMP/consumer"
          echo '{"name":"consumer","private":true,"type":"module"}' > package.json
          for attempt in {1..6}; do
            if bun add "@nowledge/hawdb-bun@$VERSION"; then break; fi
            if [[ "$attempt" == 6 ]]; then exit 1; fi
            sleep 20
          done
          cat > check.ts <<'TS'
          import { loadHawDB } from "@nowledge/hawdb-bun";
          const hawdb = loadHawDB();
          const database = hawdb.openInMemory();
          console.log(hawdb.version(), JSON.stringify(database.query("UNWIND [42] AS answer RETURN answer").dicts()));
          database.close();
          hawdb.close();
          TS
          output="$(bun check.ts)"
          echo "$output"
          grep -q "^hawdb $VERSION " <<<"$output"