#!/usr/bin/env bash # Build vfmt's release artifacts into dist/ and checksum them. # # Produces, for the machine it runs on: # dist/vfmt-- # dist/vfmt-server-- # dist/vfmt-.vsix (the VS Code extension; sideload it) # dist/SHA256SUMS # # Standard tooling only -- cargo, npm and shasum, nothing installed globally. # This does not cross-compile and does not publish anything anywhere; see # tools/RELEASING.md for the whole checklist. # # Usage: tools/release.sh [-o dist-dir] [--no-vsix] # # Exit status: 0 if every requested artifact was built and checksummed. set -eu repo_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) dist=$repo_root/dist want_vsix=1 while [ $# -gt 0 ]; do case $1 in -o) dist=$2; shift 2 ;; --no-vsix) want_vsix=0; shift ;; *) echo "usage: $0 [-o dist-dir] [--no-vsix]" >&2; exit 2 ;; esac done case $dist in /*) ;; *) dist=$repo_root/$dist ;; esac echo "==> building release binaries" cargo build --release --manifest-path "$repo_root/Cargo.toml" \ -p vfmt -p vfmt_server # The binaries themselves are the authority on the version, not Cargo.toml: # `vfmt --version` is what a user will quote in a bug report. version=$("$repo_root/target/release/vfmt" --version | awk '{print $2}') host=$(rustc -vV | awk '/^host:/{print $2}') echo " vfmt $version, host $host" rm -rf "$dist" mkdir -p "$dist" cp "$repo_root/target/release/vfmt" "$dist/vfmt-$version-$host" cp "$repo_root/target/release/vfmt-server" "$dist/vfmt-server-$version-$host" # Prove the server binary still speaks LSP before it is handed to anyone. # `smoke.js` is plain node with no dependencies, so this runs before `npm ci`. if command -v node >/dev/null 2>&1; then echo "==> smoke-testing the server binary" node "$repo_root/editors/vscode/smoke.js" "$dist/vfmt-server-$version-$host" else echo " note: no node on PATH, skipping the server smoke test" >&2 fi if [ "$want_vsix" -eq 1 ]; then echo "==> packaging the VS Code extension" # `vsce` shells out to `npm list` and globs the paths it prints back, so it # must run from a plain path: under a directory whose name has the shape the # session sandbox rewrites, it silently collects zero files and fails with # "Extension entrypoint(s) missing". The repo itself is such a plain path, # which is why this packages in place and only the output goes to -o. ( cd "$repo_root/editors/vscode" npm ci npx @vscode/vsce package --out "$dist/vfmt-$version.vsix" ) fi echo "==> checksums" artifacts="vfmt-$version-$host vfmt-server-$version-$host" if [ "$want_vsix" -eq 1 ]; then artifacts="$artifacts vfmt-$version.vsix" fi ( # Relative names, so `shasum -c SHA256SUMS` works from inside dist/. cd "$dist" # shellcheck disable=SC2086 # deliberate word splitting: one name per file shasum -a 256 $artifacts > SHA256SUMS cat SHA256SUMS ) echo echo "artifacts in $dist:" ls -l "$dist"