add ci/cd
This commit is contained in:
7 files changed
+248
-2
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import { spawn } from 'node:child_process';
|
||||
import { packageSource } from './package-source.mjs';
|
||||
|
||||
// No Vercel environment pull: application secrets remain on Vercel.
|
||||
export function validateDeployment(env) {
|
||||
for (const name of ['VERCEL_TOKEN', 'VERCEL_ORG_ID', 'VERCEL_PROJECT_ID', 'PRODUCTION_URL']) {
|
||||
if (!env[name]?.trim()) throw new Error(`Configure ${name} in the production GitHub environment.`);
|
||||
}
|
||||
const url = new URL(env.PRODUCTION_URL);
|
||||
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.');
|
||||
}
|
||||
export async function deploy(env = process.env) {
|
||||
validateDeployment(env);
|
||||
const directory = await packageSource('deployment');
|
||||
await new Promise((resolve, reject) => {
|
||||
const child = spawn('npx', ['--yes', 'vercel@65.9.0', 'deploy', '--prod', '--yes'], {
|
||||
cwd: directory, env: { ...env, VERCEL_CLI_USE_NATIVE_BINARY: '0' }, stdio: 'inherit',
|
||||
});
|
||||
child.once('error', reject);
|
||||
child.once('exit', code => code === 0 ? resolve() : reject(new Error('Vercel deployment failed; inspect the workflow and Vercel build logs.')));
|
||||
});
|
||||
}
|
||||
if (process.argv[1] && import.meta.url === new URL(process.argv[1], 'file:').href) {
|
||||
deploy().catch(error => { console.error(error.message); process.exitCode = 1; });
|
||||
}
|
||||
@@ -2,8 +2,8 @@ import { readdir, lstat } from 'node:fs/promises';
|
||||
import { resolve, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
export const projectRoot = fileURLToPath(new URL('../', import.meta.url));
|
||||
const roots = ['api', 'src', 'public', 'scripts', 'tests', 'docs', 'native/src', 'native/vendor'];
|
||||
const top = ['.gitignore', '.vercelignore', '.env.example', 'LICENSE', 'THIRD_PARTY_NOTICES.md', 'SECURITY.md', 'CONTRIBUTING.md', 'README.md', 'IMPLEMENTATION_PLAN.md', 'package.json', 'package-lock.json', 'vercel.json', 'native/Cargo.toml', 'native/Cargo.lock', 'native/README.md'];
|
||||
const roots = ['.github/workflows', 'api', 'src', 'public', 'scripts', 'tests', 'docs', 'native/src', 'native/vendor'];
|
||||
const top = ['.gitignore', '.vercelignore', '.env.example', 'LICENSE', 'THIRD_PARTY_NOTICES.md', 'SECURITY.md', 'CONTRIBUTING.md', 'README.md', 'AGENTS.md', 'IMPLEMENTATION_PLAN.md', 'package.json', 'package-lock.json', 'vercel.json', 'native/Cargo.toml', 'native/Cargo.lock', 'native/README.md'];
|
||||
export function privatePath(path) {
|
||||
return /(^|\/)(\.git|\.local|\.idea|\.vscode|node_modules|target|coverage|evidence)(\/|$)/.test(path) ||
|
||||
/^(native\/bin|docs\/verification)(\/|$)/.test(path) ||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { createHash } from 'node:crypto';
|
||||
const origin = process.argv[2];
|
||||
const url = new URL(origin);
|
||||
if (url.protocol !== 'https:' || url.origin !== origin) throw new Error('Pass an exact HTTPS production origin.');
|
||||
const files = ['index.html', 'app.mjs', 'workspace.mjs', 'workspace-model.mjs', 'protocol.mjs', 'protocol-connection.mjs', 'audio-recovery.mjs', 'style.css', 'favicon.svg', 'favicon.ico', 'site.webmanifest'];
|
||||
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
|
||||
for (let attempt = 0; attempt < 3; attempt++) {
|
||||
try {
|
||||
for (const file of files) {
|
||||
const response = await fetch(new URL(file === 'index.html' ? '/' : `/${file}`, origin), { redirect: 'error', signal: AbortSignal.timeout(30000) });
|
||||
assert.equal(response.status, 200, `${file} must be publicly served`);
|
||||
assert.equal(hash(Buffer.from(await response.arrayBuffer())), hash(await readFile(new URL(`../public/${file}`, import.meta.url))), `${file} must match this release`);
|
||||
}
|
||||
console.log(`Production release verified: ${files.length} assets match the tested source.`);
|
||||
break;
|
||||
} catch (error) {
|
||||
if (attempt === 2) throw error;
|
||||
await new Promise(resolve => setTimeout(resolve, 3000));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user