Skip to content

Fix CI for working package artifacts #6

Fix CI for working package artifacts

Fix CI for working package artifacts #6

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version_suffix:
description: 'Optional prerelease suffix such as -dev.1 or -beta.0'
required: false
type: string
default: ''
dry_run:
description: 'Build and package without publishing'
required: false
type: boolean
default: false
env:
EMSDK_VERSION: '4.0.22'
NODE_VERSION: '22'
WASM_PACK_VERSION: '0.14.0'
BINARYEN_VERSION: 'version_125'
BINARYEN_ARCHIVE: 'binaryen-version_125-x86_64-linux.tar.gz'
BINARYEN_SHA256: '7c3bc16599c8274a04d34a504fe4be2047884f900e0e2da2f6fb9cd667183be4'
jobs:
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
npm_tag: ${{ steps.version.outputs.npm_tag }}
dry_run: ${{ steps.version.outputs.dry_run }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
submodules: recursive
- name: Determine version
id: version
run: |
BASE_VERSION="$(python3 -c 'import pathlib,tomllib; cargo = tomllib.loads(pathlib.Path("Cargo.toml").read_text()); print(cargo["workspace"]["package"]["version"])')"
if [ "${{ github.event_name }}" = "push" ]; then
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
if [ "$TAG_VERSION" != "$BASE_VERSION" ]; then
echo "::error::Tag version ($TAG_VERSION) does not match Cargo workspace version ($BASE_VERSION)"
exit 1
fi
VERSION="$TAG_VERSION"
else
VERSION="${BASE_VERSION}${{ github.event.inputs.version_suffix }}"
fi
if [[ "$VERSION" == *"-dev"* ]] || [[ "$VERSION" == *"-alpha"* ]] || [[ "$VERSION" == *"-beta"* ]] || [[ "$VERSION" == *"-rc"* ]]; then
NPM_TAG="dev"
else
NPM_TAG="latest"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "npm_tag=$NPM_TAG" >> "$GITHUB_OUTPUT"
echo "dry_run=${{ github.event.inputs.dry_run || 'false' }}" >> "$GITHUB_OUTPUT"
build-wasm:
runs-on: ubuntu-latest
needs: version
timeout-minutes: 180
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
submodules: recursive
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@1.94.0
with:
targets: wasm32-unknown-unknown
- name: Setup Emscripten SDK
uses: mymindstorm/setup-emsdk@v16
with:
version: ${{ env.EMSDK_VERSION }}
actions-cache-folder: emsdk-cache
- name: Verify toolchain
run: emcc -v
- name: Install pinned Binaryen
run: |
mkdir -p "$RUNNER_TEMP/binaryen"
curl -L --fail --silent --show-error \
"https://github.com/WebAssembly/binaryen/releases/download/${{ env.BINARYEN_VERSION }}/${{ env.BINARYEN_ARCHIVE }}" \
-o "$RUNNER_TEMP/${{ env.BINARYEN_ARCHIVE }}"
echo "${{ env.BINARYEN_SHA256 }} $RUNNER_TEMP/${{ env.BINARYEN_ARCHIVE }}" | sha256sum -c -
tar -xzf "$RUNNER_TEMP/${{ env.BINARYEN_ARCHIVE }}" -C "$RUNNER_TEMP/binaryen" --strip-components=1
echo "$RUNNER_TEMP/binaryen/bin" >> "$GITHUB_PATH"
"$RUNNER_TEMP/binaryen/bin/wasm-opt" --version
- name: Install pinned wasm-pack
run: cargo install wasm-pack --locked --version ${{ env.WASM_PACK_VERSION }}
- name: Checkout vcpkg for S2-enabled builds
run: git clone --depth 1 https://github.com/microsoft/vcpkg.git deps/vcpkg
- name: Build browser packages
run: |
VCPKG_ROOT="$GITHUB_WORKSPACE/deps/vcpkg" make build-minimal
VCPKG_ROOT="$GITHUB_WORKSPACE/deps/vcpkg" make build-standard
VCPKG_ROOT="$GITHUB_WORKSPACE/deps/vcpkg" make build-global
VCPKG_ROOT="$GITHUB_WORKSPACE/deps/vcpkg" make build-full
- name: Upload WASM artifacts
uses: actions/upload-artifact@v7
with:
name: wasm-artifacts
path: |
dist/minimal
dist/standard
dist/global
dist/full
if-no-files-found: error
publish:
runs-on: ubuntu-latest
needs: [version, build-wasm]
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
package: [minimal, standard, global, full]
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
submodules: recursive
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
cache-dependency-path: js/package-lock.json
registry-url: https://registry.npmjs.org
- name: Download WASM artifacts
uses: actions/download-artifact@v8
with:
name: wasm-artifacts
path: dist
- name: Recreate pkg symlink for selected package
run: ln -sfn dist/${{ matrix.package }} pkg
- name: Install JS dependencies
run: cd js && npm ci
- name: Build shared TypeScript wrapper
run: cd js && npm exec tsc
- name: Run Vitest for ${{ matrix.package }}
run: cd js && npm run test:${{ matrix.package }}
- name: Sync package versions
run: node scripts/sync-package-versions.mjs --version "${{ needs.version.outputs.version }}"
- name: Build npm package shell
run: node scripts/build-npm-package.mjs ${{ matrix.package }}
- name: Smoke-test packed npm artifact
run: node scripts/smoke-packed-package.mjs ${{ matrix.package }}
- name: Publish @cereusdb/${{ matrix.package }}
if: ${{ needs.version.outputs.dry_run != 'true' }}
run: cd packages/${{ matrix.package }} && npm publish --access public --tag "${{ needs.version.outputs.npm_tag }}"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
deploy-docs:
runs-on: ubuntu-latest
needs: [version, build-wasm]
if: ${{ github.event_name == 'push' && needs.version.outputs.dry_run != 'true' }}
permissions:
contents: read
deployments: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
cache-dependency-path: |
js/package-lock.json
packages/documentation/package-lock.json
- name: Download WASM artifacts
uses: actions/download-artifact@v4
with:
name: wasm-artifacts
path: dist
- name: Recreate pkg symlink for documentation build
run: ln -sfn dist/full pkg
- name: Install JS dependencies
run: cd js && npm ci
- name: Build shared TypeScript declarations
run: cd js && npm exec tsc
- name: Install documentation dependencies
run: cd packages/documentation && npm ci
- name: Build documentation site
run: cd packages/documentation && npm run build:release
- name: Validate Cloudflare credentials
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
test -n "$CLOUDFLARE_API_TOKEN" || { echo "Missing CLOUDFLARE_API_TOKEN"; exit 1; }
test -n "$CLOUDFLARE_ACCOUNT_ID" || { echo "Missing CLOUDFLARE_ACCOUNT_ID"; exit 1; }
- name: Deploy to Cloudflare Pages
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: packages/documentation
command: pages deploy dist --project-name cereusdb-api --branch main
deploy-playground:
runs-on: ubuntu-latest
needs: [version, build-wasm]
if: ${{ startsWith(github.ref, 'refs/tags/v') && needs.version.outputs.dry_run != 'true' }}
permissions:
contents: read
deployments: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
cache-dependency-path: |
js/package-lock.json
packages/playground/package-lock.json
- name: Download WASM artifacts
uses: actions/download-artifact@v4
with:
name: wasm-artifacts
path: dist
- name: Recreate pkg symlink for playground build
run: ln -sfn dist/minimal pkg
- name: Install JS dependencies
run: cd js && npm ci
- name: Build shared TypeScript declarations
run: cd js && npm exec tsc
- name: Build minimal package shell
run: node scripts/build-npm-package.mjs minimal
- name: Install playground dependencies
run: cd packages/playground && npm ci
- name: Build playground site
run: cd packages/playground && npm run build:release
- name: Validate Cloudflare credentials
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
test -n "$CLOUDFLARE_API_TOKEN" || { echo "Missing CLOUDFLARE_API_TOKEN"; exit 1; }
test -n "$CLOUDFLARE_ACCOUNT_ID" || { echo "Missing CLOUDFLARE_ACCOUNT_ID"; exit 1; }
- name: Deploy to Cloudflare Pages
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: packages/playground
command: pages deploy dist --project-name cereusdb-playground --branch main
release:
runs-on: ubuntu-latest
needs: [version, publish, deploy-docs, deploy-playground]
if: ${{ github.event_name == 'push' && needs.version.outputs.dry_run != 'true' }}
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Download WASM artifacts
uses: actions/download-artifact@v4
with:
name: wasm-artifacts
path: dist
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
files: |
dist/minimal/cereusdb_bg.wasm
dist/standard/cereusdb_bg.wasm
dist/global/cereusdb_bg.wasm
dist/full/cereusdb_bg.wasm
prerelease: ${{ needs.version.outputs.npm_tag == 'dev' }}
generate_release_notes: true
body: |
## CereusDB v${{ needs.version.outputs.version }}
### npm packages
- `@cereusdb/minimal`
- `@cereusdb/standard`
- `@cereusdb/global`
- `@cereusdb/full`
### Installation
```bash
npm install @cereusdb/minimal@${{ needs.version.outputs.version }}
npm install @cereusdb/standard@${{ needs.version.outputs.version }}
npm install @cereusdb/global@${{ needs.version.outputs.version }}
npm install @cereusdb/full@${{ needs.version.outputs.version }}
```