Skip to content
5 changes: 5 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ env = { NEWBORN_TARBALLS = "{{config_root}}/node_modules/.cache/newborn-tarballs
# run's own on disk, which it removes (newborns/scratch.ts).
run = ["node newborns/pack.ts", "node newborns/scratch.ts node --test newborns/*.test.ts"]

[tasks.publish]
description = "No-op: the packages are published by the release of a version, which `mise ship` cuts; a name is accepted and ignored"
usage = 'arg "[name]" hide=#true'
run = 'echo "publish: nothing to publish from a checkout of tooling"'

# The upstream's verb (§ 1.5 PLX)

[tasks.ship]
Expand Down
6 changes: 3 additions & 3 deletions newborns/repo-operations.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// A newborn operations repo, born as a repo is with updates beside its
// template, passes its own five verbs, with `plx doctor`, lint and the playbooks'
// template, passes its own six verbs, with `plx doctor`, lint and the playbooks'
// syntax in `check`, in each shape that changes what is generated; the collections go
// into the scratch directory, not into ~/.ansible. Created by `plx new`; it
// needs the network (`mise install`, the collections).
Expand All @@ -20,10 +20,10 @@ const SHAPES: [string, Record<string, string>][] = [
];

/** The verbs a repo answers with a verdict, each from the checkout as it is. */
const VERBS = ['dev', 'build', 'check', 'test', 'e2e'];
const VERBS = ['dev', 'build', 'check', 'test', 'e2e', 'publish'];

for (const [name, answers] of SHAPES)
test(`a newborn operations repo (${name}) passes its own five verbs`, async () => {
test(`a newborn operations repo (${name}) passes its own six verbs`, async () => {
const env = { ANSIBLE_COLLECTIONS_PATH: join(here, 'collections') };
const dir = await born(join(here, name), ['repo-operations', 'updates'], { tenant: 'acme', ...answers }, env);
for (const verb of VERBS) await pass(dir, name, verb, env);
Expand Down
68 changes: 53 additions & 15 deletions newborns/repo-turbo.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// A newborn repo of the Turborepo template, born as a repo is with updates
// beside its template, passes its own four verdicts (`check`, `test`, `build`,
// `e2e`) in each shape that changes what is generated: an app repo, a package
// repo, each also with the tenant's private packages, an app repo also with
// display versions, and one repo with the answer `postgres`, which installs
// the binary and shows its version. `check`, `build` and `test` scope to an
// app or a package by name with what it depends on, `e2e` with what depends on
// it, and each refuses an unknown name. Editing a test file moves the hash of
// `test` and leaves the hash of `build`; the answer's major moves `test` and
// `e2e` and nothing else. The pre-commit hook fixes a format error and accepts
// the commit, and refuses it without `depends = "lint"`. `mise e2e` works first
// in a fresh clone. A package repo also has what a release needs: a workspace
// package with a pending changeset passes `test`, scoped to it by name, and
// `changeset version` takes the changeset in, with a changelog that `check`
// then accepts. Created by `plx new`; it needs the network (`mise install`,
// beside its template, passes its own five verdicts (`check`, `test`, `build`,
// `e2e`, `publish`) in each shape that changes what is generated: an app repo,
// a package repo, each also with the tenant's private packages, an app repo
// also with display versions, and one repo with the answer `postgres`, which
// installs the binary and shows its version. `check`, `build` and `test` scope
// to an app or a package by name with what it depends on, `e2e` with what
// depends on it, and each refuses an unknown name; `publish` runs an app's
// publish script after its own build and no other verb. Editing a test file
// moves the hash of `test` and leaves the hash of `build`; the answer's major
// moves `test` and `e2e` and nothing else. The pre-commit hook fixes a format
// error and accepts the commit, and refuses it without `depends = "lint"`.
// `mise e2e` works first in a fresh clone. A package repo also has what a
// release needs: a workspace package with a pending changeset passes `test`,
// scoped to it by name, and `changeset version` takes the changeset in, with a
// changelog that `check` then accepts. Created by `plx new`; it needs the network (`mise install`,
// `pnpm add`).
//
// mise run newborn # every template
Expand All @@ -39,7 +40,7 @@ async function newborn(name: string, answers: Record<string, string> = {}): Prom
const read = (dir: string, file: string) => readFileSync(join(dir, file), 'utf8');

/** The verbs a repo answers with a verdict, each from the checkout as it is. */
const VERDICTS = ['check', 'test', 'build', 'e2e'];
const VERDICTS = ['check', 'test', 'build', 'e2e', 'publish'];

async function passesItsVerbs(dir: string, name: string): Promise<void> {
for (const verb of VERDICTS) await pass(dir, name, verb);
Expand Down Expand Up @@ -114,6 +115,43 @@ describe('an app repo', () => {
});
});

test('publish runs the publish of an app after its build, never cached, and no other verb', async () => {
const dir = await newborn('publishing-app');
put(dir, {
'apps/shipped/package.json': {
name: 'shipped',
version: '0.0.0',
private: true,
scripts: {
build: 'echo build-ran apps/shipped',
check: 'echo check-ran apps/shipped',
test: 'echo test-ran apps/shipped',
e2e: 'echo e2e-ran apps/shipped',
publish: 'echo publish-ran apps/shipped',
},
},
'apps/other/package.json': {
name: 'other',
version: '0.0.0',
private: true,
scripts: { build: 'echo build-ran apps/other', publish: 'echo publish-ran apps/other' },
},
});
await relock(dir);
for (const again of [1, 2]) {
const ran = await mise(dir, 'publish', 'shipped');
assert.ok(ran.ok, ran.output);
assert.match(
ran.output,
/build-ran apps\/shipped[\s\S]*publish-ran apps\/shipped/,
`its build, then it (${again})`,
);
assert.doesNotMatch(ran.output, /(check|test|e2e)-ran|apps\/other/, 'no other verb, no other app');
}
const all = await mise(dir, 'publish');
assert.match(all.output, /publish-ran apps\/other/, 'without a name, every project');
});

test('in a repo with one app, editing a test file moves the hash of test and leaves the hash of build', async () => {
// A repo of its own: the app has no marker or compose file, which only a run of plx doctor would ask for.
const dir = await newborn('one-app');
Expand Down
10 changes: 5 additions & 5 deletions newborns/turbo-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
// the stand-in's keys. With the trusted server, `build` and `e2e` write the
// trusted bucket and the shared server sees no request; `check` and `test` find
// no shared server in that job and run without one. With both servers in one
// checkout, a build after a test reads nothing of the local cache the test
// filled. Where the tenant has no bucket the verbs run without a remote cache;
// without the step `build` fails. Every case sets or unsets GITHUB_ACTIONS
// checkout, a build after a test replays nothing, and the test built nothing.
// Where the tenant has no bucket the verbs run without a remote cache; without
// the step `build` fails. Every case sets or unsets GITHUB_ACTIONS
// itself.
// Jobs of one runner host share its loopback: eight that run the whole step from its action.yml at the same instant, the pinned action's own code starting each server, each get a server of their own.
// It takes the job's token and refuses every other job's.
Expand Down Expand Up @@ -257,12 +257,12 @@ describe('a newborn app repo with the two remote caches', () => {
assert.equal(requests(sharedLog).length, before, 'the shared server saw no request from the job');
});

test('in a job with both servers, a build after a test in one checkout reads nothing the test left in the local cache', async () => {
test('in a job with both servers, a build after a test in one checkout replays nothing, and the test built nothing', async () => {
// A repo of its own name, so that neither bucket holds its tasks yet.
const job = await clone(origin, 'one-checkout', 'https://github.com/acme/one-checkout');
const env = { GITHUB_ACTIONS: 'true', CI: 'true', ...(await jobServer('shared')), ...(await jobServer('trusted')) };
const tested = await verb(job, 'test', env);
assert.match(tested, missed('lib:build'), 'the test built lib, into the local cache');
assert.doesNotMatch(tested, /lib:build/, 'in an app repo the test waits for no build');
const built = await verb(job, 'build', env);
assert.doesNotMatch(built, /cache hit/, 'nothing replayed');
assert.match(built, missed('lib:build'));
Expand Down
13 changes: 8 additions & 5 deletions packages/lib/src/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ test('the checks are exactly the requirements the contract pages say doctor chec

// --- fixtures: a repo and its apps that pass every check -------------------------

/** The five repo verbs, as `plx doctor` asks for them. */
const VERBS = ['dev', 'build', 'check', 'test', 'e2e'];
/** The six repo verbs, as `plx doctor` asks for them. */
const VERBS = ['dev', 'build', 'check', 'test', 'e2e', 'publish'];

/** The hooks `hk.pkl` of a repo that meets PLX-Repo/Hooks wires. */
const HOOKS = ['pre-commit', 'pre-push'];
Expand All @@ -52,6 +52,7 @@ const ADVICE: Record<string, string> = {
check: "add one that runs the repo's static checks",
test: "add one that runs `check` and then the repo's tests",
e2e: NO_USE,
publish: NO_USE,
};
const noTask = (verb: string) => `no root mise task \`${verb}\`: ${ADVICE[verb]}`;

Expand Down Expand Up @@ -315,9 +316,9 @@ test('mise could not list the tasks: PLX-Repo/Verbs says why, once', () => {
]);
});

// --- the five verbs and the hooks ----------------------------------------------------
// --- the six verbs and the hooks ----------------------------------------------------

test('a repo with the five verbs passes, with or without a lint task; each one missing is a finding naming it', () => {
test('a repo with the six verbs passes, with or without a lint task; each one missing is a finding naming it', () => {
assert.deepEqual(findings(repo({ tasks: { names: VERBS } })), []);
for (const verb of VERBS)
assert.deepEqual(findings(repo({ tasks: { names: VERBS.filter((v) => v !== verb) } })), [
Expand Down Expand Up @@ -840,7 +841,7 @@ const ws = (): Tree => ({
},
});

/** What mise lists of a repo whose five verbs and lint exist. */
/** What mise lists of a repo whose six verbs and lint exist. */
const ALL_TASKS = [...VERBS, 'lint'];

async function doctorOver(
Expand Down Expand Up @@ -1139,6 +1140,7 @@ test("a task's alias counts as the task, as `mise run` finds it", async () => {
task('//:dev'),
task('//:build'),
task('//:e2e'),
task('//:publish'),
task('//:test'),
task('//:static', ['//:check']),
task('biome', ['lint']),
Expand All @@ -1156,6 +1158,7 @@ test("a task from a file the repo includes from outside counts by its `dir`; a p
JSON.stringify([
task('dev', '/ws/web/mise.toml', '/ws/web'),
task('build', '/shared/tasks.toml', '/ws/web'),
task('publish', '/ws/web/mise.toml', '/ws/web'),
task('e2e', '/ws/web/../shared/more.toml', '/ws/web'),
task('lint', '/ws/web/mise/tasks.toml', '/elsewhere'),
task('check', '/ws/mise.toml', '/ws'),
Expand Down
6 changes: 4 additions & 2 deletions packages/lib/src/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@
// apply` renders; otherwise the three are skipped and a hint says why (the
// version against the pin is reported beside, as before).
//
// The repo's verbs are the five of VERBS, root mise tasks: PLX-Repo/Verbs
// The repo's verbs are the six of VERBS, root mise tasks: PLX-Repo/Verbs
// reports each that is missing, and a task `verify`, which no repo has any
// more, with the tasks that replace it. Only the names of the tasks are read,
// never what a task runs: the order of the gates (`check`, `test`, `build`,
// `e2e`) is kept by the tasks, and no check reads it. PLX-Repo/Hooks is
// `e2e`, `publish`) is kept by the mise tasks and the workflows, and no check
// reads it. PLX-Repo/Hooks is
// existence only in the same way: `hk.pkl` wires a pre-commit and a pre-push
// hook (`hooksWired`), and what either runs is not read.
//
Expand Down Expand Up @@ -168,6 +169,7 @@ const VERBS: Readonly<Record<string, string>> = {
check: "add one that runs the repo's static checks",
test: "add one that runs `check` and then the repo's tests",
e2e: NO_USE,
publish: NO_USE,
};

function repoMarker(repo: RepoFacts): string[] {
Expand Down
11 changes: 6 additions & 5 deletions packages/lib/src/repoOperations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ test('a generated file says its template lives in tooling', async () => {
);
});

// --- the five verbs and the hooks (as repo-turbo has them) --------------------------------
// --- the six verbs and the hooks (as repo-turbo has them) --------------------------------

const SHAPES = [{}, { infrastructure: true, ci_strategy: 'hybrid' }, { ci_strategy: 'on-prem', ci_overlay: 'netbird' }];

test('a repo has the five verbs as root tasks, each taking an optional name, and no verify', async () => {
test('a repo has the six verbs as root tasks, each taking an optional name, and no verify', async () => {
for (const answers of SHAPES) {
const mise = textOf(await render(answers), 'mise.toml');
const tasks = tasksOf(mise);
for (const verb of ['dev', 'build', 'check', 'test', 'e2e']) {
for (const verb of ['dev', 'build', 'check', 'test', 'e2e', 'publish']) {
assert.ok(tasks.includes(verb), `${verb} ${JSON.stringify(answers)}`);
assert.match(taskOf(mise, verb), /^usage = .*\[name\]/m, verb);
}
Expand All @@ -171,9 +171,10 @@ test('no rendered file mentions verify', async () => {
}
});

test('dev, build and e2e are no-ops that pass; test runs check first and then has nothing to run', async () => {
test('dev, build, e2e and publish are no-ops that pass; test runs check first and then has nothing to run', async () => {
const mise = textOf(await render(), 'mise.toml');
for (const verb of ['dev', 'build', 'e2e']) assert.match(runOf(mise, verb), /^run = 'echo "\w+: nothing/, verb);
for (const verb of ['dev', 'build', 'e2e', 'publish'])
assert.match(runOf(mise, verb), /^run = 'echo "\w+: nothing/, verb);
assert.match(runOf(mise, 'test'), /^run = \[\s*'mise run check',\s*'echo "test: nothing/);
assert.doesNotMatch(runOf(mise, 'e2e'), /mise run/, 'e2e runs alone');
});
Expand Down
38 changes: 34 additions & 4 deletions packages/lib/src/repoTurbo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ test('no turbo input names an answers file', async () => {
assert.doesNotMatch(textOf(await render(), 'turbo.json'), /answers/);
});

// The five verbs, the task graph and the hooks (§ 1 and § 6 of the decisions, PLX-Repo).
// The six verbs, the task graph and the hooks (§ 1 and § 6 of the decisions, PLX-Repo).

/** The tasks of a rendered `turbo.json`. */
const turboOf = (result: Awaited<ReturnType<typeof render>>) =>
Expand All @@ -185,11 +185,11 @@ const turboOf = (result: Awaited<ReturnType<typeof render>>) =>

const SHAPES = [{}, { publishes_packages: true }];

test('a repo has the five verbs as root tasks, each taking an optional name, and no verify', async () => {
test('a repo has the six verbs as root tasks, each taking an optional name, and no verify', async () => {
for (const answers of SHAPES) {
const mise = textOf(await render(answers), 'mise.toml');
const tasks = tasksOf(mise);
for (const verb of ['dev', 'build', 'check', 'test', 'e2e']) {
for (const verb of ['dev', 'build', 'check', 'test', 'e2e', 'publish']) {
assert.ok(tasks.includes(verb), `${verb} ${JSON.stringify(answers)}`);
assert.match(taskOf(mise, verb), /^usage = .*\[name\]/m, verb);
}
Expand Down Expand Up @@ -233,15 +233,45 @@ test('e2e runs the e2e of Turbo alone: it neither tests nor checks', async () =>
}
});

test('publish runs the publish of Turbo in an app repo, and changeset publish in a package repo, and no other verb', async () => {
const app = runOf(textOf(await render(), 'mise.toml'), 'publish');
assert.match(app, /turbow trusted run publish/);
const packages = runOf(textOf(await render({ publishes_packages: true }), 'mise.toml'), 'publish');
assert.match(packages, /changeset publish/);
assert.doesNotMatch(packages, /turbow/);
for (const run of [app, packages])
assert.doesNotMatch(run, /mise run|turbow \w+ run (check|test|build|e2e)/, 'publish runs no other verb');
});

test('the dependsOn of the graph hold data dependencies only', async () => {
for (const answers of SHAPES) {
const tasks = turboOf(await render(answers));
for (const task of ['build', 'check', 'test', 'e2e']) assert.deepEqual(tasks[task]?.dependsOn, ['^build'], task);
for (const task of ['build', 'e2e']) assert.deepEqual(tasks[task]?.dependsOn, ['^build'], task);
assert.equal(tasks.dev?.cache, false);
assert.equal(tasks.dev?.dependsOn, undefined);
}
});

test('check and test wait for no build in an app repo, whose packages export their source, and for the packages’ in a package repo', async () => {
const app = turboOf(await render());
const packages = turboOf(await render({ publishes_packages: true }));
for (const task of ['check', 'test']) {
assert.equal(app[task]?.dependsOn, undefined, `${task} of an app repo`);
assert.deepEqual(packages[task]?.dependsOn, ['^build'], `${task} of a package repo`);
}
});

test('publish is never cached and waits for the build of its own project only, in an app repo', async () => {
const tasks = turboOf(await render());
assert.equal(tasks.publish?.cache, false);
assert.deepEqual(tasks.publish?.dependsOn, ['build']);
assert.equal(
turboOf(await render({ publishes_packages: true })).publish,
undefined,
'a package repo has no Turbo publish',
);
});

test('test files are no input of build, and are an input of check and test', async () => {
const tasks = turboOf(await render());
assert.deepEqual(
Expand Down
5 changes: 5 additions & 0 deletions templates/repo-operations/files/mise.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ description = "No-op: an operations repo produces no artifact; third-party apps
usage = 'arg "[name]" hide=#true'
run = 'echo "build: nothing to build in an operations repo"'

[tasks.publish]
description = "No-op: an operations repo publishes nothing"
usage = 'arg "[name]" hide=#true'
run = 'echo "publish: nothing to publish from an operations repo"'

[tasks.lint]
description = "Formatting of the text files: no trailing whitespace, one final newline, one kind of line ending"
usage = '''
Expand Down
19 changes: 19 additions & 0 deletions templates/repo-turbo/files/mise.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ run = '''
./turbow trusted run e2e ${dir:+--filter="...{./$dir}"}
'''

[tasks.publish]
depends = ["install"]
{%- if publishes_packages %}
description = "Publish the packages that carry a pending release: changeset publish; a name is accepted and ignored, it applies to every package"
usage = 'arg "[name]" hide=#true'
# What a package repo publishes is its packages, as they were built: this task builds nothing itself, so `build` runs
# before it.
run = 'pnpm exec changeset publish'
{%- else %}
description = "Publish what the repo ships: the publish script of each app or package, after its own build, never cached"
{{ name_arg("publish") }}
# Each project's own publish script puts its artifact in a registry; a project without one publishes nothing. Turbo
# runs it after the build of the same project, and no other verb runs.
run = '''
{{ scoped("publish") }}
./turbow trusted run publish ${dir:+--filter="{./$dir}"}
'''
{%- endif %}

[tasks.install]
description = "Install and wire up project dependencies"
hide = true
Expand Down
Loading
Loading