Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"source": {
"source": "github",
"repo": "LasVegasForTransit/repository-tooling",
"ref": "v0.7.3"
"ref": "v0.7.6"
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions .lvbt/web-platform.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"formatVersion": 1,
"preset": "lvbt-web",
"release": "v0.7.3",
"commit": "c05e7739ef28e30e0e158d9a0e6af010007ad0f0",
"contentHash": "3b3b940f842c060203bdf2f309130f4cc0a7b3d42581b98d71614f8e356c3f9a",
"release": "v0.7.6",
"commit": "71bd6ea8a314417be4d85829480444bb61bba232",
"contentHash": "8533976f630e4836a9fa2cda0bc43616b646f577ef896118b50f1fe349ca245c",
"executables": [
"examples/with-astro/.githooks/commit-msg",
"examples/with-astro/.githooks/pre-commit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"source": {
"source": "github",
"repo": "LasVegasForTransit/repository-tooling",
"ref": "v0.7.3"
"ref": "v0.7.6"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"validate": "cf deploy --dry-run"
},
"devDependencies": {
"@lasvegasfortransit/eslint-config": "0.7.3",
"@lasvegasfortransit/eslint-config": "0.7.6",
"@lasvegasfortransit/site": "workspace:*",
"@lasvegasfortransit/typescript-config": "0.7.3",
"@lasvegasfortransit/typescript-config": "0.7.6",
"cf": "catalog:",
"eslint": "catalog:",
"typescript": "catalog:",
Expand Down
8 changes: 4 additions & 4 deletions .lvbt/web-platform/examples/with-astro/apps/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
},
"devDependencies": {
"@astrojs/check": "catalog:",
"@lasvegasfortransit/eslint-config": "0.7.3",
"@lasvegasfortransit/playwright-config": "0.7.3",
"@lasvegasfortransit/typescript-config": "0.7.3",
"@lasvegasfortransit/vitest-config": "0.7.3",
"@lasvegasfortransit/eslint-config": "0.7.6",
"@lasvegasfortransit/playwright-config": "0.7.6",
"@lasvegasfortransit/typescript-config": "0.7.6",
"@lasvegasfortransit/vitest-config": "0.7.6",
"@playwright/test": "catalog:",
"@types/node": "catalog:",
"eslint": "catalog:",
Expand Down
6 changes: 3 additions & 3 deletions .lvbt/web-platform/examples/with-astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"*": "prettier --write --ignore-unknown"
},
"devDependencies": {
"@lasvegasfortransit/cli": "0.7.3",
"@lasvegasfortransit/prettier-config": "0.7.3",
"@lasvegasfortransit/cli": "0.7.6",
"@lasvegasfortransit/prettier-config": "0.7.6",
"lint-staged": "catalog:",
"markdownlint-cli2": "catalog:",
"markdownlint-rule-relative-links": "catalog:",
Expand All @@ -39,7 +39,7 @@
"typescript": "catalog:",
"wrangler": "catalog:",
"tsx": "catalog:",
"@lasvegasfortransit/web-platform": "0.7.3"
"@lasvegasfortransit/web-platform": "0.7.6"
},
"packageManager": "pnpm@11.25.0",
"engines": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"source": {
"source": "github",
"repo": "LasVegasForTransit/repository-tooling",
"ref": "v0.7.3"
"ref": "v0.7.6"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"react-dom": "catalog:"
},
"devDependencies": {
"@lasvegasfortransit/eslint-config": "0.7.3",
"@lasvegasfortransit/playwright-config": "0.7.3",
"@lasvegasfortransit/typescript-config": "0.7.3",
"@lasvegasfortransit/vitest-config": "0.7.3",
"@lasvegasfortransit/eslint-config": "0.7.6",
"@lasvegasfortransit/playwright-config": "0.7.6",
"@lasvegasfortransit/typescript-config": "0.7.6",
"@lasvegasfortransit/vitest-config": "0.7.6",
"@playwright/test": "catalog:",
"@tailwindcss/vite": "catalog:",
"@types/node": "catalog:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"validate": "cf deploy --dry-run"
},
"devDependencies": {
"@lasvegasfortransit/eslint-config": "0.7.3",
"@lasvegasfortransit/eslint-config": "0.7.6",
"@lasvegasfortransit/app": "workspace:*",
"@lasvegasfortransit/typescript-config": "0.7.3",
"@lasvegasfortransit/typescript-config": "0.7.6",
"cf": "catalog:",
"eslint": "catalog:",
"typescript": "catalog:",
Expand Down
6 changes: 3 additions & 3 deletions .lvbt/web-platform/examples/with-vite-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"*": "prettier --write --ignore-unknown"
},
"devDependencies": {
"@lasvegasfortransit/cli": "0.7.3",
"@lasvegasfortransit/prettier-config": "0.7.3",
"@lasvegasfortransit/cli": "0.7.6",
"@lasvegasfortransit/prettier-config": "0.7.6",
"lint-staged": "catalog:",
"markdownlint-cli2": "catalog:",
"markdownlint-rule-relative-links": "catalog:",
Expand All @@ -38,7 +38,7 @@
"typescript": "catalog:",
"wrangler": "catalog:",
"tsx": "catalog:",
"@lasvegasfortransit/web-platform": "0.7.3"
"@lasvegasfortransit/web-platform": "0.7.6"
},
"packageManager": "pnpm@11.25.0",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion .lvbt/web-platform/packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lasvegasfortransit/cli",
"version": "0.7.3",
"version": "0.7.6",
"description": "The lvbt command every LVBT repository runs for bootstrap, preflight, and deploy, plus the production platform setup, the shared git hooks, and the lvbt-contributions agent plugin.",
"license": "MIT",
"type": "module",
Expand Down
19 changes: 19 additions & 0 deletions .lvbt/web-platform/packages/cli/platform.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,25 @@
"governance": {
"type": "boolean",
"description": "Report organization governance using the shared policy; new requirements warn in 0.7."
},
"environments": {
"type": "array",
"description": "Release environments restricted to one selected branch, without changing existing reviewer or timer protections.",
"items": {
"type": "object",
"additionalProperties": false,
"required": ["name", "branch"],
"properties": {
"name": {
"type": "string",
"pattern": "^[A-Za-z0-9_-]+$"
},
"branch": {
"type": "string",
"pattern": "^[A-Za-z0-9_/-]+$"
}
}
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lvbt-contributions",
"version": "0.7.3",
"version": "0.7.6",
"description": "Create readable LVBT contributions and reconcile trusted audit and recurring issues through the organization workflow.",
"author": {
"name": "Las Vegans for Better Transit",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lvbt-contributions",
"version": "0.7.3",
"version": "0.7.6",
"description": "Create readable LVBT contributions and reconcile trusted audit and recurring issues through the organization workflow.",
"author": {
"name": "Las Vegans for Better Transit",
Expand Down
1 change: 1 addition & 0 deletions .lvbt/web-platform/packages/cli/src/lib/arguments.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const flags = new Set([
]);
const valued = new Set([
'--action',
'--workflow',
'--pr',
'--publication-mode',
'--protection',
Expand Down
28 changes: 27 additions & 1 deletion .lvbt/web-platform/packages/cli/src/lib/platform/apply.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'node:path';
import { reconcileBranchPolicy } from './branch-policy.mjs';
import { varGuide } from './guides.mjs';
import { SETUP } from './plan.mjs';
import { paint } from './terminal.mjs';
Expand Down Expand Up @@ -88,6 +89,29 @@ async function createBucket(context, action) {

async function createEnvironment(context, action) {
const repository = context.manifest.github.repository;
if (action.branch) {
const call = (args, input) => {
const result = context.run('gh', ['api', ...args], {
cwd: context.directory,
...(input ? { input: JSON.stringify(input) } : {}),
});
if (!input && result.status !== 0 && /HTTP 404/.test(result.stderr)) return null;
succeeded(result);
return result.stdout ? JSON.parse(result.stdout) : undefined;
};
await reconcileBranchPolicy(
`repos/${repository}/environments/${action.environment}`,
action.branch,
{
read: async (endpoint) => call([endpoint]),
write: async (method, endpoint, body) => {
call(['--method', method, endpoint, '--input', '-'], body);
},
},
);
context.io.write(`Restricted ${action.environment} to branch ${action.branch}.\n`);
return;
}
succeeded(
context.run(
'gh',
Expand Down Expand Up @@ -161,7 +185,9 @@ export function describeAction(entry) {
case 'access.update':
return `fix the Access application ${action.app.name}`;
case 'github.environment':
return `create the GitHub environment ${action.environment}`;
return action.branch
? `restrict GitHub ${action.environment} to branch ${action.branch}`
: `create the GitHub environment ${action.environment}`;
case 'secret.put':
return `${action.source.type === 'prompt' ? 'ask for' : 'store'} ${action.secret.name} on ${action.target === 'worker' ? 'the Worker' : `GitHub ${action.target.slice(7)}`}`;
case 'secret.delete':
Expand Down
45 changes: 45 additions & 0 deletions .lvbt/web-platform/packages/cli/src/lib/platform/branch-policy.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { isDeepStrictEqual } from 'node:util';
const selectedPolicy = { protected_branches: false, custom_branch_policies: true };
export function hasBranchPolicy(value, branch) {
return (
isDeepStrictEqual(value?.deployment_branch_policy, selectedPolicy) &&
value?.branch_policies?.length === 1 &&
value.branch_policies[0].name === branch &&
value.branch_policies[0].type === 'branch'
);
}
export async function reconcileBranchPolicy(endpoint, branch, { read, write }) {
const current = await read(endpoint);
const branchEndpoint = `${endpoint}/deployment-branch-policies`;
const branches = current?.deployment_branch_policy?.custom_branch_policies
? (await read(branchEndpoint)).branch_policies
: [];
if (
branches.some((item) => item.name !== branch || item.type !== 'branch') ||
branches.length > 1
)
throw new Error('Unexpected deployment branch policies require review.');
if (!isDeepStrictEqual(current?.deployment_branch_policy, selectedPolicy)) {
await write('PUT', endpoint, {
deployment_branch_policy: selectedPolicy,
...approvalFields(current),
});
}
const latest = await read(endpoint);
if (!isDeepStrictEqual(latest.deployment_branch_policy, selectedPolicy))
throw new Error('Environment policy changed while restricting its branch.');
const found = (await read(branchEndpoint)).branch_policies;
if (found.length === 0) await write('POST', branchEndpoint, { name: branch, type: 'branch' });
else if (!hasBranchPolicy({ ...latest, branch_policies: found }, branch))
throw new Error('Deployment branch policy changed during setup.');
}

function approvalFields(current) {
const rules = current?.protection_rules ?? [];
const review = rules.find((rule) => rule.type === 'required_reviewers');
return {
wait_timer: rules.find((rule) => rule.type === 'wait_timer')?.wait_timer ?? 0,
prevent_self_review: review?.prevent_self_review ?? false,
reviewers: (review?.reviewers ?? []).map(({ type, reviewer }) => ({ type, id: reviewer.id })),
};
}
13 changes: 10 additions & 3 deletions .lvbt/web-platform/packages/cli/src/lib/platform/manifest.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { secretForTarget, scopedSecretErrors } from './secret-scope.mjs';
import { secretForTarget, secretTargets, scopedSecretErrors } from './secret-scope.mjs';
import { validateAgainstSchema } from './schema.mjs';
import { cloudflareWorkerBindings, wranglerWorkerBindings } from './worker-bindings.mjs';

Expand Down Expand Up @@ -197,9 +197,16 @@ function secretErrors(manifest) {

function forbiddenErrors(manifest) {
const errors = [];
const declared = new Set([...names(manifest.secrets), ...names(manifest.vars)]);
const declared = [...(manifest.secrets ?? []), ...(manifest.vars ?? [])];
for (const entry of manifest.forbidden ?? []) {
if (declared.has(entry.name)) errors.push(`${entry.name} is both required and forbidden.`);
if (
declared.some(
(required) =>
required.name === entry.name &&
secretTargets(required).some((target) => secretTargets(entry).includes(target)),
)
)
errors.push(`${entry.name} is both required and forbidden.`);
if (targetsGithub(entry) && !manifest.github)
errors.push(
`forbidden ${entry.name} targets a GitHub environment, so github.repository is required.`,
Expand Down
22 changes: 21 additions & 1 deletion .lvbt/web-platform/packages/cli/src/lib/platform/observe.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const SQL_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;

export function githubEnvironments(manifest) {
const targets = [
...(manifest.github?.environments ?? []).map((entry) => `github:${entry.name}`),
...(manifest.secrets ?? []).flatMap((secret) => secret.targets ?? []),
...(manifest.forbidden ?? []).flatMap((entry) => entry.targets ?? []),
...(manifest.github?.variables ?? []).flatMap((entry) =>
Expand Down Expand Up @@ -167,12 +168,22 @@ async function observeGithub(run, cwd, manifest) {
if (environments.length === 0 && !manifest.github?.variables?.length)
return known({ environments: [], secrets: {}, variables: known({}) });
const repository = manifest.github.repository;
const value = { environments: [], secrets: {} };
const value = { environments: [], secrets: {}, policies: {} };
for (const environment of environments) {
const exists = githubRead(run, cwd, ['api', `repos/${repository}/environments/${environment}`]);
if (!exists.ok && !exists.missing) return unknown(`gh: ${exists.reason}`, 'unauthorized');
if (!exists.ok) continue;
value.environments.push(environment);
if ((manifest.github?.environments ?? []).some((entry) => entry.name === environment)) {
const policy = observeBranchPolicy(
run,
cwd,
`repos/${repository}/environments/${environment}`,
JSON.parse(exists.stdout),
);
if (!policy.ok) return unknown(`gh: ${policy.reason}`, 'unauthorized');
value.policies[environment] = policy.value;
}
const listed = githubRead(run, cwd, [
'secret',
'list',
Expand Down Expand Up @@ -305,3 +316,12 @@ export async function observePlatform({ manifest, directory, apis, run, resolve,
github: await observeGithub(run, directory, manifest),
};
}

function observeBranchPolicy(run, cwd, endpoint, details) {
if (!details.deployment_branch_policy?.custom_branch_policies)
return known({ ...details, branch_policies: [] });
const listed = githubRead(run, cwd, ['api', `${endpoint}/deployment-branch-policies`]);
return listed.ok
? known({ ...details, branch_policies: JSON.parse(listed.stdout).branch_policies })
: listed;
}
17 changes: 15 additions & 2 deletions .lvbt/web-platform/packages/cli/src/lib/platform/plan-values.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { hasBranchPolicy } from './branch-policy.mjs';
import { secretTargets } from './secret-scope.mjs';
import {
configVarEntry,
Expand All @@ -21,14 +22,26 @@ export function planGithubEnvironments({ manifest, state }) {
label: `environment ${environment}`,
};
if (!state.github.ok) return unknownItem({ ...fields, credentialHint: GH_HINT }, state.github);
if (state.github.value.environments.includes(environment))
const branch = manifest.github?.environments?.find(
(entry) => entry.name === environment,
)?.branch;
const present = state.github.value.environments.includes(environment);
if (present && branch && !hasBranchPolicy(state.github.value.policies?.[environment], branch))
return item({
...fields,
status: 'missing',
detail: `must accept only branch ${branch}`,
next: `${SETUP} restricts its deployment branch`,
action: { type: 'github.environment', environment, branch },
});
if (present)
return item({ ...fields, status: 'ok', detail: `exists in ${manifest.github.repository}` });
return item({
...fields,
status: 'missing',
detail: `does not exist in ${manifest.github.repository}`,
next: `${SETUP} creates it`,
action: { type: 'github.environment', environment },
action: { type: 'github.environment', environment, ...(branch ? { branch } : {}) },
});
});
}
Expand Down
Loading
Loading