8000 ci: consumer-test both npm packages, before tagging and after publishing by adityamukho · Pull Request #7 · project-minigraf/minigraf-wasm · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 47 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,62 @@ on:
required: false
type: string
default: ''
version:
description: 'Version stamped into the tarballs (release.yml passes the release version)'
required: false
type: string
default: '0.0.0-ci'

jobs:
build-browser:
name: Build browser WASM
runs-on: ubuntu-latest
# Builds both npm tarballs as the release publishes them.
package:
name: Package
uses: ./.github/workflows/package.yml
with:
ref: ${{ inputs.ref }}
core-ref: ${{ inputs.core-ref || 'main' }}
version: ${{ inputs.version || '0.0.0-ci' }}

# Installs each tarball into an empty project and runs its README quick start
# and the consumer contract: @minigraf/browser in headless Chromium,
# @minigraf/wasi under node:wasi on every OS.
consumer:
name: Consumer test (${{ matrix.package }}, ${{ matrix.os }})
needs: package
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { package: browser, os: ubuntu-latest }
- { package: wasi, os: ubuntu-latest }
- { package: wasi, os: macos-14 }
- { package: wasi, os: windows-latest }
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-node@v4
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
node-version: '20'
- uses: actions/download-artifact@v4
with:
name: dist-${{ matrix.package }}
path: dist-${{ matrix.package }}
- name: Run consumer test
shell: bash
env:
PLAYWRIGHT_DEPS: '1'
run: bash consumer-test/run.sh ${{ matrix.package }} local dist-${{ matrix.package }} ${{ inputs.version || '0.0.0-ci' }}

build-wasi:
name: Build WASI binary
readme-sync:
name: README quick starts match the consumer test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: project-minigraf/minigraf
ref: ${{ inputs.core-ref || 'main' }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip1
- name: Build WASI binary
run: cargo build --target wasm32-wasip1 --release --bin minigraf
ref: ${{ inputs.ref }}
- run: |
python3 -I consumer-test/readme_sync.py README.md consumer-test/browser/quickstart.js '## Browser (`@minigraf/browser`)'
python3 -I consumer-test/readme_sync.py README.md consumer-test/wasi/repl.mjs '## WASI (`@minigraf/wasi`)'
python3 -I consumer-test/readme_sync.py wasi-pkg/README.md consumer-test/wasi/repl.mjs
135 changes: 135 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Package

# Builds the two npm tarballs exactly as the release publishes them, stamped
# with `version`: dist-browser (@minigraf/browser, wasm-pack) and dist-wasi
# (@minigraf/wasi, the core REPL built for wasm32-wasip1 at `core-ref`).

on:
workflow_call:
inputs:
ref:
required: false
type: string
default: ''
core-ref:
required: true
type: string
version:
required: true
type: string

jobs:
browser:
name: Package @minigraf/browser
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- 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
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Build browser WASM
run: wasm-pack build --target web --features browser
- name: Stamp package name, version and description; add the licenses
env:
VERSION: ${{ inputs.version }}
run: |
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "ERROR: VERSION '$VERSION' is not semver. Aborting."
exit 1
fi
cp LICENSE-MIT LICENSE-APACHE pkg/
node -e "
const fs = require('fs');
const p = 'pkg/package.json';
const pkg = JSON.parse(fs.readFileSync(p, 'utf8'));
pkg.name = '@minigraf/browser';
pkg.version = process.env.VERSION;
pkg.description = 'Minigraf for the browser: a bi-temporal graph database with Datalog queries, persisted in IndexedDB';
pkg.files.push('LICENSE-MIT', 'LICENSE-APACHE');
fs.writeFileSync(p, JSON.stringify(pkg, null, 2) + '\n');
"
- name: Pack and check the tarball
env:
VERSION: ${{ inputs.version }}
run: |
mkdir dist
(cd pkg && npm pack --pack-destination ../dist)
TGZ="dist/minigraf-browser-$VERSION.tgz"
tar tzf "$TGZ" | sort | tee files.txt
for f in package.json README.md LICENSE-MIT LICENSE-APACHE \
minigraf_wasm.js minigraf_wasm.d.ts minigraf_wasm_bg.wasm; do
grep -qx "package/$f" files.txt || { echo "::error::$TGZ has no $f"; exit 1; }
done
- uses: actions/upload-artifact@v4
with:
name: dist-browser
path: dist/*.tgz
if-no-files-found: error

wasi:
name: Package @minigraf/wasi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: project-minigraf/minigraf
ref: ${{ inputs.core-ref }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip1
- name: Build WASI binary
run: cargo build --target wasm32-wasip1 --release --bin minigraf
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Check out wasm binding repo for wasi-pkg
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
path: wasm-binding
- name: Stage the WASI binary and the licenses
run: |
cp target/wasm32-wasip1/release/minigraf.wasm wasm-binding/wasi-pkg/minigraf-wasi.wasm
cp wasm-binding/LICENSE-MIT wasm-binding/LICENSE-APACHE wasm-binding/wasi-pkg/
- name: Stamp package version
env:
VERSION: ${{ inputs.version }}
run: |
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "ERROR: VERSION '$VERSION' is not semver. Aborting."
exit 1
fi
node -e "
const fs = require('fs');
const p = 'wasm-binding/wasi-pkg/package.json';
const pkg = JSON.parse(fs.readFileSync(p, 'utf8'));
pkg.version = process.env.VERSION;
fs.writeFileSync(p, JSON.stringify(pkg, null, 2) + '\n');
"
- name: Test WASI package
working-directory: wasm-binding/wasi-pkg
run: npm test
- name: Pack and check the tarball
env:
VERSION: ${{ inputs.version }}
run: |
mkdir dist
(cd wasm-binding/wasi-pkg && npm pack --pack-destination "$GITHUB_WORKSPACE/dist")
TGZ="dist/minigraf-wasi-$VERSION.tgz"
tar tzf "$TGZ" | sort | tee files.txt
for f in package.json README.md LICENSE-MIT LICENSE-APACHE \
index.js index.d.ts minigraf-wasi.wasm; do
grep -qx "package/$f" files.txt || { echo "::error::$TGZ has no $f"; exit 1; }
done
- uses: actions/upload-artifact@v4
with:
name: dist-wasi
path: dist/*.tgz
if-no-files-found: error
121 changes: 40 additions & 81 deletions .github/workflows/release.yml
8
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ jobs:
with:
ref: ${{ needs.prepare.outputs.sha }}
core-ref: v${{ needs.prepare.outputs.semver }}
# The tarballs are built and consumer-tested here at the release
# version; publish uploads exactly these files.
version: ${{ needs.prepare.outputs.semver }}

tag:
name: Push tag and update main
Expand Down Expand Up @@ -115,103 +118,59 @@ jobs:
git push origin --delete "release/$TAG" \
|| echo "::warning::Could not delete branch release/$TAG"

publish-browser:
name: Build and publish @minigraf/browser
needs: [prepare, tag]
publish:
name: Publish @minigraf/${{ matrix.package }}
needs: [prepare, test, tag]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
package: [browser, wasi]
environment:
name: npm
url: https://www.npmjs.com/package/@minigraf/browser
url: https://www.npmjs.com/package/@minigraf/${{ matrix.package }}
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.tag }}
- 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@v6
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
- name: Build browser WASM
run: wasm-pack build --target web --features browser
- name: Stamp package name and version

- uses: actions/download-artifact@v4
with:
name: dist-${{ matrix.package }}
path: dist

# Re-runs are expected (e.g. after a partial failure), so a version that is
# already on npm is skipped, not treated as an error. Any other npm failure
# fails the job.
- name: Publish the tested tarball
env:
PACKAGE: ${{ matrix.package }}
VERSION: ${{ needs.prepare.outputs.semver }}
run: |
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "ERROR: VERSION '$VERSION' is not semver. Aborting."
exit 1
TGZ="dist/minigraf-$PACKAGE-$VERSION.tgz"
[ -f "$TGZ" ] || { echo "::error::no $TGZ"; ls dist; exit 1; }
if [ "$(npm view "@minigraf/$PACKAGE@$VERSION" version 2>/dev/null)" = "$VERSION" ]; then
echo "::warning::@minigraf/$PACKAGE@$VERSION is already on npm; skipping"
echo "- \`@minigraf/$PACKAGE@$VERSION\` — already published, skipped" >> "$GITHUB_STEP_SUMMARY"
else
npm publish "$TGZ" --access public
echo "- \`@minigraf/$PACKAGE@$VERSION\` — published" >> "$GITHUB_STEP_SUMMARY"
fi
node -e "
const fs = require('fs');
const p = 'pkg/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 @minigraf/browser to npm
working-directory: pkg
run: npm publish --access public

publish-wasi:
name: Build and publish @minigraf/wasi
needs: [prepare, tag]
runs-on: ubuntu-latest
environment:
name: npm
url: https://www.npmjs.com/package/@minigraf/wasi
# Installs the published version from npm and runs the consumer test; on
# failure the run fails and a release-broken issue is opened.
verify-published:
name: Verify the published packages
needs: [prepare, publish]
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
with:
repository: project-minigraf/minigraf
ref: v${{ needs.prepare.outputs.semver }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip1
- name: Build WASI binary
run: cargo build --target wasm32-wasip1 --release --bin minigraf
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
- name: Check out wasm binding repo for wasi-pkg
uses: actions/checkout@v4
with:
repository: project-minigraf/minigraf-wasm
ref: ${{ needs.prepare.outputs.tag }}
path: wasm-binding
- name: Stage WASI wasm binary
run: cp target/wasm32-wasip1/release/minigraf.wasm wasm-binding/wasi-pkg/minigraf-wasi.wasm
- name: Stamp package version
env:
VERSION: ${{ needs.prepare.outputs.semver }}
run: |
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "ERROR: VERSION '$VERSION' is not semver. Aborting."
exit 1
fi
node -e "
const fs = require('fs');
const p = 'wasm-binding/wasi-pkg/package.json';
const pkg = JSON.parse(fs.readFileSync(p, 'utf8'));
pkg.version = process.env.VERSION;
fs.writeFileSync(p, JSON.stringify(pkg, null, 2) + '\n');
"
- name: Test WASI package
working-directory: wasm-binding/wasi-pkg
run: npm test
- name: Publish @minigraf/wasi to npm
working-directory: wasm-binding/wasi-pkg
run: npm publish --access public
issues: write
uses: ./.github/workflows/verify-published.yml
with:
version: ${{ needs.prepare.outputs.semver }}
ref: ${{ needs.prepare.outputs.tag }}
Loading
Loading
0