Skip to content

fix(sdk): separate latest deployment from official archives - #65

Open
m4sh-wacker wants to merge 1 commit into
mainfrom
fix/sdk-latest-deployment-archive-policy
Open

m4sh-wacker wants to merge 1 commit into
mainfrom
fix/sdk-latest-deployment-archive-policy

Conversation

@m4sh-wacker

Copy link
Copy Markdown
Collaborator

Summary

Separates continuous latest SDK deployments from immutable milestone SDK archives so ordinary main deployments always publish the latest website, standalone HTML, and /api / /api.js aliases without colliding with archived versions.

  • Base main commit SHA: f3f7b15aac6c7359a92a584f7c3f077207b64928

Root Cause of the Previous Deployment Failure

  1. Ordinary builds wrote directly into published archive directories: scripts/build-sdk.mjs previously wrote into dist/sdk/v1/<package.json version>/ (0.3.3), while package.json stays on the previous release version until a Release Please PR is merged (and Release Please ignores chore(deps): commits because chore is hidden: true).
  2. Bundler change + immutable diff failure: PR chore(deps): bump the monthly-maintenance group with 12 updates #62 (195c13f) bumped vite (8.3.5 -> 8.4.0, updating rolldown 1.2.14 -> 1.3.4), changing the minified bytes of decodebox.js and decodebox.mjs while package.json remained 0.3.3. Consequently, Deploy to GitHub Pages runs 46672589781 and 46692468864 failed on diff -qr "$release" "$target" in .github/workflows/deploy-pages.yml (just as earlier engine PRs fix(encodings): refuse Base45 and Base85 groups that overflow #50 and fix(encodings): refuse punctuation in Punycode digits #51 failed prior to 0.3.2 and 0.3.3).
  3. Vite 8.4.0 standalone HTML regression (discovered during Chromium verification): Vite 8.4.0 changed its internal preload placeholder to /__VITE_PRELOAD__(?:[\da-f]{32})?/g. standalonePlugin() in vite.config.ts replaced only __VITE_PRELOAD__, leaving a trailing 32-hex hash ([]e115532ea529dbadd736874a4545557e) inside dist/decodebox.html and causing a SyntaxError on load.

Why diff -qr "$release" "$target" Was Removed from Website Deployment

In the finalized two-channel architecture, the latest online SDK built from main is intentionally newer than (and allowed to differ from) older official archived SDKs. Comparing a freshly built latest SDK against an archived version directory incorrectly treated the old archive as the expected latest SDK.

  • Removed diff -qr "$release" "$target" from the ordinary main website deployment path in .github/workflows/deploy-pages.yml.
  • Kept all real quality gates active and blocking, plus added a vm.SourceTextModule parse check on dist/decodebox.html before publishing.
  • Kept strict archive immutability checks in both scripts/build-sdk.mjs (--release mode) and scripts/publish-gh-pages.mjs (--mode archive), which refuse to overwrite any existing official archive with differing bytes.

Architecture: Two Independent SDK Channels

1. Latest SDK — Continuous Deployment (main)

  • npm run build:sdk (scripts/build-sdk.mjs in default latest mode) builds decodebox.js, decodebox.mjs, decodebox.d.mts, and SHA256SUMS into staging directory build/sdk/ (gitignored, outside dist/).
  • Publishes only the latest aliases inside dist/:
    • /api, /api.js, /sdk/v1/decodebox.js, /sdk/decodebox.js
    • /sdk/v1/decodebox.esm.js, /sdk/decodebox.mjs
    • /sdk/decodebox.d.mts
  • Never creates or overwrites versioned /sdk/v1/<version>/ archive directories during ordinary deployments.
  • scripts/check-sdk-dist.mjs validates all dist/ aliases against build/sdk/SHA256SUMS, verifies retained official archives and absence of obsolete directories, and runs the Node smoke test.
  • src/sdk/index.ts keeps engineVersion tied to package.json (no artificial version bumping) and adds additive buildId metadata derived from the built Git commit SHA.

2. Official SDK Archives — PATCH=0 Milestone Policy

Only stable releases whose PATCH component is 0 generate and publish an immutable versioned archive under /sdk/v1/{version}/:

Release Archive generated?
0.3.4, 0.3.5, 0.4.1, 0.4.2 No
0.4.0, 0.5.0, 1.0.0, 1.1.0 Yes
  • scripts/build-sdk.mjs --release <tag> validates PATCH === 0 via archivePathFor(), verifies <version> matches the checked-out tag's package.json, builds into a temp dir, verifies SHA256SUMS, refuses to overwrite differing existing archives, and never touches /api or /api.js.

One-Time Archive Cleanup (0.3.1–0.3.3 Removed; 0.2.0 & 0.3.0 Preserved)

  • 0.2.0 and 0.3.0 are preserved byte-for-byte (including SHA256SUMS verification before copying forward) because both are qualifying PATCH === 0 milestone releases.
  • 0.3.1, 0.3.2, and 0.3.3 are removed via OBSOLETE_ARCHIVE_DIRS in scripts/publish-gh-pages.mjs (--mode latest) on the next main deployment because they are pre-policy patch releases (PATCH !== 0). Once removed from gh-pages, latest deployments never generate versioned directories, so they are never restored.
  • No Git tags, GitHub Releases, source files, or latest aliases are deleted.

Release Please Integration

  • Ordinary bug fixes / pending Release Please PR: Merging PRs to main updates the website, decodebox.html, and /api + /api.js; pending Release Please PRs update normally without publishing archives.
  • Patch releases (e.g. v0.3.4): Release Please creates the GitHub Release and .github/actions/standalone-release uploads/verifies the standalone HTML without creating /sdk/v1/0.3.4/ or overwriting latest aliases.
  • Milestone releases (e.g. v0.4.0): Because tags/releases created with GITHUB_TOKEN do not trigger separate push: tags or release workflows, .github/workflows/release-please.yml checks out the exact tag via standalone-release, builds /sdk/v1/<version>/ (--release "$RELEASE_TAG"), verifies SHA256SUMS, and publishes only that archive directory via scripts/publish-gh-pages.mjs --mode archive (never replacing website files or /api / /api.js). Retries are idempotent when the archive already matches and fail closed on content differences.

Concurrency & GitHub Pages Publication Safety

Separate workflow concurrency groups (github-pages in deploy-pages.yml and release-please-${{ github.ref }} in release-please.yml) serialize runs within each workflow, but are not sufficient alone when a release PR merge triggers both workflows concurrently on main. Without cross-workflow coordination, a blind git push --force from whichever finishes second would wipe out either the newly deployed website/aliases or the newly published milestone archive.

To prevent lost updates across workflows:

  • Both deploy-pages.yml (--mode latest) and release-please.yml (--mode archive) share scripts/publish-gh-pages.mjs.
  • Before committing, publish-gh-pages.mjs reads refs/heads/gh-pages (expectedOid), fetches the latest FETCH_HEAD, merges only its owned slice (latest mode: website + aliases onto retained archives; archive mode: /sdk/v1/<version>/ onto the entire live gh-pages snapshot), and pushes atomically with git push --force-with-lease=refs/heads/gh-pages:<expectedOid>.
  • On a CAS conflict (stale info / ref moved), it retries with backoff against the fresh FETCH_HEAD (up to 5 attempts), ensuring neither workflow ever force-pushes a stale snapshot or loses the other's updates.

Test Results

Executed locally on Windows (Node v24.18.0, Chrome via playwright-core):

  • npm run lint (eslint .): passed (0 errors, 0 warnings; also re-run post-commit)
  • npm run typecheck (tsc --noEmit): passed (also re-run post-commit)
  • npm test -- --run: 77 test files, 1,279 tests passed, including src/sdk/sdk.test.ts (6 tests) and scripts/sdk-distribution.test.mjs (6 tests covering PATCH=0 policy, Scenarios A–G, real buildSdk latest/release modes, and bidirectional CAS concurrency race retries against bare git remotes)
  • npm run build & npm run check:sdk-dist: passed (also re-run post-commit)
  • npm audit --audit-level=high: passed (0 vulnerabilities)
  • Simulated full deployment against origin/gh-pages (67a10ed0): verified 0.2.0 & 0.3.0 preserved byte-for-byte, 0.3.1–0.3.3 removed (HTTP 404), live check-sdk-dist.mjs, check-sdk-browser.mjs (6 latest JS aliases), buildId metadata (f3f7b15aac6c), Chromium loads of index.html, decodebox.html (HTTP & file://), and simulated v0.4.0 milestone archive build/publish/--release browser check.
  • Workflow & docs checks: deploy-pages.yml, release-please.yml, and standalone-release/action.yml passed PyYAML parsing and Git Bash bash -n; docs/*.md prose lines checked <= 100 chars; verify-release-cli.cjs YAML structure assertions verified via PyYAML and sdk-paths.mjs fixture check.

Not run locally (Ubuntu runner / external toolchain dependencies): GraalJS CI job, Node 22 matrix leg, markdownlint-cli2-action / lychee-action, and full Linux execution of .github/scripts/verify-release-cli.cjs / verify-release-notes.cjs.


Remaining Risks

  • First deployment cleanup: On the first main deployment after merge, /sdk/v1/0.3.1, /sdk/v1/0.3.2, and /sdk/v1/0.3.3 will be removed from gh-pages (by design under Phase 2); external links pinning those three pre-policy patch URLs will receive 404.
  • Linux-only workflow checks: GraalJS runtime, Node 22 build matrix, verify-release-cli.cjs (/bin/bash fixture), and live GitHub Pages CDN propagation checks will exercise for the first time on the GitHub Actions ubuntu-24.04 runners.
  • Tag-checkout behavior for pre-existing tags: standalone-release checks out the exact tagged commit, so rebuilding an old pre-PR tag runs that tag's own scripts, whereas future tags from main use the new PATCH=0 archive and Vite 8.4.0 preload handling.

Comment thread scripts/sdk-integrity.mjs
if (!info.isFile()) {
throw new Error(`Expected regular file: ${filePath}`);
}
return readFile(filePath);

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants