diff --git a/desktop/go.mod b/desktop/go.mod index bdb4412f..6ed7c295 100644 --- a/desktop/go.mod +++ b/desktop/go.mod @@ -4,14 +4,14 @@ go 1.27.1 require ( github.com/coder/websocket v1.8.15 - github.com/dop251/goja v0.0.0-20261008155754-5519fb8d7b83 + github.com/dop251/goja v0.0.0-20261105002551-2413f2132ac8 github.com/egoist/mygo v0.6.4-0.20261024094029-23ac61d856d7 github.com/yuin/goldmark v1.8.6 golang.org/x/image v0.46.0 ) require ( - github.com/dlclark/regexp2/v2 v2.8.1 // indirect + github.com/dlclark/regexp2/v2 v2.11.0 // indirect github.com/ebitengine/purego v0.11.1 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/go-text/typesetting v0.3.5 // indirect diff --git a/desktop/go.sum b/desktop/go.sum index 376728a0..002d8723 100644 --- a/desktop/go.sum +++ b/desktop/go.sum @@ -4,8 +4,12 @@ github.com/coder/websocket v1.8.15 h1:6B2JPeOGlpff2Uz6vOEH1Vzpi0iUz20A+lPVhPHtNU github.com/coder/websocket v1.8.15/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg= github.com/dlclark/regexp2/v2 v2.8.1 h1:I1jbaCbXeOxdVN8z3fb55Mvtgb94/6+Dh0zjmXjKV/0= github.com/dlclark/regexp2/v2 v2.8.1/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU= +github.com/dlclark/regexp2/v2 v2.11.0 h1:z5uRPHav+eTVpoffDSuUP2KPS4f1ONZaPDK73S8HA0w= +github.com/dlclark/regexp2/v2 v2.11.0/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU= github.com/dop251/goja v0.0.0-20261008155754-5519fb8d7b83 h1:1ZW6iAC6G8f4TVs7sQZ/8DEm/J6PgE0buV2YvjlDwNU= github.com/dop251/goja v0.0.0-20261008155754-5519fb8d7b83/go.mod h1:GrCNKUrVplXZj0juFue0Cj2Xt/eL2Nuu2+y3UTanEo8= +github.com/dop251/goja v0.0.0-20261105002551-2413f2132ac8 h1:QgXsRtHGoEITJcYOHdJFYKQARRgorgr+M0ZqVFJw8kg= +github.com/dop251/goja v0.0.0-20261105002551-2413f2132ac8/go.mod h1:L1yoLBco9M3b2Gdh1UZHg+BIePeAdV1bwknaLLxAgoc= github.com/ebitengine/purego v0.11.1 h1:2zpWRSQNVKN4eKsKO9eM1ILDgWfYMY9GwqRmK6XeQ/0= github.com/ebitengine/purego v0.11.1/go.mod h1:DCHPP08djqhNSoTfImcnHYQRZmd0qhakvrozqaEYhGQ= github.com/egoist/mygo v0.6.4-0.20261024094029-23ac61d856d7 h1:9A/MH+CHE8D0Cpj2oZdtoaZAdj+kM13GxeJEecnARK4= diff --git a/docs/architecture/website.md b/docs/architecture/website.md index a0d39bdd..63b33e4d 100644 --- a/docs/architecture/website.md +++ b/docs/architecture/website.md @@ -8,13 +8,9 @@ The Windows download resolves both the staged `Beans Setup .exe` name a The Vercel project `hr-teconologia/beans` connects to `bloodf/beans` on GitHub. Pushes to `main` target production at `usebeans.app`; other branches create previews. Its root directory is `web`, with source files outside that directory enabled. Installation runs `cd .. && pnpm install --frozen-lockfile`, and the build runs `pnpm run build`. -The project's Ignored Build Step compares `VERCEL_GIT_PREVIOUS_SHA` with `HEAD` for `web/`, `desktop/`, the root `package.json` and `bun.lock`, `crates/models/catalog.json`, `crates/cli/marketplace/index.json`, and `.vercelignore`. These paths cover the site, embedded desktop demo, workspace dependencies and served catalogs. An unchanged diff skips the build. A missing previous deployment SHA or unavailable Git history allows the build. Vercel's automatic affected-project detection is disabled so it cannot skip changes to the served catalogs outside the JavaScript workspaces. +The Ignored Build Step in `web/vercel.json` runs `sh ./vercel-ignore.sh` within the 256-character configuration limit. The script requires `VERCEL_GIT_PREVIOUS_SHA` to be a full 40- or 64-character hexadecimal ID of an available Git commit before comparing it with `HEAD` for the site, embedded desktop demo, root package and pnpm lock/workspace settings, Blobatar package, served catalogs and `.vercelignore`. Only a successful unchanged diff skips the build. Missing previous deployment SHA or unavailable Git history returns exit 1 to run the build instead of failing deployment with Git's error status. Vercel's automatic affected-project detection is disabled so it cannot skip changes to served catalogs outside the JavaScript workspaces. -`.vercelignore` retains Git metadata so the Ignored Build Step can compare commits. This filter is stored in the Vercel project settings and runs from `web`: - -```sh -test -n "$VERCEL_GIT_PREVIOUS_SHA" && git diff --quiet "$VERCEL_GIT_PREVIOUS_SHA" HEAD -- . ../desktop ../package.json ../bun.lock ../crates/models/catalog.json ../crates/cli/marketplace/index.json ../.vercelignore -``` +`.vercelignore` retains Git metadata for this comparison. The repository configuration overrides the project's Ignored Build Step and runs from `web`. `python3 scripts/test_vercel_ignore.py` verifies unchanged, changed, empty and unavailable previous revisions using real temporary Git commits. ## Landing-page motion diff --git a/scripts/test_vercel_ignore.py b/scripts/test_vercel_ignore.py new file mode 100644 index 00000000..eaee479d --- /dev/null +++ b/scripts/test_vercel_ignore.py @@ -0,0 +1,87 @@ +import json +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + + +COMMAND = json.loads((Path(__file__).resolve().parents[1] / "web/vercel.json").read_text())["ignoreCommand"] + + +class IgnoreBuildTest(unittest.TestCase): + def test_sha256_commit(self): + with tempfile.TemporaryDirectory(prefix="beans-vercel-sha256-") as directory: + root = Path(directory) + web = root / "web" + web.mkdir() + (web / "vercel-ignore.sh").write_bytes((Path(__file__).resolve().parents[1] / "web/vercel-ignore.sh").read_bytes()) + subprocess.run(["git", "init", "-q", "--object-format=sha256"], cwd=root, check=True, capture_output=True) + subprocess.run(["git", "add", "."], cwd=root, check=True, capture_output=True) + subprocess.run(["git", "-c", "user.name=Beans test", "-c", "user.email=test@example.invalid", "commit", "-qm", "initial"], cwd=root, check=True, capture_output=True) + previous = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=root, text=True).strip() + self.assertEqual(len(previous), 64) + env = {**os.environ, "VERCEL_GIT_PREVIOUS_SHA": previous} + self.assertEqual(subprocess.run(["sh", "-c", COMMAND], cwd=web, env=env, capture_output=True).returncode, 0) + (web / "page.txt").write_text("changed") + subprocess.run(["git", "add", "."], cwd=root, check=True, capture_output=True) + subprocess.run(["git", "-c", "user.name=Beans test", "-c", "user.email=test@example.invalid", "commit", "-qm", "changed"], cwd=root, check=True, capture_output=True) + self.assertEqual(subprocess.run(["sh", "-c", COMMAND], cwd=web, env=env, capture_output=True).returncode, 1) + + def test_real_git_inputs(self): + with tempfile.TemporaryDirectory(prefix="beans-vercel-ignore-") as directory: + root = Path(directory) + web = root / "web" + web.mkdir() + self.assertLessEqual(len(COMMAND), 256) + (web / "vercel-ignore.sh").write_bytes((Path(__file__).resolve().parents[1] / "web/vercel-ignore.sh").read_bytes()) + + def git(*args): + return subprocess.run(["git", *args], cwd=root, check=True, capture_output=True, text=True).stdout.strip() + + def ignored(previous): + env = {**os.environ, "VERCEL_GIT_PREVIOUS_SHA": previous} + return subprocess.run(["sh", "-c", COMMAND], cwd=web, env=env, capture_output=True).returncode + + git("init", "-q") + git("config", "user.name", "Beans test") + git("config", "user.email", "test@example.invalid") + (web / "page.txt").write_text("initial") + (root / "pnpm-lock.yaml").write_text("initial") + git("add", ".") + git("commit", "-qm", "initial") + initial = git("rev-parse", "HEAD") + self.assertEqual(ignored(initial), 0) + self.assertEqual(ignored(""), 1) + self.assertEqual(ignored("f" * 40), 1) + for invalid in ("--cached", "--quiet", "HEAD", "refs/heads/main", "g" * 40, "a" * 39, "a" * 41, "a" * 63, "a" * 65, "f" * 64): + with self.subTest(previous=invalid): + self.assertEqual(ignored(invalid), 1) + missing_env = dict(os.environ) + missing_env.pop("VERCEL_GIT_PREVIOUS_SHA", None) + self.assertEqual(subprocess.run(["sh", "-c", COMMAND], cwd=web, env=missing_env, capture_output=True).returncode, 1) + blob = git("rev-parse", "HEAD:web/page.txt") + tree = git("rev-parse", "HEAD^{tree}") + self.assertEqual(ignored(blob), 1) + self.assertEqual(ignored(tree), 1) + (root / ".git").rename(root / "git-unavailable") + try: + self.assertEqual(ignored(initial), 1) + finally: + (root / "git-unavailable").rename(root / ".git") + (web / "page.txt").write_text("changed") + git("commit", "-qam", "website change") + self.assertEqual(ignored(initial), 1) + website = git("rev-parse", "HEAD") + (root / "pnpm-lock.yaml").write_text("changed") + git("commit", "-qam", "dependency change") + self.assertEqual(ignored(website), 1) + dependency = git("rev-parse", "HEAD") + (root / "Cargo.lock").write_text("Rust-only change") + git("add", ".") + git("commit", "-qm", "unrelated Rust change") + self.assertEqual(ignored(dependency), 0) + + +if __name__ == "__main__": + unittest.main() diff --git a/web/vercel-ignore.sh b/web/vercel-ignore.sh new file mode 100644 index 00000000..ba0baf20 --- /dev/null +++ b/web/vercel-ignore.sh @@ -0,0 +1,10 @@ +#!/bin/sh +case "$VERCEL_GIT_PREVIOUS_SHA" in + ''|*[!0123456789abcdefABCDEF]*) exit 1 ;; +esac +case "${#VERCEL_GIT_PREVIOUS_SHA}" in + 40|64) ;; + *) exit 1 ;; +esac +test "$(git cat-file -t "$VERCEL_GIT_PREVIOUS_SHA")" = commit || exit 1 +git diff --quiet "$VERCEL_GIT_PREVIOUS_SHA" HEAD -- . ../desktop ../package.json ../pnpm-lock.yaml ../pnpm-workspace.yaml ../.npmrc ../packages/beans-blobatar ../crates/models/catalog.json ../crates/cli/marketplace/index.json ../.vercelignore; result=$?; test "$result" -eq 0 diff --git a/web/vercel.json b/web/vercel.json index cecc1936..4a90457a 100644 --- a/web/vercel.json +++ b/web/vercel.json @@ -21,5 +21,6 @@ ] } ], - "installCommand": "pnpm install --frozen-lockfile" + "installCommand": "pnpm install --frozen-lockfile", + "ignoreCommand": "sh ./vercel-ignore.sh" }