# Build the native dust-sync sidecar for every target, then publish the five # per-platform packages, the eight @kuiralabs workspace packages mn depends on, # and mn itself, so an `npm install midnight-wallet-cli` gets the native Dust # reader (a cold read of mainnet's Dust events in 86 s on a laptop, several times # faster than the WASM reader). # # Trigger: push a `v*` tag (after bumping the versions). Or run manually with # dry_run to build without publishing. # # Each package goes to the dist-tag of its own version: a prerelease version (a # `-` in it, e.g. 0.6.0-rc.0) under `next`, so it never becomes `latest`, and a # stable one under `latest`. The platform packages (@kuiralabs/dust-sync--) # and the workspace packages carry their own version (0.1.0), not mn's; one # already on npm is not published again. Nothing is published before the # typecheck and the full test suite pass. # # Auth: OIDC trusted publishing (no long-lived secret) once each package has a # trusted publisher configured on npmjs.com (repo kuiralabs/midnight-cli, # this workflow file). Until then — including the very first publish, since a # trusted publisher can only be attached to a package that already exists — npm # falls back to the `NPM_TOKEN` repo secret (a classic Automation token). After # the first release + configuring trusted publishers, that secret can be deleted. name: release on: push: tags: ['v*'] workflow_dispatch: inputs: dry_run: description: 'Build the binaries but do not publish' type: boolean default: true jobs: build-sidecar: name: build ${{ matrix.pkg }} runs-on: ${{ matrix.os }} strategy: fail-fast: false # every platform reports its own result; publish needs them all matrix: include: # `native`: the runner can run what it builds (tests and the ledger check run there). - { os: macos-15, target: aarch64-apple-darwin, pkg: darwin-arm64, ext: '', native: true } # darwin-x64 cross-compiled on the Apple-Silicon runner (macOS ships the # x86_64 SDK). Avoids the scarce/deprecated macos-13 Intel runner, which # queues indefinitely; macos-15 has plentiful capacity. - { os: macos-15, target: x86_64-apple-darwin, pkg: darwin-x64, ext: '', native: false } - { os: ubuntu-latest, target: x86_64-unknown-linux-gnu, pkg: linux-x64, ext: '', native: true } - { os: ubuntu-24.04-arm, target: aarch64-unknown-linux-gnu, pkg: linux-arm64, ext: '', native: true } - { os: windows-latest, target: x86_64-pc-windows-msvc, pkg: win32-x64, ext: '.exe', native: true } steps: - uses: actions/checkout@v4 - name: Install Rust uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.target }} # The ledger-9 crates link rustls on aws-lc-rs, whose aws-lc-sys compiles # AWS-LC from C (pregenerated bindings exist for all five targets, so no # bindgen or clang; cmake, preinstalled on these runners, is only its # fallback). On Windows x86-64 its assembly needs NASM, which the runner # lacks: use the NASM objects aws-lc-sys ships instead. - name: Use aws-lc-sys's prebuilt NASM objects if: runner.os == 'Windows' shell: bash run: echo "AWS_LC_SYS_PREBUILT_NASM=1" >> "$GITHUB_ENV" - name: Cache cargo uses: Swatinem/rust-cache@v2 with: workspaces: sidecar/dust-sync # --locked keeps the ledger crate pins (midnight-ledger-v9 =1.0.0 etc.) so # the serialized DustLocalState round-trips byte-identically with the # engine's @midnightntwrk/ledger-v9. - name: Build sidecar working-directory: sidecar/dust-sync run: cargo build --release --locked --target ${{ matrix.target }} - name: Test sidecar if: matrix.native working-directory: sidecar/dust-sync run: cargo test --release --locked --target ${{ matrix.target }} - name: Sanity-check it's the right arch if: runner.os != 'Windows' run: file "sidecar/dust-sync/target/${{ matrix.target }}/release/dust-sync${{ matrix.ext }}" # mn runs only a sidecar that reports its own ledger as ledger 9. - name: Check it folds ledger 9 if: matrix.native shell: bash run: | set -euo pipefail ledger="$("sidecar/dust-sync/target/${{ matrix.target }}/release/dust-sync${{ matrix.ext }}" --ledger)" [ "$ledger" = "9" ] || { echo "::error::dust-sync --ledger printed '$ledger', not 9"; exit 1; } - name: Upload binary artifact uses: actions/upload-artifact@v4 with: name: dust-sync-${{ matrix.pkg }} path: sidecar/dust-sync/target/${{ matrix.target }}/release/dust-sync${{ matrix.ext }} if-no-files-found: error retention-days: 1 publish: name: publish to npm needs: build-sidecar # Only publish for a real tag push (never for a manual dry run), and only # with every platform's binary built. if: >- ${{ !cancelled() && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && needs.build-sidecar.result == 'success' }} runs-on: ubuntu-latest permissions: contents: read id-token: write # mint the OIDC token npm uses for trusted publishing steps: - uses: actions/checkout@v4 # Stop before anything is published if the tag and package.json disagree # (stable and prerelease alike): v0.6.0-rc.0 must ship version 0.6.0-rc.0. - name: Check the tag matches package.json version shell: bash env: TAG: ${{ github.ref_name }} run: | set -euo pipefail tag_version="${TAG#v}" pkg_version="$(node -p "require('./package.json').version")" if [ "$tag_version" != "$pkg_version" ]; then echo "::error::tag $TAG does not match package.json version $pkg_version" exit 1 fi echo "tag $TAG matches package.json version $pkg_version" - uses: actions/setup-node@v4 with: node-version: 22 registry-url: 'https://registry.npmjs.org' - uses: oven-sh/setup-bun@v2 with: bun-version-file: .bun-version # OIDC trusted publishing needs npm >= 11.5.1; Node 22 ships npm 10.x. Held at npm 11: npm 12 neither packs # nor reads npm-shrinkwrap.json, which the engine and grant ship (and mn's own). - name: Upgrade npm for OIDC trusted publishing run: npm install -g npm@11 - run: npm ci # Nothing is published unless the tree being published typechecks and passes the full test suite. - name: Typecheck run: npm run typecheck - run: npm run build - name: Tests run: npm test - name: Download all platform binaries uses: actions/download-artifact@v4 with: path: /tmp/dust-sync-artifacts # mn pins each platform package exactly, so a version that is not on npm # yet must be published now, with its binary; one already there stays. - name: Stage each binary into its platform package shell: bash run: | set -euo pipefail for pkg in darwin-arm64 darwin-x64 linux-x64 linux-arm64 win32-x64; do ext=""; [ "$pkg" = "win32-x64" ] && ext=".exe" src="/tmp/dust-sync-artifacts/dust-sync-$pkg/dust-sync$ext" dest="packages/dust-sync-$pkg/dust-sync$ext" name="$(node -p "require('./packages/dust-sync-$pkg/package.json').name")" version="$(node -p "require('./packages/dust-sync-$pkg/package.json').version")" if npm view "$name@$version" version >/dev/null 2>&1; then echo "$name@$version is published already" elif [ -f "$src" ]; then cp "$src" "$dest"; chmod +x "$dest" || true echo "staged $pkg" else echo "::error::no binary for $pkg, and $name@$version is not on npm: mn would pin a package that does not exist" exit 1 fi done - name: Pin mn's optional dependencies to the platform packages run: node scripts/sync-sidecar-versions.mjs # Platform packages MUST publish before the main package, so the main # package's optionalDependencies resolve. Only staged ones publish (a # version on npm already has no binary staged). - name: Publish platform packages shell: bash env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: | set -euo pipefail for pkg in darwin-arm64 darwin-x64 linux-x64 linux-arm64 win32-x64; do ext=""; [ "$pkg" = "win32-x64" ] && ext=".exe" if [ -f "packages/dust-sync-$pkg/dust-sync$ext" ]; then version="$(node -p "require('./packages/dust-sync-$pkg/package.json').version")" tag=""; case "$version" in *-*) tag="--tag next" ;; esac ( cd "packages/dust-sync-$pkg" && npm publish --access public $tag ) else echo "skipping $pkg: published already" fi done # mn depends on its workspace packages (core, chain, the engine, # wallet, connect, contract, dev, grant) at exact versions: each publishes first, unless that version is # on npm already, under its own version's dist-tag, in dependency order (a package after those it declares). - name: Publish the workspace packages mn depends on env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} shell: bash run: | set -euo pipefail for dir in packages/cli-core packages/chain packages/engine-rc packages/wallet packages/connect packages/contract packages/dev packages/grant; do name="$(node -p "require('./$dir/package.json').name")" version="$(node -p "require('./$dir/package.json').version")" if npm view "$name@$version" version >/dev/null 2>&1; then echo "$name@$version is published already" else # The engine ships the SDK set the tests ran on, for a program that installs it without mn; so does # grant, whose account chain is built on that set. case "$name" in @kuiralabs/midnight-engine-*|@kuiralabs/midnight-grant) node scripts/make-shrinkwrap.mjs --package "$dir" ;; esac # Packed with the manifest it is published with: no exports entry names a source file. tarball="$(node scripts/publish-manifest.mjs "$dir" "$RUNNER_TEMP/workspace-packs")" tag=""; case "$version" in *-*) tag="--tag next" ;; esac npm publish "$tarball" --access public $tag # The shrinkwrap step reads each package's dist from the registry; a version just published can take # a minute or two to be served (0.7.0-rc.0's first run failed on a 404 one second after publishing). for attempt in $(seq 1 20); do if npm view "$name@$version" dist.integrity --prefer-online >/dev/null 2>&1; then break; fi if [ "$attempt" = 20 ]; then echo "::error::$name@$version is not served by npm 10 minutes after publishing"; exit 1; fi sleep 30 done fi done # The tree the tests ran on, shipped with mn so a user's npm installs it # (one copy of each WASM package). Written only here, never committed. - name: Write the shrinkwrap mn ships run: node scripts/make-shrinkwrap.mjs - name: Publish main package env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} shell: bash run: | set -euo pipefail version="$(node -p "require('./package.json').version")" tag=""; case "$version" in *-*) tag="--tag next" ;; esac npm publish --access public $tag # A user's install, from npm: mn runs, and finds a native Dust reader that # folds ledger 9. 0.6.0 shipped without one, its shrinkwrap listing the # platform packages but not installing them. A version just published can # take a minute or two to be served, so the install is retried. - name: Check a clean install from npm finds the native Dust reader shell: bash working-directory: ${{ runner.temp }} run: | set -euo pipefail version="$(node -p "require('$GITHUB_WORKSPACE/package.json').version")" prefix="$RUNNER_TEMP/clean-install" for attempt in $(seq 1 10); do if npm install -g --prefix "$prefix" --prefer-online "midnight-wallet-cli@$version"; then break; fi if [ "$attempt" = 10 ]; then echo "::error::midnight-wallet-cli@$version did not install from npm"; exit 1; fi sleep 30 done installed="$("$prefix/bin/mn" --version)" [ "$installed" = "$version" ] || { echo "::error::mn --version printed '$installed', not $version"; exit 1; } # As mn resolves it: the platform package beside its bundle. reader="$(node -e " const { createRequire } = require('node:module'); const { dirname, join } = require('node:path'); const from = createRequire('$prefix/lib/node_modules/midnight-wallet-cli/dist/wallet.js'); console.log(join(dirname(from.resolve('@kuiralabs/dust-sync-linux-x64/package.json')), 'dust-sync')); ")" ledger="$("$reader" --ledger)" [ "$ledger" = "9" ] || { echo "::error::$reader --ledger printed '$ledger', not 9"; exit 1; } echo "mn $installed from npm runs the native Dust reader $reader (ledger $ledger)"