Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ node_modules
dist
out
build
!website/build/
!website/build/sites-vite-plugin.ts
.open-next

.env
Expand Down
27 changes: 27 additions & 0 deletions tests/baseline/ross-website-contract.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,40 @@ test("the public website is a separate build target", () => {
const rootPackage = json("package.json");
const websitePackage = json("website/package.json");
assert.equal(existsSync(resolve(root, "website/.openai/hosting.json")), true);
assert.equal(existsSync(resolve(root, "website/build/sites-vite-plugin.ts")), true);
assert.equal(websitePackage.name, "ross-ontario");
assert.match(rootPackage.scripts["install:all"], /--prefix website/);
assert.match(rootPackage.scripts.build, /build:website/);
assert.match(rootPackage.scripts.lint, /lint:website/);
assert.match(rootPackage.scripts.check, /test:website/);
});

test("the website build plugin is deliberately tracked", () => {
const ignoreRules = read(".gitignore");
assert.match(ignoreRules, /!website\/build\//);
assert.match(ignoreRules, /!website\/build\/sites-vite-plugin\.ts/);
assert.match(read("website/vite.config.ts"), /\.\/build\/sites-vite-plugin/);
});

test("website shell helpers survive browser uploads without executable modes", () => {
const wrappers = [
"website/scripts/build-verified.sh",
"website/scripts/install-ci.sh",
"website/scripts/validate-artifact.sh",
];
for (const wrapper of wrappers) {
assert.match(
read(wrapper),
/exec bash "\$\{script_dir\}\/sites-env\.sh" -- bash "\$0" "\$@"/,
wrapper,
);
}
assert.match(
read("website/scripts/build-verified.sh"),
/bash "\$\{script_dir\}\/validate-artifact\.sh"/,
);
});

test("the public website derives identity and policy from central configuration", () => {
const central = json("config/ross-brand.json");
const siteConfig = read("website/app/site-config.ts");
Expand Down
45 changes: 45 additions & 0 deletions website/build/sites-vite-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { access, cp, mkdir, rm } from "node:fs/promises";
import { resolve } from "node:path";
import type { Plugin } from "vite";

async function exists(path: string): Promise<boolean> {
try {
await access(path);
return true;
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
return false;
}
throw error;
}
}

// Packages Sites metadata and migrations after Vite finishes compiling.
export function sites(): Plugin {
let root = process.cwd();

return {
name: "sites",
apply: "build",
configResolved(config) {
root = config.root;
},
async closeBundle() {
const outputDirectory = resolve(root, "dist", ".openai");
const hostingConfig = resolve(root, ".openai", "hosting.json");
const drizzleSource = resolve(root, "drizzle");

await rm(outputDirectory, { recursive: true, force: true });
await mkdir(outputDirectory, { recursive: true });

if (await exists(hostingConfig)) {
await cp(hostingConfig, resolve(outputDirectory, "hosting.json"));
}
if (await exists(drizzleSource)) {
await cp(drizzleSource, resolve(outputDirectory, "drizzle"), {
recursive: true,
});
}
},
};
}
5 changes: 3 additions & 2 deletions website/scripts/build-verified.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ set -euo pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

if [[ "${SITES_ENV_READY:-}" != "1" ]]; then
exec "${script_dir}/sites-env.sh" -- "$0" "$@"
# Browser-based GitHub uploads do not preserve executable file modes.
exec bash "${script_dir}/sites-env.sh" -- bash "$0" "$@"
fi

command -v timeout >/dev/null || {
Expand All @@ -25,4 +26,4 @@ timeout \
"${SITES_BUILD_TIMEOUT:-3m}" \
"${vinext}" build

"${script_dir}/validate-artifact.sh"
bash "${script_dir}/validate-artifact.sh"
3 changes: 2 additions & 1 deletion website/scripts/install-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ set -euo pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

if [[ "${SITES_ENV_READY:-}" != "1" ]]; then
exec "${script_dir}/sites-env.sh" -- "$0" "$@"
# Browser-based GitHub uploads do not preserve executable file modes.
exec bash "${script_dir}/sites-env.sh" -- bash "$0" "$@"
fi

command -v flock >/dev/null || {
Expand Down
3 changes: 2 additions & 1 deletion website/scripts/validate-artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ set -euo pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

if [[ "${SITES_ENV_READY:-}" != "1" ]]; then
exec "${script_dir}/sites-env.sh" -- "$0" "$@"
# Browser-based GitHub uploads do not preserve executable file modes.
exec bash "${script_dir}/sites-env.sh" -- bash "$0" "$@"
fi

worker="${SITES_PROJECT_ROOT}/dist/server/index.js"
Expand Down
Loading