add ci/cd
This commit is contained in:
7 files changed
+248
-2
No files matched your search
@@ -0,0 +1,125 @@
|
||||
name: VoxHarbor CI/CD
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
name: Verify (${{ matrix.platform }}, ${{ matrix.toolchain }})
|
||||
runs-on: ${{ matrix.runner }}
|
||||
timeout-minutes: 30
|
||||
concurrency:
|
||||
group: verify-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ matrix.platform }}-${{ matrix.toolchain }}
|
||||
cancel-in-progress: true
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- platform: linux
|
||||
runner: ubuntu-latest
|
||||
toolchain: production
|
||||
node: '22.x'
|
||||
rust: '1.96.0'
|
||||
- platform: macos
|
||||
runner: macos-latest
|
||||
toolchain: production
|
||||
node: '22.x'
|
||||
rust: '1.96.0'
|
||||
- platform: linux
|
||||
runner: ubuntu-latest
|
||||
toolchain: latest
|
||||
node: 'lts/*'
|
||||
rust: stable
|
||||
- platform: macos
|
||||
runner: macos-latest
|
||||
toolchain: latest
|
||||
node: 'lts/*'
|
||||
rust: stable
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
check-latest: true
|
||||
cache: npm
|
||||
- name: Install locked dependencies
|
||||
run: npm ci
|
||||
- name: Select Rust toolchain
|
||||
env:
|
||||
CI_RUST_TOOLCHAIN: ${{ matrix.rust }}
|
||||
run: |
|
||||
rustup toolchain install "$CI_RUST_TOOLCHAIN" --profile minimal --no-self-update
|
||||
rustup default "$CI_RUST_TOOLCHAIN"
|
||||
- name: Build native adapter and browser codec
|
||||
run: npm run native:build
|
||||
- name: Check JavaScript syntax
|
||||
run: npm run check
|
||||
- name: Run tests (including native identity tests)
|
||||
run: npm test
|
||||
- name: Audit public source
|
||||
run: npm run publication:check
|
||||
- name: Verify deployment packaging
|
||||
run: npm run deployment:package
|
||||
|
||||
deploy:
|
||||
name: Deploy production
|
||||
needs: verify
|
||||
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
environment:
|
||||
name: production
|
||||
url: ${{ vars.PRODUCTION_URL }}
|
||||
concurrency:
|
||||
group: voxharbor-production
|
||||
cancel-in-progress: false
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
check-latest: true
|
||||
cache: npm
|
||||
- name: Skip superseded commits
|
||||
id: current
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
head_sha="$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/main" --jq '.object.sha')"
|
||||
if [ "$head_sha" = "$GITHUB_SHA" ]; then
|
||||
echo 'deploy=true' >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo 'A newer main commit exists; this deployment is skipped.'
|
||||
echo 'deploy=false' >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
- name: Install locked dependencies
|
||||
if: steps.current.outputs.deploy == 'true'
|
||||
run: npm ci
|
||||
- name: Upload audited source and wait for Vercel
|
||||
if: steps.current.outputs.deploy == 'true'
|
||||
env:
|
||||
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
|
||||
VERCEL_ORG_ID: ${{ vars.VERCEL_ORG_ID }}
|
||||
VERCEL_PROJECT_ID: ${{ vars.VERCEL_PROJECT_ID }}
|
||||
PRODUCTION_URL: ${{ vars.PRODUCTION_URL }}
|
||||
VERCEL_CLI_USE_NATIVE_BINARY: '0'
|
||||
run: node scripts/deploy-ci.mjs
|
||||
- name: Verify live release and authentication gates
|
||||
if: steps.current.outputs.deploy == 'true'
|
||||
env:
|
||||
PRODUCTION_URL: ${{ vars.PRODUCTION_URL }}
|
||||
run: |
|
||||
node scripts/verify-release.mjs "$PRODUCTION_URL"
|
||||
node scripts/verify-public-deployment.mjs "$PRODUCTION_URL"
|
||||
@@ -32,6 +32,8 @@ npm run deployment:package
|
||||
|
||||
Upload only the printed clean folder. It excludes environment files, identities, local evidence, dependencies, Git metadata and build outputs. Native code builds for the deployment platform. A successful local build is not proof that another deployment/account works.
|
||||
|
||||
GitHub Actions tests pull requests on Linux and macOS and deploys passing changes from `main` to Vercel. See [CI/CD setup](docs/CI_CD.md) for the production environment configuration.
|
||||
|
||||
## Development and verification
|
||||
|
||||
```sh
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# CI/CD
|
||||
|
||||
GitHub Actions runs `.github/workflows/pipeline.yml` to test pull requests and deploy passing changes from `main` to the existing Vercel project.
|
||||
|
||||
## Pipeline
|
||||
|
||||
Pull requests run secret-free verification on the latest stable GitHub-hosted Ubuntu and macOS images. Each platform tests two toolchain combinations:
|
||||
|
||||
| Toolchain | Node.js | Rust |
|
||||
| --- | --- | --- |
|
||||
| Production | Latest Node.js 22 patch | 1.96.0, matching the Vercel native build |
|
||||
| Latest | Latest LTS (`lts/*`, currently 26) | Latest stable (currently 1.99.1) |
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
1. Push the project, including `.github/workflows/pipeline.yml`, to GitHub. Pull requests start verification automatically; pushes to `main` also run the production deployment job.
|
||||
2. In GitHub repository **Settings → Environments**, create `production`. Restrict deployment branches to `main`; add required reviewers if you want a release approval gate.
|
||||
3. Add the environment secret `VERCEL_TOKEN`: a Vercel token authorized for the existing project's team. Create it in Vercel account settings and save it as a GitHub environment secret.
|
||||
4. Add these **environment variables**, not application credentials:
|
||||
|
||||
| Name | Value |
|
||||
| --- | --- |
|
||||
| `VERCEL_ORG_ID` | Existing Vercel team ID (`team_…`) |
|
||||
| `VERCEL_PROJECT_ID` | Existing VoxHarbor project ID (`prj_…`) |
|
||||
| `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.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
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`.
|
||||
|
||||
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.
|
||||
|
||||
## Preview isolation
|
||||
|
||||
Pull requests are tested but are not deployed with production credentials. Preview apps must have their own Vercel project/environment, stable allowed origin, separate Redis database and separate encryption/session keys. The current exact-origin policy and durable account data make reusing production secrets in arbitrary preview URLs inappropriate. Preview deployment is intentionally not enabled by this pipeline.
|
||||
|
||||
## Failures and rollback
|
||||
|
||||
- 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 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.
|
||||
- Do not rotate keys, clear Redis or recreate identities to recover a code deployment.
|
||||
- Configure Actions failure notifications for the maintainers. Do not upload environment files, private runtime logs or account screenshots as workflow artifacts.
|
||||
|
||||
Check the first Actions run after setup to confirm runner builds, Vercel token access and live release verification. Review action release pins and the Vercel CLI version regularly; production runtime upgrades require their own deployment verification.
|
||||
|
||||
Version references: [checkout releases](https://github.com/actions/checkout/releases), [setup-node releases](https://github.com/actions/setup-node/releases), [Node.js releases](https://nodejs.org/en/about/previous-releases), [Rust stable releases](https://releases.rs/), [Vercel CLI package](https://www.npmjs.com/package/vercel).
|
||||
|
||||
References: [Vercel GitHub deployments](https://vercel.com/docs/git/vercel-for-github), [Vercel CLI deployments](https://vercel.com/docs/deployments), [GitHub workflow syntax](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax), [fork pull-request permissions](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows).
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { validateDeployment } from '../scripts/deploy-ci.mjs';
|
||||
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' };
|
||||
assert.doesNotThrow(() => validateDeployment(env));
|
||||
for (const key of Object.keys(env)) assert.throws(() => validateDeployment({ ...env, [key]: '' }), new RegExp(key));
|
||||
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' }));
|
||||
});
|
||||
Reference in new issue
Block a user