fix(ci): build the CLI before publishing it

pnpm publish runs no build. apps/cli has no prepack, prepare or
prepublishOnly hook, and the npm lifecycle never invokes a plain
`build` script, so in a clean CI checkout `files: ["dist"]` matched an
empty directory. v0.2.0 shipped a package.json and a LICENSE, nothing
else, and npm reported it as a clean publish.

The old "Validate packaging" step could not catch this: `publish
--dry-run` packs that same empty tarball and exits 0.

Both lanes now build explicitly and then run scripts/verify-tarball.sh,
which packs for real and asserts dist/index.js, both vendored IIFEs and
the three woff2 fonts are present, with a floor on total size.
This commit is contained in:
Nayan
2026-08-11 05:09:15 +05:30
parent 813b34dbe7
commit ae8194f5e8
3 changed files with 104 additions and 9 deletions
+10 -5
View File
@@ -86,11 +86,16 @@ jobs:
node -e "const f='apps/cli/package.json';const p=require('./'+f);p.version='${{ steps.ver.outputs.next }}';require('fs').writeFileSync(f, JSON.stringify(p,null,2)+'\n');"
pnpm install --lockfile-only
# Builds the CLI (tsup + the vendor step) and validates the tarball
# without publishing it. Catches a missing vendored asset here rather
# than in someone's npx.
- name: Validate packaging (build + pack dry-run)
run: pnpm --filter @airshiplabs/cli publish --dry-run --no-git-checks --access public
# This step used to be `publish --dry-run`, which validated nothing:
# `pnpm publish` does not build the package (apps/cli has no prepack or
# prepare hook), so the dry run packed an empty tarball and exited 0.
# That is how v0.2.0 shipped with no dist/. Build explicitly, then pack
# for real and look inside.
- name: Build the CLI
run: pnpm turbo run build --filter=@airshiplabs/cli
- name: Validate packaging
run: bash scripts/verify-tarball.sh
- name: Commit, tag and push
if: ${{ inputs.dry_run == false }}
+14 -4
View File
@@ -42,10 +42,20 @@ jobs:
exit 1
fi
# `pnpm publish` runs the package's build first, which is tsup plus
# scripts/vendor-assets.mjs — the step that puts the overlay bundles and
# the editor fonts inside the tarball. Without it the published CLI 404s
# on its own overlay.
# `pnpm publish` does NOT build the package. apps/cli has no prepack,
# prepare or prepublishOnly hook, and the npm lifecycle never invokes a
# plain `build` script — so nothing here builds unless this step does.
# Skip it and `files: ["dist"]` matches an empty directory, npm reports a
# clean publish, and the tarball ships a package.json and a LICENSE.
# v0.2.0 went out exactly that way.
- name: Build the CLI
run: pnpm turbo run build --filter=@airshiplabs/cli
# Packs for real and looks inside. `publish --dry-run` cannot stand in
# here — it packs the same empty tarball and exits 0.
- name: Verify the tarball is complete
run: bash scripts/verify-tarball.sh
- name: Publish to npm
run: pnpm --filter @airshiplabs/cli publish --access public --no-git-checks --provenance
env:
+80
View File
@@ -0,0 +1,80 @@
#!/usr/bin/env bash
# Asserts the @airshiplabs/cli tarball is actually shippable before it goes out.
#
# Why this exists: `files: ["dist"]` silently matches nothing when dist/ has not
# been built, so `pnpm publish` succeeds and ships a package.json and a LICENSE.
# npm reports that as a clean publish, the version number is burned forever, and
# the breakage only surfaces when a user runs `npx airship`. A --dry-run does not
# catch it — it packs the same empty tarball and exits 0.
#
# So: pack for real, look inside, and fail loudly on anything missing.
#
# bash scripts/verify-tarball.sh
#
# Assumes the CLI is already built (`pnpm turbo run build --filter=@airshiplabs/cli`).
set -euo pipefail
PKG_DIR="apps/cli"
PKG_NAME="@airshiplabs/cli"
# Every path the published CLI resolves at runtime but no bundler can inline.
# dist/vendor/ is written by apps/cli/scripts/vendor-assets.mjs; without it the
# installed CLI 404s on its own overlay and renders unstyled.
REQUIRED=(
"package/package.json"
"package/dist/index.js"
"package/dist/vendor/overlay.global.js"
"package/dist/vendor/hook.global.js"
"package/dist/vendor/fonts/inter-variable.woff2"
"package/dist/vendor/fonts/jetbrains-mono-400.woff2"
"package/dist/vendor/fonts/jetbrains-mono-700.woff2"
)
# A correctly built tarball is ~1MB. An empty one is ~1.5KB. This catches the
# shape of failure the per-file checks might miss if the layout ever changes.
MIN_BYTES=200000
cd "$(git rev-parse --show-toplevel)"
[ -d "$PKG_DIR" ] || { echo "verify-tarball: $PKG_DIR not found" >&2; exit 1; }
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
echo "» packing $PKG_NAME"
( cd "$PKG_DIR" && npm pack --pack-destination "$WORK" >/dev/null )
TARBALL="$(find "$WORK" -name '*.tgz' -maxdepth 1 | head -1)"
[ -n "$TARBALL" ] || { echo "verify-tarball: npm pack produced no tarball" >&2; exit 1; }
SIZE="$(wc -c < "$TARBALL" | tr -d ' ')"
LISTING="$WORK/listing.txt"
tar tzf "$TARBALL" > "$LISTING"
MISSING=0
for entry in "${REQUIRED[@]}"; do
if grep -qxF "$entry" "$LISTING"; then
echo " ✓ ${entry#package/}"
else
echo " ✖ ${entry#package/} — MISSING"
MISSING=1
fi
done
echo
echo " $(wc -l < "$LISTING" | tr -d ' ') files, $SIZE bytes"
if [ "$MISSING" -ne 0 ]; then
echo >&2
echo "verify-tarball: the tarball is incomplete — refusing to publish." >&2
echo " Build it first: pnpm turbo run build --filter=$PKG_NAME" >&2
exit 1
fi
if [ "$SIZE" -lt "$MIN_BYTES" ]; then
echo >&2
echo "verify-tarball: tarball is $SIZE bytes, expected at least $MIN_BYTES." >&2
echo " Something is missing even though the required paths are present." >&2
exit 1
fi
echo "✓ tarball is complete"