TypeScript
fix(release): keep Vercel warnings out of deployment URLs (#22817)
Theo Browne1688f965682d
diff --git a/.github/scripts/vercel-deployment-output.test.cjs b/.github/scripts/vercel-deployment-output.test.cjsnew file mode 100644index 00000000000..a249653350f--- /dev/null+++ b/.github/scripts/vercel-deployment-output.test.cjs@@ -0,0 +1,87 @@+const assert = require("node:assert/strict");+const { spawnSync } = require("node:child_process");+const { mkdtempSync, readFileSync, rmSync, existsSync } = require("node:fs");+const { tmpdir } = require("node:os");+const { join } = require("node:path");+const { test } = require("node:test");++const release = readFileSync(join(__dirname, "../workflows/release.yml"), "utf8");+const preview = readFileSync(join(__dirname, "../workflows/web-preview.yml"), "utf8");+const stepPattern =+ / name: (?:Build staged deployment|Deploy preview)\n shell: bash\n run: \|\n((?: .*\n|\n)+)/g;+const steps = [+ ...Array.from(release.matchAll(stepPattern), (match, index) => [+ index === 0 ? "hosted web" : "marketing",+ match[1],+ ]),+ ...Array.from(preview.matchAll(stepPattern), (match) => ["web preview", match[1]]),+];+assert.equal(steps.length, 3, "Expected both release steps and the preview step");++const url = "https://t3code-fixture-pinglabs.vercel.app";+const warning = 'Error while parsing config file: "/runner/t3code/pnpm-lock.yaml"';++function runStep(script, stdout, exitCode = 0) {+ const directory = mkdtempSync(join(tmpdir(), "t3-vercel-output-"));+ const outputFile = join(directory, "output");+ try {+ const result = spawnSync(+ "bash",+ [+ "-c",+ 'vp() { printf "%s\\n" "$FIXTURE_STDOUT"; return "$FIXTURE_EXIT"; }\n' ++ 'curl() { printf \'{"id":"fixture-project"}\\n\'; }\n' ++ script.replace(/^ /gm, "").replace(/\$\{\{.*?\}\}/g, "fixture"),+ ],+ {+ encoding: "utf8",+ env: {+ PATH: process.env.PATH,+ VERCEL_TOKEN: "fixture-token",+ VERCEL_ORG_ID: "fixture-org",+ VERCEL_PROJECT_ID: "fixture-project",+ GITHUB_OUTPUT: outputFile,+ FIXTURE_STDOUT: stdout,+ FIXTURE_EXIT: String(exitCode),+ },+ },+ );+ assert.ifError(result.error);+ return {+ ...result,+ output: existsSync(outputFile) ? readFileSync(outputFile, "utf8") : "",+ };+ } finally {+ rmSync(directory, { recursive: true, force: true });+ }+}++for (const [name, script] of steps) {+ for (const [label, stdout] of [+ ["plain URL", url],+ ["lockfile warning", `${warning}\n${url}`],+ ["trailing diagnostic", `${url}\nDone`],+ ]) {+ test(`${name}: saves one deployment URL after ${label}`, () => {+ const result = runStep(script, stdout);+ assert.equal(result.status, 0, result.stderr);+ assert.deepEqual(+ result.output.split("\n").filter((line) => !line.startsWith("project_id=")),+ [`deployment_url=${url}`, ""],+ );+ });+ }++ for (const [label, stdout, exitCode] of [+ ["missing URL", warning, 0],+ ["invalid URL", "https://example.invalid/deployment", 0],+ ["multiple URLs", `${url}\nhttps://other.vercel.app`, 0],+ ["failed deployment", url, 1],+ ]) {+ test(`${name}: rejects ${label} without saving output`, () => {+ const result = runStep(script, stdout, exitCode);+ assert.notEqual(result.status, 0);+ assert.equal(result.output, "");+ });+ }+}diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex d2c569b8217..6707b0151bb 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -253,7 +253,7 @@ jobs:run: python3 -B .github/scripts/stage-preview-bundle.test.py- name: Test release checks- run: node --test .github/scripts/check-nightly-release.test.cjs+ run: node --test .github/scripts/check-nightly-release.test.cjs .github/scripts/vercel-deployment-output.test.cjs- name: Finish installing browser secret helper build librariestimeout-minutes: 5diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 65ea056e85a..6a80220c28a 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -1072,7 +1072,7 @@ jobs:fiecho "Building hosted web app for $channel_name channel."- deployment_url="$(+ deployment_output="$(vp dlx [email protected] deploy \--archive=tgz \--prod \@@ -1091,6 +1091,13 @@ jobs:--build-env "VITE_HOSTED_APP_URL=$router_url" \--build-env "VITE_HOSTED_APP_CHANNEL=$channel_name")"+ printf '%s\n' "$deployment_output"+ # Vercel can print lockfile warnings to stdout before the deployment URL.+ deployment_url="$(printf '%s\n' "$deployment_output" | grep -E '^https://[[:alnum:].-]+\.vercel\.app$')"+ if [[ "$deployment_url" == *$'\n'* ]]; then+ echo "Vercel returned multiple deployment URLs." >&2+ exit 1+ fiecho "Staged $deployment_url."echo "deployment_url=$deployment_url" >> "$GITHUB_OUTPUT"@@ -1219,7 +1226,7 @@ jobs:)"export VERCEL_PROJECT_ID- deployment_url="$(+ deployment_output="$(vp dlx [email protected] deploy \--archive=tgz \--prod \@@ -1228,6 +1235,13 @@ jobs:--token "$VERCEL_TOKEN" \--scope "${VERCEL_TEAM_SLUG:-$VERCEL_ORG_ID}")"+ printf '%s\n' "$deployment_output"+ # Vercel can print lockfile warnings to stdout before the deployment URL.+ deployment_url="$(printf '%s\n' "$deployment_output" | grep -E '^https://[[:alnum:].-]+\.vercel\.app$')"+ if [[ "$deployment_url" == *$'\n'* ]]; then+ echo "Vercel returned multiple deployment URLs." >&2+ exit 1+ fiecho "Staged $deployment_url."echo "deployment_url=$deployment_url" >> "$GITHUB_OUTPUT"echo "project_id=$VERCEL_PROJECT_ID" >> "$GITHUB_OUTPUT"diff --git a/.github/workflows/web-preview.yml b/.github/workflows/web-preview.ymlindex f9cc3b063fc..3def8478bbd 100644--- a/.github/workflows/web-preview.yml+++ b/.github/workflows/web-preview.yml@@ -77,13 +77,20 @@ jobs:vercel_scope="${VERCEL_TEAM_SLUG:-$VERCEL_ORG_ID}"- deployment_url="$(+ deployment_output="$(vp dlx [email protected] deploy \--archive=tgz \--yes \--token "$VERCEL_TOKEN" \--scope "$vercel_scope")"+ printf '%s\n' "$deployment_output"+ # Vercel can print lockfile warnings to stdout before the deployment URL.+ deployment_url="$(printf '%s\n' "$deployment_output" | grep -E '^https://[[:alnum:].-]+\.vercel\.app$')"+ if [[ "$deployment_url" == *$'\n'* ]]; then+ echo "Vercel returned multiple deployment URLs." >&2+ exit 1+ fiecho "Deployed $deployment_url"echo "deployment_url=$deployment_url" >> "$GITHUB_OUTPUT"