Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
99d034b
Test: a template file rendered once per item of a list (each)
davidjalbers Dec 6, 2026
982338d
plx-template renders a file once per item of a list: each, with _item
davidjalbers Dec 6, 2026
7e31cd6
Test: a stack is born with a file for each declared environment, and …
davidjalbers Dec 6, 2026
6340799
A stack is born with a file for each declared environment; every rend…
davidjalbers Dec 6, 2026
e8cc6fb
Test the workflows rendered from the declared environments
davidjalbers Dec 6, 2026
d3485bb
Test that an app repo without a declared environment has no on_push
davidjalbers Dec 6, 2026
e003896
Render the workflows from the declared environments
davidjalbers Dec 6, 2026
301e32c
Test plx-ci setup promote and the job deploy refused off an environme…
davidjalbers Dec 6, 2026
87944f6
plx-ci setup promote, and the job deploy refused off an environment's…
davidjalbers Dec 6, 2026
e51cd70
Test that plx deploy --environment refuses a name the repo does not d…
davidjalbers Dec 6, 2026
f5571c5
plx deploy --environment refuses a name the repo does not declare
davidjalbers Dec 6, 2026
c2e6af3
Test that the templates render without the computed declaration
davidjalbers Dec 6, 2026
5db1f66
The templates read the computed declaration with an empty default
davidjalbers Dec 6, 2026
1a089b9
Test what taking the version does to the workflow that deploys
davidjalbers Dec 6, 2026
77d71c3
Read the declared workflows of a newborn app repo of their own
davidjalbers Dec 6, 2026
70b13fc
Test each through a merge, and the paths an item may name
davidjalbers Dec 6, 2026
709a4b4
Say in the header of files.ts what an item of each may name
davidjalbers Dec 6, 2026
ea9b709
Derive the names a workflow's condition must not hold from the declar…
davidjalbers Dec 6, 2026
3251371
Say what a promotion promotes, and why its token and the vault's
davidjalbers Dec 6, 2026
c89e2bd
Say why the promotion is handed the vault's token: a repo that deploy…
davidjalbers Dec 6, 2026
0743777
Say only that a deploying repo's App credentials may be in the vault,…
davidjalbers Dec 6, 2026
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
4 changes: 2 additions & 2 deletions newborns/app-nextjs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import {
born,
bornStacks,
close,
ENVIRONMENTS,
freePort,
git,
open,
pass,
plxNew,
put,
relock,
STACK_FILE_ENVIRONMENTS,
sh,
start,
tryRun,
Expand All @@ -58,7 +58,7 @@ before(async () => {
here = await open('app-nextjs');
repo = await born(join(here, 'acme'), ['repo-turbo', 'updates'], {
tenant: 'acme',
environments: STACK_FILE_ENVIRONMENTS,
environments: ENVIRONMENTS,
});
for (const profile of PROFILES)
await born(join(repo, 'apps', profile), ['app-nextjs'], {
Expand Down
10 changes: 7 additions & 3 deletions newborns/deploy-job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { createServer, type Server } from 'node:http';
import { basename, join } from 'node:path';
import { after, before, test } from 'node:test';
import { parse } from 'yaml';
import { born, builtVersion, close, git, open, put, type Ran, sh, tryRun } from './helpers.ts';
import { born, builtVersion, close, ENVIRONMENTS, git, open, put, type Ran, sh, tryRun } from './helpers.ts';

/** The variable the repo's [env] sets: what the job deploy must not export. */
const VARIABLE = 'PLX_DEPLOY_JOB_PROBE';
Expand Down Expand Up @@ -68,7 +68,11 @@ let slotContainer = '';

before(async () => {
here = await open('deploy-job');
repo = await born(join(here, 'web'), ['repo-turbo'], { tenant: 'acme', ci_strategy: 'byom' });
repo = await born(join(here, 'web'), ['repo-turbo'], {
tenant: 'acme',
ci_strategy: 'byom',
environments: ENVIRONMENTS,
});
// A project for [monorepo].config_roots to match, as the apps of a real repo are: the job repo's step installs by them.
put(repo, { 'packages/probe/package.json': { name: '@acme/probe', private: true } });
const workflow = parse(readFileSync(join(repo, '.github', 'workflows', 'on_push.yml'), 'utf8'));
Expand Down Expand Up @@ -199,7 +203,7 @@ function actionEnv(dir: string, temp: string, inputs: Record<string, unknown>):
GITHUB_OUTPUT: files.output as string,
GITHUB_STATE: files.state as string,
GITHUB_REPOSITORY: 'acme/web',
GITHUB_REF: 'refs/heads/develop',
GITHUB_REF: 'refs/heads/env/staging',
GITHUB_SHA: '0'.repeat(40),
};
}
Expand Down
4 changes: 2 additions & 2 deletions newborns/e2e-playwright.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ import {
born,
bornStacks,
close,
ENVIRONMENTS,
git,
type Launched,
launch,
open,
put,
relock,
STACK_FILE_ENVIRONMENTS,
sh,
tryRun,
until,
Expand Down Expand Up @@ -227,7 +227,7 @@ async function newborn(
): Promise<string> {
const dir = await born(join(here, name), ['repo-turbo', 'updates'], {
tenant: 'acme',
environments: STACK_FILE_ENVIRONMENTS,
environments: ENVIRONMENTS,
...answers,
});
await bornStacks(
Expand Down
8 changes: 4 additions & 4 deletions newborns/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,11 @@ export async function born(
}

/**
* The `stack` template writes `production.yaml` and `staging.yaml` by name while the repo declares no environment,
* so a newborn with a stack fails `PLX-Stack/FileNamesDeclared`: the repos that must pass the doctor declare the
* two names. The stack template is to render the files from the declaration, which removes this.
* The environments of a newborn that deploys, as `plx new -a` gives them: staging, which promotes itself from main,
* and production, promoted by hand from staging. Its stacks are born with a file for each.
*/
export const STACK_FILE_ENVIRONMENTS = '{staging: {promotes_from: main}, production: {promotes_from: staging}}';
export const ENVIRONMENTS =
'{staging: {promotes_from: main, auto_promote: true}, production: {promotes_from: staging}}';

/**
* The stacks of a newborn app repo, each created by `plx new` from the template `stack` with its profile and the
Expand Down
19 changes: 4 additions & 15 deletions newborns/pipeline.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// A newborn app repo through the job repo of its on_push.yml: the steps as the
// rendered workflow lists them, read out of the job's own checkout, each run
// here in its order, as a job of the forge (GITHUB_ACTIONS=true) on a push to
// develop, by the walk of jobs.ts. The workflow itself runs only on the forge;
// env/staging, by the walk of jobs.ts. The workflow itself runs only on the forge;
// what of a step this file stands in for:
//
// actions/checkout a fresh clone of the repo's origin at the pushed commit
Expand Down Expand Up @@ -38,18 +38,7 @@ import { join } from 'node:path';
import { after, before, test } from 'node:test';
import { parse } from 'yaml';
import { type Caches, startCaches } from './caches.ts';
import {
born,
bornStacks,
close,
freePort,
open,
put,
relock,
STACK_FILE_ENVIRONMENTS,
sh,
tryRun,
} from './helpers.ts';
import { born, bornStacks, close, ENVIRONMENTS, freePort, open, put, relock, sh, tryRun } from './helpers.ts';
import { type Done, gitOk, of, type Step, walk } from './jobs.ts';

const BROWSERS = join(import.meta.dirname, '..', 'node_modules', '.cache', 'ms-playwright');
Expand Down Expand Up @@ -91,7 +80,7 @@ before(async () => {
GITHUB_REPOSITORY: 'acme/web',
GITHUB_ACTOR: 'a-maintainer',
GITHUB_EVENT_NAME: 'push',
GITHUB_REF_NAME: 'develop',
GITHUB_REF_NAME: 'env/staging',
// A slot of the runner host names its host's servers and carries their tokens.
PLX_TURBO_SHARED: `http://127.0.0.1:${sharedPort}`,
PLX_TURBO_SHARED_TOKEN: 'a-shared-token',
Expand All @@ -107,7 +96,7 @@ before(async () => {
tenant: 'acme',
repo: 'web',
ci_strategy: 'byom',
environments: STACK_FILE_ENVIRONMENTS,
environments: ENVIRONMENTS,
});
await born(join(repo, 'apps', 'web'), ['app-nextjs'], { name: '@acme/web' });
await born(join(repo, 'e2e', 'web'), ['e2e-playwright'], { app: '@acme/web' });
Expand Down
9 changes: 5 additions & 4 deletions newborns/repo-operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ import {
born,
bornStacks,
close,
ENVIRONMENTS,
git,
mise,
open,
pass,
put,
STACK_FILE_ENVIRONMENTS,
sh,
tryRun,
} from './helpers.ts';
Expand Down Expand Up @@ -537,7 +537,7 @@ interface DeployStep {
test('the job deploy of a newborn operations repo deploys two stacks of third-party software through its own steps, and one that fails leaves the other deployed', async () => {
const dir = await born(join(here, 'deploy-job'), ['repo-operations', 'updates'], {
tenant: 'acme',
environments: STACK_FILE_ENVIRONMENTS,
environments: ENVIRONMENTS,
});
const root = join(here, 'deploy-run');
const bin = runnerTools(root);
Expand Down Expand Up @@ -565,7 +565,7 @@ test('the job deploy of a newborn operations repo deploys two stacks of third-pa
GITHUB_ACTOR: 'a-maintainer',
GITHUB_RUN_ID: '41',
GITHUB_EVENT_NAME: 'push',
GITHUB_REF_NAME: 'main',
GITHUB_REF_NAME: 'env/production',
RUNNER_TEMP: temp,
RUNNER_ENVIRONMENT: 'self-hosted',
LOGS: logs,
Expand Down Expand Up @@ -616,7 +616,8 @@ test('the job deploy of a newborn operations repo deploys two stacks of third-pa

/** The verb step of the workflow, run as the forge runs it: its command, and its environment with the input `dry_run` given as `input`. */
const verb = async (input: string) => {
const step = steps.find((s) => /\bplx deploy --environment production$/.test(s.run ?? ''));
// The verb deploys the environment of the branch the run is on, env/production.
const step = steps.find((s) => /\bplx deploy$/.test(s.run ?? ''));
assert.ok(step?.run, 'the workflow has the verb step');
const env = envOf(step, { '${{ inputs.dry_run }}': input });
return tryRun('mise', ['exec', '--', ...step.run.split(' ')], dir, { ...jobEnv, ...env });
Expand Down
70 changes: 66 additions & 4 deletions newborns/repo-turbo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
// mise run newborn # every template
// KEEP=1 mise run newborn # leave the newborns in place and say where
import assert from 'node:assert/strict';
import { readFileSync, writeFileSync } from 'node:fs';
import { readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { after, before, describe, test } from 'node:test';
import { born, close, git, mise, open, pass, put, relock, sh, tryRun } from './helpers.ts';
import { parse } from 'yaml';
import { born, close, ENVIRONMENTS, git, mise, open, pass, put, relock, sh, tryRun } from './helpers.ts';

let here = '';
before(async () => {
Expand Down Expand Up @@ -71,15 +72,20 @@ function projects(dir: string, specs: Record<string, { verbs: string[]; needs?:
});
}

/** The workflow `name` of `dir`, parsed. */
const workflow = (dir: string, name: string) => parse(read(dir, `.github/workflows/${name}.yml`));

/** The workflows of `dir` by file name. */
const workflows = (dir: string) => readdirSync(join(dir, '.github', 'workflows')).sort();

describe('an app repo', () => {
let dir = '';
before(async () => {
dir = await newborn('app');
});

test('passes its own verbs, and its push workflow writes no tag', async () => {
test('passes its own verbs', async () => {
await passesItsVerbs(dir, 'app');
assert.doesNotMatch(read(dir, '.github/workflows/on_push.yml'), /contents: write/);
});

test('scopes a verb to a project by name: with what it depends on, e2e with what depends on it, and refuses an unknown name', async () => {
Expand Down Expand Up @@ -117,6 +123,62 @@ describe('an app repo', () => {
}
});
});
// A repo that declares its environments: its workflows are read, and its verbs are not run, since it has no stack,
// of which `plx doctor` asks a file for each environment.
describe('an app repo that declares its environments', () => {
let dir = '';
before(async () => {
dir = await newborn('declared', { environments: ENVIRONMENTS });
});

test('runs on_push on the branch of each declared environment and on_commit on every other, and promotes staging from main after a green run there', () => {
const branches = ['env/staging', 'env/production'];
assert.deepEqual(workflow(dir, 'on_push').on.push, { branches });
assert.doesNotMatch(
read(dir, '.github/workflows/on_push.yml'),
/contents: write/,
'its push workflow writes no tag',
);
assert.deepEqual(workflow(dir, 'on_commit').on.push['branches-ignore'], branches);
assert.deepEqual(workflows(dir), [
'on_commit.yml',
'on_pr.yml',
'on_push.yml',
'plx-update.yml',
'promote-staging.yml',
]);
const promotion = workflow(dir, 'promote-staging');
assert.deepEqual(promotion.on.workflow_run, {
workflows: ['on_commit', 'on_push'],
types: ['completed'],
branches: ['main'],
});
assert.equal(promotion.jobs.promote.steps.at(-1).run, 'plx -y promote staging');
});

test('promoting an environment from another one instead renders the same workflow, with the other two branch names', async () => {
const other = await newborn('promotes-from-staging', {
environments: '{staging: {promotes_from: main}, production: {promotes_from: staging, auto_promote: true}}',
});
assert.deepEqual(workflows(other), [
'on_commit.yml',
'on_pr.yml',
'on_push.yml',
'plx-update.yml',
'promote-production.yml',
]);
assert.deepEqual(workflow(other, 'promote-production').on.workflow_run.branches, ['env/staging']);
assert.equal(
read(other, '.github/workflows/promote-production.yml'),
read(dir, '.github/workflows/promote-staging.yml')
.replaceAll('branches: [main]', 'branches: [env/staging]')
.replaceAll('promote-staging', 'promote-production')
.replaceAll('promote staging', 'promote production')
.replaceAll('env/staging to the head of main', 'env/production to the head of env/staging')
.replaceAll('on main, the branch staging promotes from', 'on env/staging, the branch production promotes from'),
);
});
});

test('publish runs the publish of every project after its build, never cached, then every app’s image, and no other verb; a name is ignored', async () => {
const dir = await newborn('publishing-app');
Expand Down
Loading