fix(ci): fail fast on blocked Vercel deployments and cache Rust builds
VoxHarbor CI/CD / Verify (linux, latest) (push) Canceled after 0s
VoxHarbor CI/CD / Verify (linux, production) (push) Canceled after 0s
VoxHarbor CI/CD / Verify (macos, latest) (push) Canceled after 0s
VoxHarbor CI/CD / Verify (macos, production) (push) Canceled after 0s
VoxHarbor CI/CD / Deploy production (push) Canceled after 0s
VoxHarbor CI/CD / Verify (linux, latest) (push) Canceled after 0s
VoxHarbor CI/CD / Verify (linux, production) (push) Canceled after 0s
VoxHarbor CI/CD / Verify (macos, latest) (push) Canceled after 0s
VoxHarbor CI/CD / Verify (macos, production) (push) Canceled after 0s
VoxHarbor CI/CD / Deploy production (push) Canceled after 0s
This commit is contained in:
4 files changed
+134
-11
No files matched your search
@@ -58,6 +58,20 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
rustup toolchain install "$CI_RUST_TOOLCHAIN" --profile minimal --no-self-update
|
rustup toolchain install "$CI_RUST_TOOLCHAIN" --profile minimal --no-self-update
|
||||||
rustup default "$CI_RUST_TOOLCHAIN"
|
rustup default "$CI_RUST_TOOLCHAIN"
|
||||||
|
- name: Identify Rust compiler for cache
|
||||||
|
id: rust
|
||||||
|
shell: bash
|
||||||
|
run: echo "version=$(rustc --version | tr ' ' '-')" >> "$GITHUB_OUTPUT"
|
||||||
|
- name: Cache Rust dependencies and build outputs
|
||||||
|
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry/index
|
||||||
|
~/.cargo/registry/cache
|
||||||
|
~/.cargo/registry/src
|
||||||
|
~/.cargo/git/db
|
||||||
|
native/target
|
||||||
|
key: cargo-${{ runner.os }}-${{ runner.arch }}-${{ steps.rust.outputs.version }}-${{ hashFiles('native/Cargo.lock', 'native/Cargo.toml') }}
|
||||||
- name: Build native adapter and browser codec
|
- name: Build native adapter and browser codec
|
||||||
run: npm run native:build
|
run: npm run native:build
|
||||||
- name: Check JavaScript syntax
|
- name: Check JavaScript syntax
|
||||||
|
|||||||
+9
-5
@@ -13,12 +13,14 @@ Pull requests run secret-free verification on the latest stable GitHub-hosted Ub
|
|||||||
|
|
||||||
Each job installs locked npm dependencies, builds the native adapter and browser codec, checks syntax, runs the complete test suite, audits public source and verifies clean deployment packaging. Building before tests enables the real native identity tests instead of silently skipping them. Latest-toolchain jobs test upgrade compatibility; the application's declared production runtime remains Node.js 22.
|
Each job installs locked npm dependencies, builds the native adapter and browser codec, checks syntax, runs the complete test suite, audits public source and verifies clean deployment packaging. Building before tests enables the real native identity tests instead of silently skipping them. Latest-toolchain jobs test upgrade compatibility; the application's declared production runtime remains Node.js 22.
|
||||||
|
|
||||||
Fork pull requests receive no Vercel credentials. The workflow uses `pull_request`. Official `actions/checkout` v7.0.1 and `actions/setup-node` v7.1.0 are pinned to release commit IDs. Node patches, latest LTS, stable Rust and hosted runner images resolve at execution time; action commit pins and the Vercel CLI version are updated explicitly. Superseded verification jobs are canceled.
|
Fork pull requests receive no Vercel credentials. The workflow uses `pull_request`. Official `actions/checkout` v7.0.1 and `actions/setup-node` v7.1.0 are pinned to release commit IDs. Node patches, latest LTS, stable Rust and hosted runner images resolve at execution time; action commit pins and the Vercel CLI version are updated explicitly. Superseded verification jobs are canceled. Rust dependency downloads and compiled outputs are cached separately by operating system, architecture, exact compiler version and dependency lockfile. The first run builds from scratch; subsequent runs can reuse compatible cached work.
|
||||||
|
|
||||||
A push to `main`, or a manual run on `main`, deploys only after all four verification jobs succeed. The production job has read-only repository permissions, uses the `production` environment and serializes deployments without interrupting an active release. It checks the current main SHA before upload and skips superseded commits.
|
A push to `main`, or a manual run on `main`, deploys only after all four verification jobs succeed. The production job has read-only repository permissions, uses the `production` environment and serializes deployments without interrupting an active release. It checks the current main SHA before upload and skips superseded commits.
|
||||||
|
|
||||||
The deployment job runs on the latest Node.js LTS and uses the pinned official Vercel CLI 65.9.0 with the configured existing team/project IDs. It uploads only the audited folder returned by `deployment:package`. Vercel builds the Linux native executable remotely using its existing production configuration. No application environment values are pulled into GitHub; no local binaries, identity files or private development evidence are uploaded. The CLI token is supplied through the environment, not printed or embedded in a command argument.
|
The deployment job runs on the latest Node.js LTS and uses the pinned official Vercel CLI 65.9.0 with the configured existing team/project IDs. It uploads only the audited folder returned by `deployment:package`. Vercel builds the Linux native executable remotely using its existing production configuration. No application environment values are pulled into GitHub; no local binaries, identity files or private development evidence are uploaded. The CLI token is supplied through the environment, not printed or embedded in a command argument.
|
||||||
|
|
||||||
|
Upload returns immediately with a deployment URL. The workflow then polls Vercel every ten seconds, reports progress, and stops immediately on blocked, failed or canceled states. Upload is limited to three minutes and readiness polling to twelve minutes. A timeout does not cancel the remote deployment; inspect it before uploading again.
|
||||||
|
|
||||||
After Vercel reports readiness, the workflow checks that production serves this release's HTML, browser modules, styles, favicon and manifest. It also checks public sign-in, authentication, origin rejection and WebSocket upgrade gates. These checks do not sign in, create accounts, contact TeamSpeak or test real voice. Failures mark the workflow as failed; an already published release is not automatically rolled back.
|
After Vercel reports readiness, the workflow checks that production serves this release's HTML, browser modules, styles, favicon and manifest. It also checks public sign-in, authentication, origin rejection and WebSocket upgrade gates. These checks do not sign in, create accounts, contact TeamSpeak or test real voice. Failures mark the workflow as failed; an already published release is not automatically rolled back.
|
||||||
|
|
||||||
## GitHub and Vercel setup
|
## GitHub and Vercel setup
|
||||||
@@ -35,10 +37,11 @@ After Vercel reports readiness, the workflow checks that production serves this
|
|||||||
| `PRODUCTION_URL` | Exact production HTTPS origin, without a trailing slash |
|
| `PRODUCTION_URL` | Exact production HTTPS origin, without a trailing slash |
|
||||||
|
|
||||||
IDs are available in the Vercel project settings or existing local `.vercel/project.json`. Do not create another project just to populate these values.
|
IDs are available in the Vercel project settings or existing local `.vercel/project.json`. Do not create another project just to populate these values.
|
||||||
5. Keep `APP_ORIGIN`, Redis credentials, session secret, identity encryption key, reserved owner hash and registration configuration in Vercel. Preserve existing values and data. Do not copy them into GitHub.
|
5. In Vercel **Account Settings → Authentication**, connect the GitHub account used to author commits. That account must have deployment access to the project’s team. For a Hobby team, the author must be its owner. A valid CLI token alone does not grant commit-author access. See [Vercel collaboration troubleshooting](https://vercel.com/docs/deployments/troubleshoot-project-collaboration).
|
||||||
6. Configure branch protection/rules for `main` to require **Verify (linux, production)**, **Verify (macos, production)**, **Verify (linux, latest)** and **Verify (macos, latest)** and block direct pushes as appropriate. Give workflows read-only repository permission; no GitHub write token is needed.
|
6. Keep `APP_ORIGIN`, Redis credentials, session secret, identity encryption key, reserved owner hash and registration configuration in Vercel. Preserve existing values and data. Do not copy them into GitHub.
|
||||||
7. If Vercel's Git integration is enabled, disable its independent automatic Git deployments for this project before relying on this workflow as the deployment gate. Otherwise Vercel can deploy a commit before CI succeeds. Do this in Vercel project settings; keep the project's runtime and private environment unchanged.
|
7. Configure branch protection/rules for `main` to require **Verify (linux, production)**, **Verify (macos, production)**, **Verify (linux, latest)** and **Verify (macos, latest)** and block direct pushes as appropriate. Give workflows read-only repository permission; no GitHub write token is needed.
|
||||||
8. Publish a reviewed change and inspect its first Actions run. Verify the existing owner identity and saved connections after the first rollout. Trigger later manual redeploys through Actions on `main`.
|
8. If Vercel's Git integration is enabled, disable its independent automatic Git deployments for this project before relying on this workflow as the deployment gate. Otherwise Vercel can deploy a commit before CI succeeds. Do this in Vercel project settings; keep the project's runtime and private environment unchanged.
|
||||||
|
9. Publish a reviewed change and inspect its first Actions run. Verify the existing owner identity and saved connections after the first rollout. Trigger later manual redeploys through Actions on `main`.
|
||||||
|
|
||||||
If the default branch has another name, update both the workflow trigger/condition and its main-head check together. Keep the environment branch restriction consistent.
|
If the default branch has another name, update both the workflow trigger/condition and its main-head check together. Keep the environment branch restriction consistent.
|
||||||
|
|
||||||
@@ -48,6 +51,7 @@ Pull requests are tested but are not deployed with production credentials. Previ
|
|||||||
|
|
||||||
## Failures and rollback
|
## Failures and rollback
|
||||||
|
|
||||||
|
- A blocked deployment can indicate missing commit-author access. Check the deployment details, connect the correct GitHub account in Vercel Authentication and verify team membership before trying again.
|
||||||
- A verification failure prevents the deployment job. Fix the failing check; do not bypass it by loosening authentication or changing secrets.
|
- A verification failure prevents the deployment job. Fix the failing check; do not bypass it by loosening authentication or changing secrets.
|
||||||
- A native/Vercel build failure leaves the previous production deployment serving traffic.
|
- A native/Vercel build failure leaves the previous production deployment serving traffic.
|
||||||
- A post-deployment smoke failure can occur after the new release is live. Inspect the Actions/Vercel logs, then manually promote a known-good existing deployment in Vercel if necessary. Check data/schema compatibility first; source rollback does not undo database changes.
|
- A post-deployment smoke failure can occur after the new release is live. Inspect the Actions/Vercel logs, then manually promote a known-good existing deployment in Vercel if necessary. Check data/schema compatibility first; source rollback does not undo database changes.
|
||||||
|
|||||||
+51
-5
@@ -10,16 +10,62 @@ export function validateDeployment(env) {
|
|||||||
if (url.protocol !== 'https:' || url.origin !== env.PRODUCTION_URL || url.username || url.password) throw new Error('PRODUCTION_URL must be an exact HTTPS origin without credentials or a trailing slash.');
|
if (url.protocol !== 'https:' || url.origin !== env.PRODUCTION_URL || url.username || url.password) throw new Error('PRODUCTION_URL must be an exact HTTPS origin without credentials or a trailing slash.');
|
||||||
if (!env.VERCEL_PROJECT_ID.startsWith('prj_') || !env.VERCEL_ORG_ID.startsWith('team_')) throw new Error('Configure the existing Vercel project and team IDs.');
|
if (!env.VERCEL_PROJECT_ID.startsWith('prj_') || !env.VERCEL_ORG_ID.startsWith('team_')) throw new Error('Configure the existing Vercel project and team IDs.');
|
||||||
}
|
}
|
||||||
|
// Poll explicit states: the CLI's default wait can hang on a blocked deployment.
|
||||||
|
export async function waitForDeployment(deploymentUrl, env, {
|
||||||
|
fetchImpl = fetch,
|
||||||
|
sleep = ms => new Promise(resolve => setTimeout(resolve, ms)),
|
||||||
|
now = Date.now,
|
||||||
|
timeoutMs = 12 * 60_000,
|
||||||
|
log = console.log,
|
||||||
|
} = {}) {
|
||||||
|
const endpoint = new URL(`https://api.vercel.com/v13/deployments/${encodeURIComponent(new URL(deploymentUrl).hostname)}`);
|
||||||
|
endpoint.searchParams.set('teamId', env.VERCEL_ORG_ID);
|
||||||
|
const deadline = now() + timeoutMs;
|
||||||
|
while (now() < deadline) {
|
||||||
|
const response = await fetchImpl(endpoint, {
|
||||||
|
headers: { Authorization: `Bearer ${env.VERCEL_TOKEN}` },
|
||||||
|
signal: AbortSignal.timeout(Math.min(15_000, Math.max(1, deadline - now()))),
|
||||||
|
redirect: 'error',
|
||||||
|
});
|
||||||
|
if (!response.ok) throw new Error(`Cannot inspect Vercel deployment (HTTP ${response.status}); inspect its status before retrying the upload.`);
|
||||||
|
const deployment = await response.json();
|
||||||
|
const state = deployment.readyState ?? deployment.status;
|
||||||
|
if (state === 'BLOCKED' || deployment.readySubstate === 'BLOCKED') {
|
||||||
|
throw new Error('Vercel blocked deployment. Check commit-author permissions: connect the author’s GitHub account in Vercel Account Settings → Authentication and confirm access to this project’s team. Inspect the deployment for details.');
|
||||||
|
}
|
||||||
|
if (state === 'READY') { log('Vercel deployment is ready.'); return; }
|
||||||
|
if (['ERROR', 'CANCELED', 'CANCELLED'].includes(state)) throw new Error(`Vercel deployment ${state.toLowerCase()}; inspect its build logs before retrying.`);
|
||||||
|
// Only print known states, never arbitrary API error text or account metadata.
|
||||||
|
log(`Waiting for Vercel: ${['QUEUED', 'INITIALIZING', 'BUILDING'].includes(state) ? state : 'pending'}.`);
|
||||||
|
await sleep(Math.min(10_000, Math.max(0, deadline - now())));
|
||||||
|
}
|
||||||
|
throw new Error('Vercel did not finish within 12 minutes. The deployment may still be running; inspect it before retrying.');
|
||||||
|
}
|
||||||
|
|
||||||
export async function deploy(env = process.env) {
|
export async function deploy(env = process.env) {
|
||||||
validateDeployment(env);
|
validateDeployment(env);
|
||||||
const directory = await packageSource('deployment');
|
const directory = await packageSource('deployment');
|
||||||
await new Promise((resolve, reject) => {
|
const output = await new Promise((resolve, reject) => {
|
||||||
const child = spawn('npx', ['--yes', 'vercel@65.9.0', 'deploy', '--prod', '--yes'], {
|
let stdout = '';
|
||||||
cwd: directory, env: { ...env, VERCEL_CLI_USE_NATIVE_BINARY: '0' }, stdio: 'inherit',
|
const child = spawn('npx', ['--yes', 'vercel@65.9.0', 'deploy', '--prod', '--yes', '--no-wait'], {
|
||||||
|
cwd: directory, env: { ...env, VERCEL_CLI_USE_NATIVE_BINARY: '0' }, stdio: ['ignore', 'pipe', 'inherit'],
|
||||||
|
});
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
child.kill('SIGTERM');
|
||||||
|
reject(new Error('Vercel upload exceeded 3 minutes. Inspect recent deployments before retrying.'));
|
||||||
|
}, 3 * 60_000);
|
||||||
|
child.stdout.on('data', chunk => { stdout = (stdout + chunk).slice(-16_384); });
|
||||||
|
child.once('error', error => { clearTimeout(timer); reject(error); });
|
||||||
|
child.once('exit', code => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
if (code === 0) resolve(stdout);
|
||||||
|
else reject(new Error('Vercel upload failed; inspect the workflow and Vercel logs.'));
|
||||||
});
|
});
|
||||||
child.once('error', reject);
|
|
||||||
child.once('exit', code => code === 0 ? resolve() : reject(new Error('Vercel deployment failed; inspect the workflow and Vercel build logs.')));
|
|
||||||
});
|
});
|
||||||
|
const deploymentUrl = output.match(/https:\/\/[a-z0-9-]+\.vercel\.app\b/i)?.[0];
|
||||||
|
if (!deploymentUrl) throw new Error('Vercel did not return a deployment URL. Inspect recent deployments before retrying.');
|
||||||
|
console.log(`Inspect deployment: ${deploymentUrl}`);
|
||||||
|
await waitForDeployment(deploymentUrl, env);
|
||||||
}
|
}
|
||||||
if (process.argv[1] && import.meta.url === new URL(process.argv[1], 'file:').href) {
|
if (process.argv[1] && import.meta.url === new URL(process.argv[1], 'file:').href) {
|
||||||
deploy().catch(error => { console.error(error.message); process.exitCode = 1; });
|
deploy().catch(error => { console.error(error.message); process.exitCode = 1; });
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import test from 'node:test';
|
import test from 'node:test';
|
||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { validateDeployment } from '../scripts/deploy-ci.mjs';
|
import { validateDeployment, waitForDeployment } from '../scripts/deploy-ci.mjs';
|
||||||
test('CI deployment fails before upload without an explicit existing project and HTTPS origin', () => {
|
test('CI deployment fails before upload without an explicit existing project and HTTPS origin', () => {
|
||||||
const env = { VERCEL_TOKEN: 'synthetic-ci-token', VERCEL_ORG_ID: 'team_fixture', VERCEL_PROJECT_ID: 'prj_fixture', PRODUCTION_URL: 'https://example.com' };
|
const env = { VERCEL_TOKEN: 'synthetic-ci-token', VERCEL_ORG_ID: 'team_fixture', VERCEL_PROJECT_ID: 'prj_fixture', PRODUCTION_URL: 'https://example.com' };
|
||||||
assert.doesNotThrow(() => validateDeployment(env));
|
assert.doesNotThrow(() => validateDeployment(env));
|
||||||
@@ -8,3 +8,62 @@ test('CI deployment fails before upload without an explicit existing project and
|
|||||||
for (const origin of ['http://example.com', 'https://example.com/', 'https://user:password@example.com']) assert.throws(() => validateDeployment({ ...env, PRODUCTION_URL: origin }));
|
for (const origin of ['http://example.com', 'https://example.com/', 'https://user:password@example.com']) assert.throws(() => validateDeployment({ ...env, PRODUCTION_URL: origin }));
|
||||||
assert.throws(() => validateDeployment({ ...env, VERCEL_PROJECT_ID: 'another-project' }));
|
assert.throws(() => validateDeployment({ ...env, VERCEL_PROJECT_ID: 'another-project' }));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const deploymentEnv = { VERCEL_TOKEN: 'synthetic-ci-token', VERCEL_ORG_ID: 'team_fixture' };
|
||||||
|
const deploymentUrl = 'https://fixture-deployment.vercel.app';
|
||||||
|
function pollingFixture(states) {
|
||||||
|
let time = 0;
|
||||||
|
const calls = [];
|
||||||
|
const logs = [];
|
||||||
|
return {
|
||||||
|
calls, logs,
|
||||||
|
options: {
|
||||||
|
now: () => time,
|
||||||
|
sleep: async ms => { time += ms; },
|
||||||
|
log: message => logs.push(message),
|
||||||
|
fetchImpl: async (url, options) => {
|
||||||
|
calls.push({ url, options });
|
||||||
|
const state = states[Math.min(calls.length - 1, states.length - 1)];
|
||||||
|
return { ok: true, json: async () => typeof state === 'string' ? { readyState: state } : state };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
test('CI detects the observed Vercel TEAM_ACCESS_REQUIRED block without waiting or exposing metadata', async () => {
|
||||||
|
const fixture = pollingFixture([{ readyState: 'BLOCKED', status: 'BLOCKED', seatBlock: { blockCode: 'TEAM_ACCESS_REQUIRED', isVerified: false }, privateData: 'must-not-be-logged' }]);
|
||||||
|
await assert.rejects(waitForDeployment(deploymentUrl, deploymentEnv, fixture.options), /blocked.*commit-author permissions/);
|
||||||
|
assert.equal(fixture.calls.length, 1);
|
||||||
|
assert.deepEqual(fixture.logs, []);
|
||||||
|
assert.equal(fixture.calls[0].url.origin, 'https://api.vercel.com');
|
||||||
|
assert.equal(fixture.calls[0].url.searchParams.get('teamId'), 'team_fixture');
|
||||||
|
assert.equal(fixture.calls[0].options.headers.Authorization, 'Bearer synthetic-ci-token');
|
||||||
|
assert.equal(fixture.calls[0].options.redirect, 'error');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('CI waits for readiness and stops polling immediately after success', async () => {
|
||||||
|
const fixture = pollingFixture(['QUEUED', 'BUILDING', 'READY']);
|
||||||
|
await waitForDeployment(deploymentUrl, deploymentEnv, fixture.options);
|
||||||
|
assert.equal(fixture.calls.length, 3);
|
||||||
|
assert.equal(fixture.logs.at(-1), 'Vercel deployment is ready.');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('CI stops on build errors, cancellation and blocked substates', async () => {
|
||||||
|
for (const state of ['ERROR', 'CANCELED', { readyState: 'BUILDING', readySubstate: 'BLOCKED' }]) {
|
||||||
|
const fixture = pollingFixture([state]);
|
||||||
|
await assert.rejects(waitForDeployment(deploymentUrl, deploymentEnv, fixture.options), /Vercel deployment|Vercel blocked/);
|
||||||
|
assert.equal(fixture.calls.length, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('CI bounds queue/build waits and warns against duplicate uploads after timeout', async () => {
|
||||||
|
const fixture = pollingFixture(['BUILDING']);
|
||||||
|
await assert.rejects(waitForDeployment(deploymentUrl, deploymentEnv, { ...fixture.options, timeoutMs: 20_000 }), /may still be running.*inspect it before retrying/);
|
||||||
|
assert.equal(fixture.calls.length, 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('CI surfaces inspection access failures without printing response bodies', async () => {
|
||||||
|
await assert.rejects(waitForDeployment(deploymentUrl, deploymentEnv, {
|
||||||
|
fetchImpl: async () => ({ ok: false, status: 403, json: () => { throw new Error('private response must not be read'); } }),
|
||||||
|
}), /HTTP 403/);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user