From 3a38fddaba3d305e1a708b4e717d317798d1f22a Mon Sep 17 00:00:00 2001 From: Jeremiah Zucker Date: Fri, 12 Jul 2024 16:43:45 -0400 Subject: [PATCH 1/6] let publish script know more about the type of release, instead of hardcoding snapshot for next --- plugins/version-file/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/version-file/src/index.ts b/plugins/version-file/src/index.ts index c436f22ba..8c4b6d7cf 100644 --- a/plugins/version-file/src/index.ts +++ b/plugins/version-file/src/index.ts @@ -141,7 +141,7 @@ export default class VersionFilePlugin implements IPlugin { // Ship canary release if release script is provided if(this.publishScript){ auto.logger.log.info(`Calling release script in repo at ${this.publishScript}`); - await execPromise(this.publishScript, ["snapshot"]); + await execPromise(this.publishScript, ["canary"]); } else { auto.logger.log.info("Skipping calling release script in repo since none was provided"); } @@ -188,7 +188,7 @@ export default class VersionFilePlugin implements IPlugin { // ship next release if release script is provided if(this.publishScript){ auto.logger.log.info(`Calling release script in repo at ${this.publishScript}`); - await execPromise(this.publishScript, ["snapshot"]); + await execPromise(this.publishScript, ["next"]); } else { auto.logger.log.info("Skipping calling release script in repo since none was provided"); } From 44deb2468380342d384f3f12d55a7acb92c6deca Mon Sep 17 00:00:00 2001 From: Jeremiah Zucker Date: Fri, 12 Jul 2024 16:49:01 -0400 Subject: [PATCH 2/6] update version-file docs to reflect change --- plugins/version-file/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/version-file/README.md b/plugins/version-file/README.md index 2043ad867..9ff4c6449 100644 --- a/plugins/version-file/README.md +++ b/plugins/version-file/README.md @@ -17,7 +17,7 @@ yarn add -D @auto-it/version-file ## Options - versionFile (optional, default="VERSION"): Path to where the version is stored in the repository. It should be a file containing just the semver. -- releaseScript: (optional, default=None): Path to script that runs the publish actions in your repository. If not supplied nothing will be called. If supplied will be called during the `publish`,`canary` and `next` hooks. For the `publish` hook the first parameter passed to the script will be `release` to indicate that a regular release is being called. For `canary` and `next` hooks the first parameter will be `snapshot` to indicate a prerelease version. +- releaseScript: (optional, default=None): Path to script that runs the publish actions in your repository. If not supplied nothing will be called. If supplied will be called during the `publish`,`canary` and `next` hooks. For the `publish` hook the first parameter passed to the script will be `release` to indicate that a regular release is being called. For `canary` and `next` hooks the first parameter will be `canary` or `next` to indicate a prerelease version, and let the consumer handle what to do for those types of releases. ## Usage @@ -36,4 +36,4 @@ yarn add -D @auto-it/version-file "plugins": [ "version-file", {"versionFile": "./tools/Version.txt", "releaseScript":"./tools/publish.sh"} ] -} \ No newline at end of file +} From 3bc7bd5dd686d260eca14a760e3d7faa668471d9 Mon Sep 17 00:00:00 2001 From: Jeremiah Zucker Date: Fri, 12 Jul 2024 16:51:21 -0400 Subject: [PATCH 3/6] update version-file tests to reflect change --- plugins/version-file/__tests__/version-file.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/version-file/__tests__/version-file.test.ts b/plugins/version-file/__tests__/version-file.test.ts index 003bf83a4..44c801396 100644 --- a/plugins/version-file/__tests__/version-file.test.ts +++ b/plugins/version-file/__tests__/version-file.test.ts @@ -217,7 +217,7 @@ describe("Test Release Types", () => { await hooks.canary.promise({bump: SEMVER.minor, canaryIdentifier: "canary.368.1"}) // check release script was called - expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["snapshot"]); + expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["canary"]); // check local changes were reverted expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["reset", "--hard", "HEAD"]); @@ -293,7 +293,7 @@ describe("Test Release Types", () => { await hooks.next.promise(["1.0.0"], {bump: SEMVER.major, fullReleaseNotes:"", releaseNotes:"", commits:[]}) // check release script was called - expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["snapshot"]); + expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["next"]); // Check git ops expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "v2.0.0-next.0"]); @@ -302,4 +302,4 @@ describe("Test Release Types", () => { // Check the right version was written expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("v2.0.0-next.0") }); -}); \ No newline at end of file +}); From c379344320e975ec5f0d84ac4ec0f351aed59c58 Mon Sep 17 00:00:00 2001 From: Jeremiah Zucker Date: Fri, 12 Jul 2024 18:55:27 -0400 Subject: [PATCH 4/6] make it non-breaking --- plugins/version-file/README.md | 13 +++- .../__tests__/version-file.test.ts | 66 ++++++++++++++++++- plugins/version-file/src/index.ts | 31 +++++++-- 3 files changed, 101 insertions(+), 9 deletions(-) diff --git a/plugins/version-file/README.md b/plugins/version-file/README.md index 9ff4c6449..b827e9bae 100644 --- a/plugins/version-file/README.md +++ b/plugins/version-file/README.md @@ -17,7 +17,12 @@ yarn add -D @auto-it/version-file ## Options - versionFile (optional, default="VERSION"): Path to where the version is stored in the repository. It should be a file containing just the semver. -- releaseScript: (optional, default=None): Path to script that runs the publish actions in your repository. If not supplied nothing will be called. If supplied will be called during the `publish`,`canary` and `next` hooks. For the `publish` hook the first parameter passed to the script will be `release` to indicate that a regular release is being called. For `canary` and `next` hooks the first parameter will be `canary` or `next` to indicate a prerelease version, and let the consumer handle what to do for those types of releases. +- publishScript: (optional, default=None): Path to script that runs the publish actions in your repository. If not supplied nothing will be called. If supplied will be called during the `publish`,`canary` and `next` hooks with the arguments defined in `publishScriptReleaseTypeArgs` for that release type. +- publishScriptReleaseTypeArgs: (optional, default={ + "publish": ["release"], + "canary": ["snapshot"], + "next": ["snapshot"], +}): Mapping of arguments to pass to the `publishScript` for each release type (`publish`, `canary`, `next`) ## Usage @@ -34,6 +39,10 @@ yarn add -D @auto-it/version-file ```json { "plugins": [ - "version-file", {"versionFile": "./tools/Version.txt", "releaseScript":"./tools/publish.sh"} + "version-file", {"versionFile": "./tools/Version.txt", "publishScript":"./tools/publish.sh", "publishScriptReleaseTypeArgs": { + "publish": ["release"], // (default) + "canary": ["snapshot"], + "next": ["some", "other", "args"], + }} ] } diff --git a/plugins/version-file/__tests__/version-file.test.ts b/plugins/version-file/__tests__/version-file.test.ts index 44c801396..6a4a07f06 100644 --- a/plugins/version-file/__tests__/version-file.test.ts +++ b/plugins/version-file/__tests__/version-file.test.ts @@ -217,7 +217,7 @@ describe("Test Release Types", () => { await hooks.canary.promise({bump: SEMVER.minor, canaryIdentifier: "canary.368.1"}) // check release script was called - expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["canary"]); + expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["snapshot"]); // check local changes were reverted expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["reset", "--hard", "HEAD"]); @@ -293,7 +293,7 @@ describe("Test Release Types", () => { await hooks.next.promise(["1.0.0"], {bump: SEMVER.major, fullReleaseNotes:"", releaseNotes:"", commits:[]}) // check release script was called - expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["next"]); + expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["snapshot"]); // Check git ops expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "v2.0.0-next.0"]); @@ -302,4 +302,66 @@ describe("Test Release Types", () => { // Check the right version was written expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("v2.0.0-next.0") }); + + test("Release type args can be provided to override default args for publish script", async () => { + const prefixRelease: (a: string) => string = (version: string) => { + return `v${version}`; + }; + + mockFs({ + VERSION: `1.0.0`, + }); + const plugin = new BazelPlugin({ + publishScript: "./tools/release.sh", + publishScriptReleaseTypeArgs: { + publish: ["args", "for", "publish"], + canary: ["different", "canary"], + next: ["next"], + }, + }); + const hooks = makeHooks(); + + plugin.apply(({ + hooks, + config: { prereleaseBranches: ["next"] }, + remote: "origin", + baseBranch: "main", + logger: dummyLog(), + prefixRelease, + getCurrentVersion: () => "1.0.0", + git: { + getLastTagNotInBaseBranch: async () => undefined, + getLatestRelease: () => "1.0.0", + getLatestTagInBranch: () => Promise.resolve("1.0.0"), + }, + } as unknown) as Auto); + + + await hooks.publish.promise({ bump: SEMVER.major }); + + expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", [ + "args", "for", "publish" + ]); + + await hooks.canary.promise({ + bump: SEMVER.minor, + canaryIdentifier: "canary.368.1", + }); + + expect(execPromise).toHaveBeenNthCalledWith(3, "./tools/release.sh", [ + "different", + "canary", + ]); + + await hooks.next.promise(["1.0.0"], { + bump: SEMVER.major, + fullReleaseNotes: "", + releaseNotes: "", + commits: [], + }); + + expect(execPromise).toHaveBeenNthCalledWith(5, "./tools/release.sh", [ + "next", + ]); + }) }); diff --git a/plugins/version-file/src/index.ts b/plugins/version-file/src/index.ts index 8c4b6d7cf..f5b293acb 100644 --- a/plugins/version-file/src/index.ts +++ b/plugins/version-file/src/index.ts @@ -7,13 +7,25 @@ import { inc, ReleaseType } from "semver"; const readFile = promisify(fs.readFile); const writeFile = promisify(fs.writeFile); +interface ReleaseTypeArgs { + publish: string[]; + canary: string[]; + next: string[]; +} const pluginOptions = t.partial({ /** Path to file (from where auto is executed) where the version is stored */ versionFile: t.string, /** Optional script that executes release pipeline stages */ - publishScript: t.string + publishScript: t.string, + + /** Optional publish script args mapping for each release hook, defaults `publish` to ["release"] and the others to ["snapshot"] */ + publishScriptReleaseTypeArgs: t.partial({ + publish: t.array(t.string), + canary: t.array(t.string), + next: t.array(t.string), + }) }); export type IVersionFilePluginOptions = t.TypeOf; @@ -55,10 +67,19 @@ export default class VersionFilePlugin implements IPlugin { /** Release script location */ readonly publishScript: string | undefined + /** */ + readonly publishScriptReleaseTypeArgs: ReleaseTypeArgs; + /** Initialize the plugin with it's options */ constructor(options: IVersionFilePluginOptions) { this.versionFile = options.versionFile ?? "VERSION"; - this.publishScript = options.publishScript + this.publishScript = options.publishScript; + this.publishScriptReleaseTypeArgs = { + publish: ['release'], + canary: ['snapshot'], + next: ['snapshot'], + ...options.publishScriptReleaseTypeArgs ?? {} + }; } @@ -113,7 +134,7 @@ export default class VersionFilePlugin implements IPlugin { // Call release script if provided if(this.publishScript){ auto.logger.log.info(`Calling release script in repo at ${this.publishScript}`); - await execPromise(this.publishScript, ["release"]) + await execPromise(this.publishScript, this.publishScriptReleaseTypeArgs['publish']) } else { auto.logger.log.info("Skipping calling release script in repo since none was provided"); } @@ -141,7 +162,7 @@ export default class VersionFilePlugin implements IPlugin { // Ship canary release if release script is provided if(this.publishScript){ auto.logger.log.info(`Calling release script in repo at ${this.publishScript}`); - await execPromise(this.publishScript, ["canary"]); + await execPromise(this.publishScript, this.publishScriptReleaseTypeArgs['canary']); } else { auto.logger.log.info("Skipping calling release script in repo since none was provided"); } @@ -188,7 +209,7 @@ export default class VersionFilePlugin implements IPlugin { // ship next release if release script is provided if(this.publishScript){ auto.logger.log.info(`Calling release script in repo at ${this.publishScript}`); - await execPromise(this.publishScript, ["next"]); + await execPromise(this.publishScript, this.publishScriptReleaseTypeArgs['next']); } else { auto.logger.log.info("Skipping calling release script in repo since none was provided"); } From df6cf8dd217d880568fdf530708b746e34b8564d Mon Sep 17 00:00:00 2001 From: Jeremiah Zucker Date: Fri, 12 Jul 2024 18:57:36 -0400 Subject: [PATCH 5/6] readme formatting --- plugins/version-file/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/version-file/README.md b/plugins/version-file/README.md index b827e9bae..cebf246dd 100644 --- a/plugins/version-file/README.md +++ b/plugins/version-file/README.md @@ -18,11 +18,11 @@ yarn add -D @auto-it/version-file - versionFile (optional, default="VERSION"): Path to where the version is stored in the repository. It should be a file containing just the semver. - publishScript: (optional, default=None): Path to script that runs the publish actions in your repository. If not supplied nothing will be called. If supplied will be called during the `publish`,`canary` and `next` hooks with the arguments defined in `publishScriptReleaseTypeArgs` for that release type. -- publishScriptReleaseTypeArgs: (optional, default={ +- publishScriptReleaseTypeArgs: (optional, default=```{ "publish": ["release"], "canary": ["snapshot"], - "next": ["snapshot"], -}): Mapping of arguments to pass to the `publishScript` for each release type (`publish`, `canary`, `next`) + "next": ["snapshot"] +}```): Mapping of arguments to pass to the `publishScript` for each release type (`publish`, `canary`, `next`) ## Usage From ec6d09c171f53d40863ebae20adbaf637e262691 Mon Sep 17 00:00:00 2001 From: Jeremiah Zucker Date: Fri, 12 Jul 2024 19:06:51 -0400 Subject: [PATCH 6/6] lint --- plugins/version-file/src/index.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/version-file/src/index.ts b/plugins/version-file/src/index.ts index f5b293acb..853d67766 100644 --- a/plugins/version-file/src/index.ts +++ b/plugins/version-file/src/index.ts @@ -8,8 +8,11 @@ const readFile = promisify(fs.readFile); const writeFile = promisify(fs.writeFile); interface ReleaseTypeArgs { + /** Args to use when invoking the publishScript during the publish hook */ publish: string[]; + /** Args to use when invoking the publishScript during the canary hook */ canary: string[]; + /** Args to use when invoking the publishScript during the next hook */ next: string[]; } @@ -134,7 +137,7 @@ export default class VersionFilePlugin implements IPlugin { // Call release script if provided if(this.publishScript){ auto.logger.log.info(`Calling release script in repo at ${this.publishScript}`); - await execPromise(this.publishScript, this.publishScriptReleaseTypeArgs['publish']) + await execPromise(this.publishScript, this.publishScriptReleaseTypeArgs.publish) } else { auto.logger.log.info("Skipping calling release script in repo since none was provided"); } @@ -162,7 +165,7 @@ export default class VersionFilePlugin implements IPlugin { // Ship canary release if release script is provided if(this.publishScript){ auto.logger.log.info(`Calling release script in repo at ${this.publishScript}`); - await execPromise(this.publishScript, this.publishScriptReleaseTypeArgs['canary']); + await execPromise(this.publishScript, this.publishScriptReleaseTypeArgs.canary); } else { auto.logger.log.info("Skipping calling release script in repo since none was provided"); } @@ -209,7 +212,7 @@ export default class VersionFilePlugin implements IPlugin { // ship next release if release script is provided if(this.publishScript){ auto.logger.log.info(`Calling release script in repo at ${this.publishScript}`); - await execPromise(this.publishScript, this.publishScriptReleaseTypeArgs['next']); + await execPromise(this.publishScript, this.publishScriptReleaseTypeArgs.next); } else { auto.logger.log.info("Skipping calling release script in repo since none was provided"); }