diff --git a/mise.toml b/mise.toml index 838a9a7f..72670c2e 100644 --- a/mise.toml +++ b/mise.toml @@ -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] diff --git a/newborns/repo-operations.test.ts b/newborns/repo-operations.test.ts index 36622a06..a752b91a 100644 --- a/newborns/repo-operations.test.ts +++ b/newborns/repo-operations.test.ts @@ -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). @@ -20,10 +20,10 @@ const SHAPES: [string, Record][] = [ ]; /** 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); diff --git a/newborns/repo-turbo.test.ts b/newborns/repo-turbo.test.ts index 62d4cd3b..2a4bccdb 100644 --- a/newborns/repo-turbo.test.ts +++ b/newborns/repo-turbo.test.ts @@ -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 @@ -39,7 +40,7 @@ async function newborn(name: string, answers: Record = {}): 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 { for (const verb of VERDICTS) await pass(dir, name, verb); @@ -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'); diff --git a/newborns/turbo-cache.test.ts b/newborns/turbo-cache.test.ts index dbc8a427..c0fbbd71 100644 --- a/newborns/turbo-cache.test.ts +++ b/newborns/turbo-cache.test.ts @@ -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. @@ -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')); diff --git a/packages/lib/src/doctor.test.ts b/packages/lib/src/doctor.test.ts index bae35658..93b2661c 100644 --- a/packages/lib/src/doctor.test.ts +++ b/packages/lib/src/doctor.test.ts @@ -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']; @@ -52,6 +52,7 @@ const ADVICE: Record = { 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]}`; @@ -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) } })), [ @@ -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( @@ -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']), @@ -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'), diff --git a/packages/lib/src/doctor.ts b/packages/lib/src/doctor.ts index befc024f..b2471e7c 100644 --- a/packages/lib/src/doctor.ts +++ b/packages/lib/src/doctor.ts @@ -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. // @@ -168,6 +169,7 @@ const VERBS: Readonly> = { 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[] { diff --git a/packages/lib/src/repoOperations.test.ts b/packages/lib/src/repoOperations.test.ts index 70172077..c65828fd 100644 --- a/packages/lib/src/repoOperations.test.ts +++ b/packages/lib/src/repoOperations.test.ts @@ -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); } @@ -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'); }); diff --git a/packages/lib/src/repoTurbo.test.ts b/packages/lib/src/repoTurbo.test.ts index 925e57b7..ebaeaf1b 100644 --- a/packages/lib/src/repoTurbo.test.ts +++ b/packages/lib/src/repoTurbo.test.ts @@ -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>) => @@ -185,11 +185,11 @@ const turboOf = (result: Awaited>) => 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); } @@ -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( diff --git a/templates/repo-operations/files/mise.toml.jinja b/templates/repo-operations/files/mise.toml.jinja index 8b48724c..13f4e938 100644 --- a/templates/repo-operations/files/mise.toml.jinja +++ b/templates/repo-operations/files/mise.toml.jinja @@ -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 = ''' diff --git a/templates/repo-turbo/files/mise.toml.jinja b/templates/repo-turbo/files/mise.toml.jinja index 87f73e1f..7fbe264a 100644 --- a/templates/repo-turbo/files/mise.toml.jinja +++ b/templates/repo-turbo/files/mise.toml.jinja @@ -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 diff --git a/templates/repo-turbo/files/turbo.json.jinja b/templates/repo-turbo/files/turbo.json.jinja index d6472752..160b2a50 100644 --- a/templates/repo-turbo/files/turbo.json.jinja +++ b/templates/repo-turbo/files/turbo.json.jinja @@ -15,12 +15,18 @@ ], "outputs": [{% if not publishes_packages %}".next/**", "!.next/cache/**", {% endif %}"dist/**"] }, + // Only a package repo builds its packages, and so only there a check or a test waits for a build. An app repo's + // packages export their source, so these two read no build and the shared cache holds no build output. "check": { + {%- if publishes_packages %} "dependsOn": ["^build"], + {%- endif %} "inputs": ["$TURBO_DEFAULT$", "!**/{README,AGENTS,PLEXUS}.md", "!docs/**", "!docker/compose*.yaml"] }, "test": { + {%- if publishes_packages %} "dependsOn": ["^build"], + {%- endif %} "inputs": ["$TURBO_DEFAULT$", "!**/{README,AGENTS,PLEXUS}.md", "!docs/**"], {%- if postgres %} "env": ["PLX_POSTGRES_MAJOR"], @@ -36,6 +42,13 @@ {%- endif %} "passThroughEnv": ["CI", "PLAYWRIGHT_BROWSERS_PATH"] }, + {%- if not publishes_packages %} + // Puts the artifact of an app into a registry: after the build of the same project, and never replayed. + "publish": { + "dependsOn": ["build"], + "cache": false + }, + {%- endif %} "dev": { "cache": false, "persistent": true