npm-publish jobs take an optional tag: the npm dist-tag to publish under (latest if none)
of shared·infra-pipeline··Not checked
Version 90 · Files at version 91
2 files, 30 lines added, 2 removed.
--- a/src/pipeline/pipeline.ts
+++ b/src/pipeline/pipeline.ts
@@ -76,10 +76,13 @@
7676 deploy: ["worker", "staging", "live"], 79− // The npm packages it may publish, from the .tgz files its from: job kept.
80− "npm-publish": ["packages"],
79+ // The npm packages it may publish, from the .tgz files its from: job kept, and the dist-tag (latest if none). 80+ "npm-publish": ["packages", "tag"], 83+/** An npm dist-tag: npm refuses one that reads as a version, so it starts with a letter. */ 84+const DIST_TAG = /^[a-z][a-z0-9_-]{0,31}$/; 8386/** An npm package name: lower case, URL-safe, optionally under a @scope/. */ 8487const NPM_NAME = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/; @@ -293,6 +296,8 @@
293296 if (typeof p !== "string" || p.length > 214 || !NPM_NAME.test(p)) 294297 say(`${at}.packages[${i}]`, `${q(p)} isn't an npm package name`); 299+ if (j.tag !== undefined && (typeof j.tag !== "string" || !DIST_TAG.test(j.tag))) 300+ say(`${at}.tag`, `${q(j.tag)} isn't an npm dist-tag (a lower-case name such as next, not a version)`); --- a/src/pipeline/test/pipeline.test.ts
+++ b/src/pipeline/test/pipeline.test.ts
@@ -245,6 +245,29 @@
245245 has(ps, "pipelines.p.jobs.c.packages[2]", /isn't an npm package name/); 248+ it("npm-publish: an optional dist-tag", () => { 249+ const pack = { run: "npm pack --pack-destination out", keep: ["out"] }; 250+ const read = checkPipelines( 251+ one({ pack, publish: { uses: "npm-publish", from: "p.pack", packages: ["tool"], tag: "next" } }), 254+ const job = read.ok ? read.file.pipelines[0]!.jobs.find((j) => j.name === "publish") : undefined; 255+ assert.deepEqual(job?.with, { packages: ["tool"], tag: "next" }); 256+ const ps = problems( 260+ a: { uses: "npm-publish", from: "p.pack", packages: ["tool"], tag: "1.2.0" }, 261+ b: { uses: "npm-publish", from: "p.pack", packages: ["tool"], tag: "Next" }, 262+ c: { uses: "npm-publish", from: "p.pack", packages: ["tool"], tag: 7 }, 266+ has(ps, "pipelines.p.jobs.a.tag", /isn't an npm dist-tag/); 267+ has(ps, "pipelines.p.jobs.b.tag", /isn't an npm dist-tag/); 268+ has(ps, "pipelines.p.jobs.c.tag", /isn't an npm dist-tag/); 248271 it("keys it doesn't know, at every level", () => { 249272 const ps = problems(