Skip to content

Open source CapCut alternative.

TypeScript

ci(site): build and deploy Vercel output from GitHub Actions

David Lea900f4ff4f27
diff --git a/.github/workflows/deploy-site.yml b/.github/workflows/deploy-site.yml
new file mode 100644
index 00000000..d30babe4
--- /dev/null
+++ b/.github/workflows/deploy-site.yml
@@ -0,0 +1,103 @@
+name: Deploy Site
+
+on:
+ push:
+ branches: [main]
+ paths:
+ - site/**
+ - .github/workflows/deploy-site.yml
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+# Finish each deployment before starting another. Queued runs check out main
+# when they start, so rerunning an old workflow also ships the current code.
+concurrency:
+ group: deploy-site-production
+ cancel-in-progress: false
+
+jobs:
+ deploy:
+ if: github.ref == 'refs/heads/main'
+ runs-on: ubuntu-latest
+ timeout-minutes: 45
+ env:
+ VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
+ VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ ref: main
+
+ - uses: actions/setup-node@v7
+ with:
+ node-version: 24
+ cache: npm
+ cache-dependency-path: site/package-lock.json
+
+ - name: Check deployment credentials
+ env:
+ VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
+ VERCEL_BUILD_ENV: ${{ secrets.VERCEL_BUILD_ENV }}
+ run: |
+ : "${VERCEL_TOKEN:?Set the VERCEL_TOKEN repository secret}"
+ : "${VERCEL_ORG_ID:?Set the VERCEL_ORG_ID repository secret}"
+ : "${VERCEL_PROJECT_ID:?Set the VERCEL_PROJECT_ID repository secret}"
+ : "${VERCEL_BUILD_ENV:?Set the VERCEL_BUILD_ENV repository secret}"
+
+ - name: Install dependencies
+ working-directory: site
+ run: npm ci
+
+ - name: Build ChatGPT widget
+ working-directory: site
+ run: npm run chatgpt:build
+
+ - name: Test
+ working-directory: site
+ env:
+ DATABASE_URL: postgresql://placeholder:placeholder@localhost:5432/placeholder
+ DIRECT_URL: postgresql://placeholder:placeholder@localhost:5432/placeholder
+ run: |
+ node --test scripts/prepare-vercel-build.test.mjs
+ npm test
+
+ # The Vercel project sets site/ as its root directory. Run its CLI from
+ # the repository root so both the build and upload resolve that directory.
+ - name: Pull production settings
+ env:
+ VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
+ run: npx --yes [email protected] pull --yes --environment=production --token="$VERCEL_TOKEN"
+
+ - name: Prepare build credentials
+ env:
+ VERCEL_BUILD_ENV: ${{ secrets.VERCEL_BUILD_ENV }}
+ run: node site/scripts/prepare-vercel-build.mjs
+
+ - name: Build Vercel output
+ env:
+ VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
+ VERCEL: '1'
+ NODE_OPTIONS: --max-old-space-size=8192
+ DONKEY_DEPLOYMENT_ID: gha-${{ github.run_id }}-${{ github.run_attempt }}
+ run: |
+ npx --yes [email protected] build --prod --token="$VERCEL_TOKEN"
+ node --input-type=module - <<'NODE'
+ import { readFileSync } from 'node:fs';
+ const output = JSON.parse(readFileSync('.vercel/output/config.json', 'utf8'));
+ if (output.deploymentId !== process.env.DONKEY_DEPLOYMENT_ID) {
+ throw new Error('Vercel output must retain the build deployment ID for Skew Protection');
+ }
+ NODE
+
+ - name: Deploy prebuilt output
+ env:
+ VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
+ run: |
+ npx --yes [email protected] deploy --prebuilt --prod --yes --token="$VERCEL_TOKEN" > "$RUNNER_TEMP/site-deployment-url"
+ printf 'Deployed commit `%s`: %s\n' "$(git rev-parse HEAD)" "$(cat "$RUNNER_TEMP/site-deployment-url")" >> "$GITHUB_STEP_SUMMARY"
+
+ - name: Remove pulled credentials
+ if: always()
+ run: rm -f .vercel/.env.production.local
diff --git a/.github/workflows/promote-donkey-release.yml b/.github/workflows/promote-donkey-release.yml
index 40112b42..aabaf5ea 100644
--- a/.github/workflows/promote-donkey-release.yml
+++ b/.github/workflows/promote-donkey-release.yml
@@ -29,6 +29,7 @@ on:
permissions:
contents: write
+ actions: write
# One release at a time, repo-wide: version numbers are derived from the tags that
# already exist, so two runs deriving in parallel would both claim the same patch.
@@ -343,3 +344,9 @@ jobs:
)
python3 scripts/promote-github-release.py "${args[@]}"
+
+ # The Actions token's push does not trigger another push workflow.
+ - name: Deploy updated download link and appcast
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: gh workflow run deploy-site.yml --ref main
diff --git a/.gitignore b/.gitignore
index e2d6910a..03653058 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,6 +14,7 @@ xcuserdata/
# catches a tool run from the repo root, which resolves its cache to a
# node_modules beside this file.
node_modules/
+/.vercel/
/dist/
/apps/Donkey/ultralytics/
__pycache__/
diff --git a/site/next.config.ts b/site/next.config.ts
index 46313bfb..19f9a21c 100644
--- a/site/next.config.ts
+++ b/site/next.config.ts
@@ -2,6 +2,8 @@ import createMDX from "@next/mdx";
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
+ // Prebuilt uploads carry this ID through to Vercel's Skew Protection.
+ deploymentId: process.env.DONKEY_DEPLOYMENT_ID,
pageExtensions: ["js", "jsx", "ts", "tsx", "md", "mdx"],
// Workspace packages ship TypeScript source; the app build transpiles them.
transpilePackages: ["@donkeycut/effects-kit", "@donkeycut/abexp", "@donkeycut/artifact-player"],
diff --git a/site/scripts/prepare-vercel-build.mjs b/site/scripts/prepare-vercel-build.mjs
new file mode 100644
index 00000000..e712ee58
--- /dev/null
+++ b/site/scripts/prepare-vercel-build.mjs
@@ -0,0 +1,45 @@
+import { chmodSync, readFileSync, writeFileSync } from "node:fs";
+import { fileURLToPath } from "node:url";
+import { parse } from "dotenv";
+
+// Vercel keeps runtime secrets unreadable. Prerendering needs database and
+// blog media access; auth initializes during the build, and public keys inline.
+export const buildKeys = [
+ "DATABASE_URL", "DIRECT_URL", "BETTER_AUTH_SECRET", "NEXT_PUBLIC_POSTHOG_KEY",
+ "R2_ACCOUNT_ID", "R2_ACCESS_KEY_ID", "R2_SECRET_ACCESS_KEY",
+];
+
+export function prepareBuildEnvironment(pulled, credentials) {
+ if (!credentials || typeof credentials !== "object" || Array.isArray(credentials)) {
+ throw new Error("VERCEL_BUILD_ENV must be a JSON object");
+ }
+ const values = parse(pulled);
+ for (const key of buildKeys) {
+ const value = credentials[key];
+ if (typeof value !== "string" || !value || value === "[SENSITIVE]") {
+ throw new Error(`VERCEL_BUILD_ENV is missing ${key}`);
+ }
+ values[key] = value;
+ }
+ for (const [key, value] of Object.entries(values)) {
+ if (value !== "[SENSITIVE]") continue;
+ if (key.startsWith("NEXT_PUBLIC_")) {
+ throw new Error(`Public build variable ${key} needs an explicit build credential`);
+ }
+ delete values[key];
+ }
+ return Object.entries(values).map(([key, value]) => {
+ // dotenv preserves literal backslashes inside single quotes and backticks.
+ const quote = ["'", "`"].find(candidate => !value.includes(candidate));
+ if (!quote) throw new Error(`Build variable ${key} contains unsupported quote delimiters`);
+ return `${key}=${quote}${value}${quote}`;
+ }).join("\n") + "\n";
+}
+
+if (process.argv[1] === fileURLToPath(import.meta.url)) {
+ const file = new URL("../../.vercel/.env.production.local", import.meta.url);
+ const credentials = JSON.parse(process.env.VERCEL_BUILD_ENV ?? "null");
+ const output = prepareBuildEnvironment(readFileSync(file, "utf8"), credentials);
+ chmodSync(file, 0o600);
+ writeFileSync(file, output, { mode: 0o600 });
+}
diff --git a/site/scripts/prepare-vercel-build.test.mjs b/site/scripts/prepare-vercel-build.test.mjs
new file mode 100644
index 00000000..390e9700
--- /dev/null
+++ b/site/scripts/prepare-vercel-build.test.mjs
@@ -0,0 +1,31 @@
+import assert from "node:assert/strict";
+import { test } from "node:test";
+import { parse } from "dotenv";
+import { buildKeys, prepareBuildEnvironment } from "./prepare-vercel-build.mjs";
+
+const credentials = Object.fromEntries(buildKeys.map(key => [key, `test-${key}`]));
+
+test("replaces build credentials and removes unreadable runtime secrets", () => {
+ const result = parse(prepareBuildEnvironment(
+ 'DATABASE_URL="[SENSITIVE]"\nOPENAI_API_KEY="[SENSITIVE]"\nVERCEL_ENV="production"\n',
+ credentials,
+ ));
+ assert.equal(result.DATABASE_URL, credentials.DATABASE_URL);
+ assert.equal(result.NEXT_PUBLIC_POSTHOG_KEY, credentials.NEXT_PUBLIC_POSTHOG_KEY);
+ assert.equal(result.VERCEL_ENV, "production");
+ assert.equal(result.OPENAI_API_KEY, undefined);
+});
+
+test("refuses missing build values and unresolved public placeholders", () => {
+ for (const missing of [undefined, "", "[SENSITIVE]", 42]) {
+ assert.throws(() => prepareBuildEnvironment("", { ...credentials, DATABASE_URL: missing }), /missing DATABASE_URL/);
+ }
+ assert.throws(() => prepareBuildEnvironment('NEXT_PUBLIC_NEW_KEY="[SENSITIVE]"', credentials), /NEXT_PUBLIC_NEW_KEY/);
+ assert.throws(() => prepareBuildEnvironment("", null), /JSON object/);
+});
+
+test("preserves quoted and multiline credential values", () => {
+ const value = 'key"with\\slashes\nand-newlines';
+ const result = parse(prepareBuildEnvironment("", { ...credentials, BETTER_AUTH_SECRET: value }));
+ assert.equal(result.BETTER_AUTH_SECRET, value);
+});
diff --git a/site/vercel.json b/site/vercel.json
index 32a22587..0ca66e6a 100644
--- a/site/vercel.json
+++ b/site/vercel.json
@@ -1,5 +1,5 @@
{
- "ignoreCommand": "[ -n \"$VERCEL_GIT_PREVIOUS_SHA\" ] && git cat-file -e \"$VERCEL_GIT_PREVIOUS_SHA^{commit}\" && git diff --quiet \"$VERCEL_GIT_PREVIOUS_SHA\" HEAD -- .",
+ "git": { "deploymentEnabled": false },
"crons": [
{ "path": "/api/chatgpt/gc", "schedule": "15 4 * * *" },
{ "path": "/api/credits/expire", "schedule": "30 0 * * *" },