From 5558326af9022d39a56fd3134974c315adb070e3 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Wed, 10 Nov 2021 15:00:24 -0800 Subject: [PATCH 01/16] Core hooks scaffolded out --- plugins/bazel/README.md | 24 ++++++ plugins/bazel/__tests__/bazel.test.ts | 7 ++ plugins/bazel/package.json | 45 ++++++++++ plugins/bazel/src/index.ts | 114 ++++++++++++++++++++++++++ plugins/bazel/tsconfig.json | 16 ++++ tsconfig.dev.json | 3 + 6 files changed, 209 insertions(+) create mode 100644 plugins/bazel/README.md create mode 100644 plugins/bazel/__tests__/bazel.test.ts create mode 100644 plugins/bazel/package.json create mode 100644 plugins/bazel/src/index.ts create mode 100644 plugins/bazel/tsconfig.json diff --git a/plugins/bazel/README.md b/plugins/bazel/README.md new file mode 100644 index 000000000..a056b6309 --- /dev/null +++ b/plugins/bazel/README.md @@ -0,0 +1,24 @@ +# Bazel Plugin + + + +## Installation + +This plugin is not included with the `auto` CLI installed via NPM. To install: + +```bash +npm i --save-dev @auto-it/bazel +# or +yarn add -D @auto-it/bazel +``` + +## Usage + +```json +{ + "plugins": [ + "bazel" + // other plugins + ] +} +``` diff --git a/plugins/bazel/__tests__/bazel.test.ts b/plugins/bazel/__tests__/bazel.test.ts new file mode 100644 index 000000000..c962bc95a --- /dev/null +++ b/plugins/bazel/__tests__/bazel.test.ts @@ -0,0 +1,7 @@ +import Auto from '@auto-it/core'; +import Bazel from '../src'; + +describe('Bazel Plugin', () => { + test('should do something', async () => { + }); +}); diff --git a/plugins/bazel/package.json b/plugins/bazel/package.json new file mode 100644 index 000000000..ed706f7c0 --- /dev/null +++ b/plugins/bazel/package.json @@ -0,0 +1,45 @@ +{ + "name": "@auto-it/bazel", + "version": "10.32.2", + "main": "dist/index.js", + "description": "", + "license": "MIT", + "author": { + "name": "Andrew Lisowski", + "email": "lisowski54@gmail.com" + }, + "publishConfig": { + "registry": "https://registry.npmjs.org/", + "access": "public" + }, + "repository": { + "type": "git", + "url": "https://github.com/intuit/auto" + }, + "files": [ + "dist" + ], + "keywords": [ + "automation", + "semantic", + "release", + "github", + "labels", + "automated", + "continuos integration", + "changelog" + ], + "scripts": { + "build": "tsc -b", + "start": "npm run build -- -w", + "lint": "eslint src --ext .ts", + "test": "jest --maxWorkers=2 --config ../../package.json" + }, + "dependencies": { + "@auto-it/core": "link:../../packages/core", + "fp-ts": "^2.5.3", + "io-ts": "^2.1.2", + "tslib": "1.10.0", + "semver":"^7.0.0" + } +} diff --git a/plugins/bazel/src/index.ts b/plugins/bazel/src/index.ts new file mode 100644 index 000000000..689fef670 --- /dev/null +++ b/plugins/bazel/src/index.ts @@ -0,0 +1,114 @@ +import { Auto, IPlugin, execPromise, validatePluginConfiguration, getCurrentBranch } from '@auto-it/core'; +import * as t from "io-ts"; +import * as fs from "fs"; + +import { inc, ReleaseType } from "semver"; + +const pluginOptions = t.partial({ + /** Path to file (from where auto is executed) where the version is stored */ + versionFile: t.string, + + /** Bazel script that executes release pipeline stages */ + releaseScript: t.string +}); + +export type IBazelPluginOptions = t.TypeOf; + +/** + * Reads version file from location specified in config + */ +async function getPreviousVersion(auto: Auto, versionFile: string) { + auto.logger.veryVerbose.info(`Reading version from file `, versionFile) + try { + return await execPromise("cat", [versionFile]) + } catch (e){ + auto.logger.log.error("Error, looks like the version file doesn't exist or is unreadable") + } + + return "" +} + +/** Writes new version to version file at specified location */ +async function writeNewVersion(auto: Auto, version: string, versionFile: string) { + auto.logger.veryVerbose.info(`Writing version to file `, versionFile) + + fs.writeFile('/Users/joe/test.txt', version, err => { + auto.logger.log.error(err) + throw new Error("Failed to write version to file") + }) +} + +/** Creates a git tag for the specified version */ +async function sealVersion(version: string){ + await execPromise("git", ["commit", "-am", "'Update versions'"]); + await execPromise("git", [ + "tag", + version, + "-m", + `"Update version to ${version}"`, + ]); +} + +/** Pushes changes to current branch */ +async function gitPush(auto:Auto) { + const branch = getCurrentBranch() + await execPromise("git", ["push", auto.remote, branch, "--tags"]); +} + +/** Plugin to orchestrate releases in a Bazel repo */ +export default class BazelPlugin implements IPlugin { + /** The name of the plugin */ + name = 'bazel'; + + /** Version file location */ + readonly versionFile: string; + + /** Release script location */ + readonly releaseScript: string + + /** Initialize the plugin with it's options */ + constructor(options: IBazelPluginOptions) { + this.versionFile = options.versionFile ?? "VERSION"; + this.releaseScript = options.releaseScript ?? "./tools/release.sh" + } + + + /** Tap into auto plugin points. */ + apply(auto: Auto) { + auto.hooks.validateConfig.tapPromise(this.name, async (name, options) => { + // If it's a string thats valid config + if (name === this.name && typeof options !== "string") { + return validatePluginConfiguration(this.name, pluginOptions, options); + } + }); + + auto.hooks.getPreviousVersion.tapPromise(this.name, () =>{ + return getPreviousVersion(auto, this.versionFile) + }); + + auto.hooks.version.tapPromise( this.name, async ({ bump }) => { + const lastVersion = await getPreviousVersion(auto, this.versionFile) + const newVersion = inc(lastVersion, bump as ReleaseType); + + auto.logger.log.info(`Calculated new version as: ${newVersion}`) + + if (newVersion){ + return writeNewVersion(auto, newVersion, this.versionFile) + } + + auto.logger.log.error(`Error: Unable to calculate new version based off of ${lastVersion} being bumped with a ${bump} release`) + throw new Error ("Version bump failed") + }); + + auto.hooks.publish.tapPromise(this.name, async () => { + auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); + + await execPromise(this.releaseScript, ["release"]); + + const version = await getPreviousVersion(auto, this.versionFile) + + await sealVersion(version) + await gitPush(auto) + }); + } +} diff --git a/plugins/bazel/tsconfig.json b/plugins/bazel/tsconfig.json new file mode 100644 index 000000000..bfbef6fc7 --- /dev/null +++ b/plugins/bazel/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*", "../../typings/**/*"], + + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./src", + "composite": true + }, + + "references": [ + { + "path": "../../packages/core" + } + ] +} diff --git a/tsconfig.dev.json b/tsconfig.dev.json index 827e03a84..97ebdf29d 100644 --- a/tsconfig.dev.json +++ b/tsconfig.dev.json @@ -91,6 +91,9 @@ }, { "path": "plugins/sbt" + }, + { + "path": "plugins/bazel" } ] } \ No newline at end of file From 136ec9d518df642dc5a8d9c2949aee54dcb30a3f Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Fri, 12 Nov 2021 15:05:47 -0800 Subject: [PATCH 02/16] canary and next hooks --- plugins/bazel/src/index.ts | 113 +++++++++++++++++++++++++++++++------ 1 file changed, 97 insertions(+), 16 deletions(-) diff --git a/plugins/bazel/src/index.ts b/plugins/bazel/src/index.ts index 689fef670..304000db0 100644 --- a/plugins/bazel/src/index.ts +++ b/plugins/bazel/src/index.ts @@ -1,9 +1,11 @@ -import { Auto, IPlugin, execPromise, validatePluginConfiguration, getCurrentBranch } from '@auto-it/core'; +import { Auto, IPlugin, execPromise, validatePluginConfiguration, getCurrentBranch, determineNextVersion, DEFAULT_PRERELEASE_BRANCHES } from '@auto-it/core'; import * as t from "io-ts"; import * as fs from "fs"; import { inc, ReleaseType } from "semver"; +const VERSION_COMMIT_MESSAGE = `'"Bump version to: %s [skip ci]"'`; + const pluginOptions = t.partial({ /** Path to file (from where auto is executed) where the version is stored */ versionFile: t.string, @@ -38,23 +40,17 @@ async function writeNewVersion(auto: Auto, version: string, versionFile: string) }) } -/** Creates a git tag for the specified version */ -async function sealVersion(version: string){ - await execPromise("git", ["commit", "-am", "'Update versions'"]); - await execPromise("git", [ - "tag", - version, - "-m", - `"Update version to ${version}"`, - ]); +/** Reset the scope changes of all the packages */ +async function gitReset() { + await execPromise("git", ["reset", "--hard", "HEAD"]); } -/** Pushes changes to current branch */ -async function gitPush(auto:Auto) { - const branch = getCurrentBranch() - await execPromise("git", ["push", auto.remote, branch, "--tags"]); +/** Generates canary release notes */ +function makeCanaryNotes(canaryVersion: string){ + return `Try this version out locally by upgrading relevant packages to ${canaryVersion}` } + /** Plugin to orchestrate releases in a Bazel repo */ export default class BazelPlugin implements IPlugin { /** The name of the plugin */ @@ -75,6 +71,18 @@ export default class BazelPlugin implements IPlugin { /** Tap into auto plugin points. */ apply(auto: Auto) { + + const prereleaseBranches = + auto.config?.prereleaseBranches || DEFAULT_PRERELEASE_BRANCHES; + + const branch = getCurrentBranch(); + // if ran from baseBranch we publish the prerelease to the first + // configured prerelease branch + const prereleaseBranch = + branch && prereleaseBranches.includes(branch) + ? branch + : prereleaseBranches[0]; + auto.hooks.validateConfig.tapPromise(this.name, async (name, options) => { // If it's a string thats valid config if (name === this.name && typeof options !== "string") { @@ -107,8 +115,81 @@ export default class BazelPlugin implements IPlugin { const version = await getPreviousVersion(auto, this.versionFile) - await sealVersion(version) - await gitPush(auto) + // Seal versions via commit and tag + await execPromise("git", ["commit", "-am", VERSION_COMMIT_MESSAGE]); + await execPromise("git", [ + "tag", + version + ]); + await execPromise("git", ["push", auto.remote, branch, "--tags"]); + }); + + auto.hooks.canary.tapPromise(this.name, async ({ bump, canaryIdentifier}) => { + + // Figure out canary version + const lastRelease = await auto.git!.getLatestRelease(); + const [, latestTag = lastRelease] = await auto.git!.getLatestTagInBranch() + const current = await auto.getCurrentVersion(lastRelease); + const canaryVersion = determineNextVersion( + latestTag, + current, + bump, + canaryIdentifier + ); + + // Write Canary version + await writeNewVersion(auto, canaryVersion, this.versionFile) + + // Ship canary release + auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); + await execPromise(this.releaseScript, ["snapshot"]); + + // Reset temporary canary versioning + await gitReset(); + + return { + newVersion: canaryVersion, + details: makeCanaryNotes(canaryVersion), + }; + }); + + auto.hooks.next.tapPromise(this.name, async (preReleaseVersions, { bump }) => { + + // Figure out next version + const lastRelease = await auto.git!.getLatestRelease(); + const latestTag = + (await auto.git?.getLastTagNotInBaseBranch(prereleaseBranch)) || + (await getPreviousVersion(auto, this.versionFile)); + const nextVersion = determineNextVersion( + lastRelease, + latestTag, + bump, + prereleaseBranch + ); + const prefixedVersion = auto.prefixRelease(nextVersion); + preReleaseVersions.push(prefixedVersion); + + auto.logger.log.info(`Marking version as ${nextVersion}`); + + // Write version to file + await writeNewVersion(auto, nextVersion, this.versionFile) + + // Ship canary release + auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); + await execPromise(this.releaseScript, ["snapshot"]); + + // Push next tag + await execPromise("git", [ + "tag", + prefixedVersion + ]); + await execPromise("git", ["push", auto.remote, branch, "--tags"]); + + // Reset temporary next versioning + await gitReset(); + + return preReleaseVersions }); + } } From 7923405642419bf5af3032073434d10e9f703551 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Fri, 12 Nov 2021 15:33:38 -0800 Subject: [PATCH 03/16] use echo rather than fs to write version to file --- plugins/bazel/src/index.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugins/bazel/src/index.ts b/plugins/bazel/src/index.ts index 304000db0..f2784e64f 100644 --- a/plugins/bazel/src/index.ts +++ b/plugins/bazel/src/index.ts @@ -1,6 +1,5 @@ import { Auto, IPlugin, execPromise, validatePluginConfiguration, getCurrentBranch, determineNextVersion, DEFAULT_PRERELEASE_BRANCHES } from '@auto-it/core'; import * as t from "io-ts"; -import * as fs from "fs"; import { inc, ReleaseType } from "semver"; @@ -34,10 +33,7 @@ async function getPreviousVersion(auto: Auto, versionFile: string) { async function writeNewVersion(auto: Auto, version: string, versionFile: string) { auto.logger.veryVerbose.info(`Writing version to file `, versionFile) - fs.writeFile('/Users/joe/test.txt', version, err => { - auto.logger.log.error(err) - throw new Error("Failed to write version to file") - }) + await execPromise("echo", [version, ">", versionFile]); } /** Reset the scope changes of all the packages */ From 7b134e094c52a0c192b4faff4fe2803c0477817e Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Mon, 15 Nov 2021 11:46:16 -0800 Subject: [PATCH 04/16] Fix canary versioning --- plugins/bazel/__tests__/bazel.test.ts | 178 +++++++++++++++++++++++++- plugins/bazel/src/index.ts | 61 ++++----- 2 files changed, 200 insertions(+), 39 deletions(-) diff --git a/plugins/bazel/__tests__/bazel.test.ts b/plugins/bazel/__tests__/bazel.test.ts index c962bc95a..5d8a513b4 100644 --- a/plugins/bazel/__tests__/bazel.test.ts +++ b/plugins/bazel/__tests__/bazel.test.ts @@ -1,7 +1,177 @@ -import Auto from '@auto-it/core'; -import Bazel from '../src'; +import Auto, { SEMVER } from '@auto-it/core'; +import mockFs from "mock-fs"; +import fs from "fs"; +import BazelPlugin from '../src'; +import { makeHooks } from '@auto-it/core/dist/utils/make-hooks'; +import { dummyLog } from "@auto-it/core/dist/utils/logger"; -describe('Bazel Plugin', () => { - test('should do something', async () => { +// Mocks +const execPromise = jest.fn(); +jest.mock( + "../../../packages/core/dist/utils/exec-promise", + () => (...args: any[]) => execPromise(...args) +); +jest.mock("../../../packages/core/dist/utils/get-current-branch", () => ({ + getCurrentBranch: () => "main", +})); + +beforeEach(() => { + execPromise.mockClear(); +}); +afterEach(() => { + mockFs.restore(); +}) + +describe('Version File Read Operations', () => { + test("It should return the value in the default file", async () => { + mockFs({ + "VERSION": `1.0.0`, + }); + const plugin = new BazelPlugin({}); + const hooks = makeHooks(); + + plugin.apply({ + hooks, + remote: "origin", + baseBranch: "main", + logger: dummyLog(), + } as Auto); + + expect(await hooks.getPreviousVersion.promise()).toBe("1.0.0"); + }); + + test("It should return the value in the specified file", async () => { + mockFs({ + "VERSIONFILE": `1.0.0`, + }); + const plugin = new BazelPlugin({versionFile: "VERSIONFILE"}); + const hooks = makeHooks(); + + plugin.apply({ + hooks, + remote: "origin", + baseBranch: "main", + logger: dummyLog(), + } as Auto); + + expect(await hooks.getPreviousVersion.promise()).toBe("1.0.0"); }); }); + +describe("Version File Write Operations", () => { + test("It should version the file properly for major releases", async () => { + mockFs({ + "VERSION": `1.0.0`, + }); + const plugin = new BazelPlugin({}); + const hooks = makeHooks(); + + plugin.apply({ + hooks, + remote: "origin", + baseBranch: "main", + logger: dummyLog(), + } as Auto); + + await hooks.version.promise({bump: SEMVER.major}) + expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("2.0.0") + // check that the proper git operations were performed + expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "'\"Bump version to: %s [skip ci]\"'"]); + expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "2.0.0"]); + }); + + test("It should version the file properly for minor releases", async () => { + mockFs({ + "VERSION": `1.0.0`, + }); + const plugin = new BazelPlugin({}); + const hooks = makeHooks(); + + plugin.apply({ + hooks, + remote: "origin", + baseBranch: "main", + logger: dummyLog(), + } as Auto); + + await hooks.version.promise({bump: SEMVER.minor}) + expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("1.1.0"); + // check that the proper git operations were performed + expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "'\"Bump version to: %s [skip ci]\"'"]); + expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "1.1.0"]); + }); + + test("It should version the file properly for patch releases", async () => { + mockFs({ + "VERSION": `1.0.0`, + }); + const plugin = new BazelPlugin({}); + const hooks = makeHooks(); + + plugin.apply({ + hooks, + remote: "origin", + baseBranch: "main", + logger: dummyLog(), + } as Auto); + + await hooks.version.promise({bump: SEMVER.patch}) + expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("1.0.1"); + // check that the proper git operations were performed + expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "'\"Bump version to: %s [skip ci]\"'"]); + expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "1.0.1"]); + }); +}) + +describe("Test Release Types", () => { + test("Full Releases", async () => { + mockFs({ + "VERSION": `1.0.0`, + }); + const plugin = new BazelPlugin({}); + const hooks = makeHooks(); + + plugin.apply({ + hooks, + remote: "origin", + baseBranch: "main", + logger: dummyLog(), + } as Auto); + + await hooks.publish.promise({bump: SEMVER.major}) + + // check release script was called + expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["release"]); + + // check changes would be pushed + expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["push", "origin", "main", "--tags"]); + }); + + test("Canary Release", async () => { + mockFs({ + "VERSION": `1.0.0`, + }); + const plugin = new BazelPlugin({}); + const hooks = makeHooks(); + + plugin.apply(({ + hooks, + remote: "origin", + baseBranch: "main", + logger: dummyLog(), + getCurrentVersion: () => "1.0.0", + git: { + getLatestRelease: () => "1.0.0", + getLatestTagInBranch: () => Promise.resolve("1.0.0"), + }, + } as unknown) as Auto); + + await hooks.canary.promise({bump: SEMVER.minor, canaryIdentifier: "canary.368.1"}) + + // check release script was called + expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["snapshot"]); + + // Check the right version was written + expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("1.1.0-canary.368.1") + }); +}); \ No newline at end of file diff --git a/plugins/bazel/src/index.ts b/plugins/bazel/src/index.ts index f2784e64f..b5f6057a9 100644 --- a/plugins/bazel/src/index.ts +++ b/plugins/bazel/src/index.ts @@ -1,9 +1,13 @@ import { Auto, IPlugin, execPromise, validatePluginConfiguration, getCurrentBranch, determineNextVersion, DEFAULT_PRERELEASE_BRANCHES } from '@auto-it/core'; +import { promisify } from "util"; import * as t from "io-ts"; - +import * as fs from "fs"; import { inc, ReleaseType } from "semver"; const VERSION_COMMIT_MESSAGE = `'"Bump version to: %s [skip ci]"'`; +const readFile = promisify(fs.readFile); +const writeFile = promisify(fs.writeFile); + const pluginOptions = t.partial({ /** Path to file (from where auto is executed) where the version is stored */ @@ -20,20 +24,13 @@ export type IBazelPluginOptions = t.TypeOf; */ async function getPreviousVersion(auto: Auto, versionFile: string) { auto.logger.veryVerbose.info(`Reading version from file `, versionFile) - try { - return await execPromise("cat", [versionFile]) - } catch (e){ - auto.logger.log.error("Error, looks like the version file doesn't exist or is unreadable") - } - - return "" + return readFile(versionFile, "utf-8") } /** Writes new version to version file at specified location */ async function writeNewVersion(auto: Auto, version: string, versionFile: string) { auto.logger.veryVerbose.info(`Writing version to file `, versionFile) - - await execPromise("echo", [version, ">", versionFile]); + return writeFile(versionFile, version) } /** Reset the scope changes of all the packages */ @@ -97,27 +94,28 @@ export default class BazelPlugin implements IPlugin { auto.logger.log.info(`Calculated new version as: ${newVersion}`) if (newVersion){ - return writeNewVersion(auto, newVersion, this.versionFile) - } - - auto.logger.log.error(`Error: Unable to calculate new version based off of ${lastVersion} being bumped with a ${bump} release`) - throw new Error ("Version bump failed") + // Seal versions via commit and tag + await writeNewVersion(auto, newVersion, this.versionFile) + await execPromise("git", ["commit", "-am", VERSION_COMMIT_MESSAGE]); + await execPromise("git", [ + "tag", + newVersion + ]); + auto.logger.verbose.info("Successfully versioned repo"); + } else { + auto.logger.log.error(`Error: Unable to calculate new version based off of ${lastVersion} being bumped with a ${bump} release`) + throw new Error ("Version bump failed") + } }); auto.hooks.publish.tapPromise(this.name, async () => { auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); - await execPromise(this.releaseScript, ["release"]); - - const version = await getPreviousVersion(auto, this.versionFile) + // Call release script + await execPromise(this.releaseScript, ["release"]) - // Seal versions via commit and tag - await execPromise("git", ["commit", "-am", VERSION_COMMIT_MESSAGE]); - await execPromise("git", [ - "tag", - version - ]); - await execPromise("git", ["push", auto.remote, branch, "--tags"]); + // push tag and version change commit up + await execPromise("git", ["push", auto.remote, branch || auto.baseBranch, "--tags"]); }); auto.hooks.canary.tapPromise(this.name, async ({ bump, canaryIdentifier}) => { @@ -125,13 +123,9 @@ export default class BazelPlugin implements IPlugin { // Figure out canary version const lastRelease = await auto.git!.getLatestRelease(); const [, latestTag = lastRelease] = await auto.git!.getLatestTagInBranch() - const current = await auto.getCurrentVersion(lastRelease); - const canaryVersion = determineNextVersion( - latestTag, - current, - bump, - canaryIdentifier - ); + const current = await auto.getCurrentVersion(latestTag); + const nextVersion = inc(current, bump as ReleaseType); + const canaryVersion = `${nextVersion}-${canaryIdentifier}`; // Write Canary version await writeNewVersion(auto, canaryVersion, this.versionFile) @@ -181,9 +175,6 @@ export default class BazelPlugin implements IPlugin { ]); await execPromise("git", ["push", auto.remote, branch, "--tags"]); - // Reset temporary next versioning - await gitReset(); - return preReleaseVersions }); From 1ed61392af8a47b33fc5d15c611e6645d201ef3e Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Mon, 15 Nov 2021 13:40:01 -0800 Subject: [PATCH 05/16] Test for next release hook --- plugins/bazel/__tests__/bazel.test.ts | 40 +++++++++++++++++++++++++++ plugins/bazel/src/index.ts | 4 +-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/plugins/bazel/__tests__/bazel.test.ts b/plugins/bazel/__tests__/bazel.test.ts index 5d8a513b4..09bb953d1 100644 --- a/plugins/bazel/__tests__/bazel.test.ts +++ b/plugins/bazel/__tests__/bazel.test.ts @@ -174,4 +174,44 @@ describe("Test Release Types", () => { // Check the right version was written expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("1.1.0-canary.368.1") }); + + test("Next Release", async () => { + + const prefixRelease: (a: string) => string = (version: string) => { + return `v${version}`; + }; + + mockFs({ + "VERSION": `1.0.0`, + }); + const plugin = new BazelPlugin({}); + 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.next.promise(["1.0.0"], {bump: SEMVER.major, fullReleaseNotes:"", releaseNotes:"", commits:[]}) + + // check release script was called + expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["snapshot"]); + + // Check git ops + expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "v2.0.0-next.0"]); + expect(execPromise).toHaveBeenNthCalledWith(3, "git", ["push", "origin", "main", "--tags"]); + + // Check the right version was written + expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("v2.0.0-next.0") + }); }); \ No newline at end of file diff --git a/plugins/bazel/src/index.ts b/plugins/bazel/src/index.ts index b5f6057a9..c8f6a35e2 100644 --- a/plugins/bazel/src/index.ts +++ b/plugins/bazel/src/index.ts @@ -159,10 +159,10 @@ export default class BazelPlugin implements IPlugin { const prefixedVersion = auto.prefixRelease(nextVersion); preReleaseVersions.push(prefixedVersion); - auto.logger.log.info(`Marking version as ${nextVersion}`); + auto.logger.log.info(`Marking version as ${prefixedVersion}`); // Write version to file - await writeNewVersion(auto, nextVersion, this.versionFile) + await writeNewVersion(auto, prefixedVersion, this.versionFile) // Ship canary release auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); From 3b025e6d4ce6274b51538988dc3a17cff2280289 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Mon, 15 Nov 2021 15:49:09 -0800 Subject: [PATCH 06/16] Rename to be more accurate. Make releaseScript optional, update tests. --- plugins/bazel/README.md | 24 ----- plugins/version-file/README.md | 39 ++++++++ .../__tests__/version-file.test.ts} | 94 ++++++++++++++++++- plugins/{bazel => version-file}/package.json | 6 +- plugins/{bazel => version-file}/src/index.ts | 54 +++++++---- plugins/{bazel => version-file}/tsconfig.json | 0 6 files changed, 168 insertions(+), 49 deletions(-) delete mode 100644 plugins/bazel/README.md create mode 100644 plugins/version-file/README.md rename plugins/{bazel/__tests__/bazel.test.ts => version-file/__tests__/version-file.test.ts} (67%) rename plugins/{bazel => version-file}/package.json (89%) rename plugins/{bazel => version-file}/src/index.ts (75%) rename plugins/{bazel => version-file}/tsconfig.json (100%) diff --git a/plugins/bazel/README.md b/plugins/bazel/README.md deleted file mode 100644 index a056b6309..000000000 --- a/plugins/bazel/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Bazel Plugin - - - -## Installation - -This plugin is not included with the `auto` CLI installed via NPM. To install: - -```bash -npm i --save-dev @auto-it/bazel -# or -yarn add -D @auto-it/bazel -``` - -## Usage - -```json -{ - "plugins": [ - "bazel" - // other plugins - ] -} -``` diff --git a/plugins/version-file/README.md b/plugins/version-file/README.md new file mode 100644 index 000000000..4d136d1ba --- /dev/null +++ b/plugins/version-file/README.md @@ -0,0 +1,39 @@ +# Version File Plugin + +For managing versions in a repository that maintains the version primarily in a flat file. +Agnostic to the primary language of the repository. +Optional input for a release script to call during the publish/canary/next hooks. + +## Installation + +This plugin is not included with the `auto` CLI installed via NPM. To install: + +```bash +npm i --save-dev @auto-it/version-file +# or +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. + +## Usage + +### With default options +```json +{ + "plugins": [ + "version-file" + // other plugins + ] +} +``` +### With optional arguments +```json +{ + "plugins": [ + "version-file", {"versionFile": "./tools/Version.txt", "releaseScript":"./tools/publish.sh"} + ] +} \ No newline at end of file diff --git a/plugins/bazel/__tests__/bazel.test.ts b/plugins/version-file/__tests__/version-file.test.ts similarity index 67% rename from plugins/bazel/__tests__/bazel.test.ts rename to plugins/version-file/__tests__/version-file.test.ts index 09bb953d1..1932d54b1 100644 --- a/plugins/bazel/__tests__/bazel.test.ts +++ b/plugins/version-file/__tests__/version-file.test.ts @@ -124,7 +124,7 @@ describe("Version File Write Operations", () => { }) describe("Test Release Types", () => { - test("Full Releases", async () => { + test("Full release with no release script", async () => { mockFs({ "VERSION": `1.0.0`, }); @@ -140,6 +140,26 @@ describe("Test Release Types", () => { await hooks.publish.promise({bump: SEMVER.major}) + // check release script was not called but check changes would be pushed + expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["push", "origin", "main", "--tags"]); + }); + + test("Full release with release script", async () => { + mockFs({ + "VERSION": `1.0.0`, + }); + const plugin = new BazelPlugin({releaseScript:"./tools/release.sh"}); + const hooks = makeHooks(); + + plugin.apply({ + hooks, + remote: "origin", + baseBranch: "main", + logger: dummyLog(), + } as Auto); + + await hooks.publish.promise({bump: SEMVER.major}) + // check release script was called expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["release"]); @@ -147,7 +167,7 @@ describe("Test Release Types", () => { expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["push", "origin", "main", "--tags"]); }); - test("Canary Release", async () => { + test("Canary release with no release script", async () => { mockFs({ "VERSION": `1.0.0`, }); @@ -168,14 +188,45 @@ describe("Test Release Types", () => { await hooks.canary.promise({bump: SEMVER.minor, canaryIdentifier: "canary.368.1"}) + // check release script was not called and local changes were reverted + expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["reset", "--hard", "HEAD"]); + + // Check the right version was written + expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("1.1.0-canary.368.1") + }); + + test("Canary release with release script", async () => { + mockFs({ + "VERSION": `1.0.0`, + }); + const plugin = new BazelPlugin({releaseScript:"./tools/release.sh"}); + const hooks = makeHooks(); + + plugin.apply(({ + hooks, + remote: "origin", + baseBranch: "main", + logger: dummyLog(), + getCurrentVersion: () => "1.0.0", + git: { + getLatestRelease: () => "1.0.0", + getLatestTagInBranch: () => Promise.resolve("1.0.0"), + }, + } as unknown) as Auto); + + await hooks.canary.promise({bump: SEMVER.minor, canaryIdentifier: "canary.368.1"}) + // check release script was called expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["snapshot"]); + // check local changes were reverted + expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["reset", "--hard", "HEAD"]); + // Check the right version was written expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("1.1.0-canary.368.1") }); - test("Next Release", async () => { + test("Next release with no release script", async () => { const prefixRelease: (a: string) => string = (version: string) => { return `v${version}`; @@ -204,6 +255,43 @@ describe("Test Release Types", () => { await hooks.next.promise(["1.0.0"], {bump: SEMVER.major, fullReleaseNotes:"", releaseNotes:"", commits:[]}) + // check release script was not called but git ops were performed + expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["tag", "v2.0.0-next.0"]); + expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["push", "origin", "main", "--tags"]); + + // Check the right version was written + expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("v2.0.0-next.0") + }); + + test("Next release with release script", async () => { + + const prefixRelease: (a: string) => string = (version: string) => { + return `v${version}`; + }; + + mockFs({ + "VERSION": `1.0.0`, + }); + const plugin = new BazelPlugin({releaseScript:"./tools/release.sh"}); + 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.next.promise(["1.0.0"], {bump: SEMVER.major, fullReleaseNotes:"", releaseNotes:"", commits:[]}) + // check release script was called expect(execPromise).toHaveBeenNthCalledWith(1, "./tools/release.sh", ["snapshot"]); diff --git a/plugins/bazel/package.json b/plugins/version-file/package.json similarity index 89% rename from plugins/bazel/package.json rename to plugins/version-file/package.json index ed706f7c0..5849757df 100644 --- a/plugins/bazel/package.json +++ b/plugins/version-file/package.json @@ -1,12 +1,12 @@ { - "name": "@auto-it/bazel", + "name": "@auto-it/version-file", "version": "10.32.2", "main": "dist/index.js", "description": "", "license": "MIT", "author": { - "name": "Andrew Lisowski", - "email": "lisowski54@gmail.com" + "name": "Ketan Reddy", + "email": "ketan@ketanreddy.com" }, "publishConfig": { "registry": "https://registry.npmjs.org/", diff --git a/plugins/bazel/src/index.ts b/plugins/version-file/src/index.ts similarity index 75% rename from plugins/bazel/src/index.ts rename to plugins/version-file/src/index.ts index c8f6a35e2..9880775fe 100644 --- a/plugins/bazel/src/index.ts +++ b/plugins/version-file/src/index.ts @@ -13,11 +13,11 @@ const pluginOptions = t.partial({ /** Path to file (from where auto is executed) where the version is stored */ versionFile: t.string, - /** Bazel script that executes release pipeline stages */ + /** Optional script that executes release pipeline stages */ releaseScript: t.string }); -export type IBazelPluginOptions = t.TypeOf; +export type IVersionFilePluginOptions = t.TypeOf; /** * Reads version file from location specified in config @@ -34,7 +34,8 @@ async function writeNewVersion(auto: Auto, version: string, versionFile: string) } /** Reset the scope changes of all the packages */ -async function gitReset() { +async function gitReset(auto: Auto) { + auto.logger.veryVerbose.info("Hard resetting local changes") await execPromise("git", ["reset", "--hard", "HEAD"]); } @@ -44,21 +45,21 @@ function makeCanaryNotes(canaryVersion: string){ } -/** Plugin to orchestrate releases in a Bazel repo */ -export default class BazelPlugin implements IPlugin { +/** Plugin to orchestrate releases in a repo where version is maintained in a flat file */ +export default class VersionFilePlugin implements IPlugin { /** The name of the plugin */ - name = 'bazel'; + name = 'VersionFile'; /** Version file location */ readonly versionFile: string; /** Release script location */ - readonly releaseScript: string + readonly releaseScript: string | undefined /** Initialize the plugin with it's options */ - constructor(options: IBazelPluginOptions) { + constructor(options: IVersionFilePluginOptions) { this.versionFile = options.versionFile ?? "VERSION"; - this.releaseScript = options.releaseScript ?? "./tools/release.sh" + this.releaseScript = options.releaseScript } @@ -109,10 +110,14 @@ export default class BazelPlugin implements IPlugin { }); auto.hooks.publish.tapPromise(this.name, async () => { - auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); - // Call release script - await execPromise(this.releaseScript, ["release"]) + // Call release script if provided + if(this.releaseScript){ + auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); + await execPromise(this.releaseScript, ["release"]) + } else { + auto.logger.log.info("Skipping calling release script in repo since none was provided"); + } // push tag and version change commit up await execPromise("git", ["push", auto.remote, branch || auto.baseBranch, "--tags"]); @@ -127,15 +132,22 @@ export default class BazelPlugin implements IPlugin { const nextVersion = inc(current, bump as ReleaseType); const canaryVersion = `${nextVersion}-${canaryIdentifier}`; + auto.logger.log.info(`Marking version as ${canaryVersion}`); + // Write Canary version await writeNewVersion(auto, canaryVersion, this.versionFile) - // Ship canary release - auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); - await execPromise(this.releaseScript, ["snapshot"]); + // Ship canary release if release script is provided + if(this.releaseScript){ + auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); + await execPromise(this.releaseScript, ["snapshot"]); + } else { + auto.logger.log.info("Skipping calling release script in repo since none was provided"); + } + // Reset temporary canary versioning - await gitReset(); + await gitReset(auto); return { newVersion: canaryVersion, @@ -164,9 +176,13 @@ export default class BazelPlugin implements IPlugin { // Write version to file await writeNewVersion(auto, prefixedVersion, this.versionFile) - // Ship canary release - auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); - await execPromise(this.releaseScript, ["snapshot"]); + // ship next release if release script is provided + if(this.releaseScript){ + auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); + await execPromise(this.releaseScript, ["snapshot"]); + } else { + auto.logger.log.info("Skipping calling release script in repo since none was provided"); + } // Push next tag await execPromise("git", [ diff --git a/plugins/bazel/tsconfig.json b/plugins/version-file/tsconfig.json similarity index 100% rename from plugins/bazel/tsconfig.json rename to plugins/version-file/tsconfig.json From da1d63b4bb0436a6e6e435d1e23a4339d7ec0655 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Mon, 15 Nov 2021 16:22:27 -0800 Subject: [PATCH 07/16] include the version-file plugin with the cli --- packages/cli/package.json | 1 + packages/cli/tsconfig.json | 3 +++ plugins/version-file/README.md | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 13f9dfcae..7b38d4d05 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -52,6 +52,7 @@ "@auto-it/core": "link:../core", "@auto-it/npm": "link:../../plugins/npm", "@auto-it/released": "link:../../plugins/released", + "@auto-it/version-file": "link:../../plugins/version-file", "await-to-js": "^3.0.0", "chalk": "^4.0.0", "command-line-application": "^0.10.1", diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 0f4f9be91..c87d50c51 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -17,6 +17,9 @@ }, { "path": "../../plugins/released" + }, + { + "path": "../../plugins/version-file" } ] } diff --git a/plugins/version-file/README.md b/plugins/version-file/README.md index 4d136d1ba..2043ad867 100644 --- a/plugins/version-file/README.md +++ b/plugins/version-file/README.md @@ -6,7 +6,7 @@ Optional input for a release script to call during the publish/canary/next hooks ## Installation -This plugin is not included with the `auto` CLI installed via NPM. To install: +This plugin is included with the `auto` CLI so you do not have to install it. To install if you are using the `auto` API directly: ```bash npm i --save-dev @auto-it/version-file From 6055c445104b4172859765f1cd97fe6fbf50694b Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Mon, 15 Nov 2021 16:32:09 -0800 Subject: [PATCH 08/16] Fix straggling naming reference --- tsconfig.dev.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.dev.json b/tsconfig.dev.json index 97ebdf29d..027fb450a 100644 --- a/tsconfig.dev.json +++ b/tsconfig.dev.json @@ -93,7 +93,7 @@ "path": "plugins/sbt" }, { - "path": "plugins/bazel" + "path": "plugins/version-file" } ] } \ No newline at end of file From 163c082b932f68ec5eae0a85ece74b191a9a33a7 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Tue, 16 Nov 2021 09:33:32 -0800 Subject: [PATCH 09/16] rename releaseScript to publishScript to keep naming consistant --- .../__tests__/version-file.test.ts | 6 ++--- plugins/version-file/src/index.ts | 24 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/plugins/version-file/__tests__/version-file.test.ts b/plugins/version-file/__tests__/version-file.test.ts index 1932d54b1..ec7c482ec 100644 --- a/plugins/version-file/__tests__/version-file.test.ts +++ b/plugins/version-file/__tests__/version-file.test.ts @@ -148,7 +148,7 @@ describe("Test Release Types", () => { mockFs({ "VERSION": `1.0.0`, }); - const plugin = new BazelPlugin({releaseScript:"./tools/release.sh"}); + const plugin = new BazelPlugin({publishScript:"./tools/release.sh"}); const hooks = makeHooks(); plugin.apply({ @@ -199,7 +199,7 @@ describe("Test Release Types", () => { mockFs({ "VERSION": `1.0.0`, }); - const plugin = new BazelPlugin({releaseScript:"./tools/release.sh"}); + const plugin = new BazelPlugin({publishScript:"./tools/release.sh"}); const hooks = makeHooks(); plugin.apply(({ @@ -272,7 +272,7 @@ describe("Test Release Types", () => { mockFs({ "VERSION": `1.0.0`, }); - const plugin = new BazelPlugin({releaseScript:"./tools/release.sh"}); + const plugin = new BazelPlugin({publishScript:"./tools/release.sh"}); const hooks = makeHooks(); plugin.apply(({ diff --git a/plugins/version-file/src/index.ts b/plugins/version-file/src/index.ts index 9880775fe..9b7245cea 100644 --- a/plugins/version-file/src/index.ts +++ b/plugins/version-file/src/index.ts @@ -14,7 +14,7 @@ const pluginOptions = t.partial({ versionFile: t.string, /** Optional script that executes release pipeline stages */ - releaseScript: t.string + publishScript: t.string }); export type IVersionFilePluginOptions = t.TypeOf; @@ -54,12 +54,12 @@ export default class VersionFilePlugin implements IPlugin { readonly versionFile: string; /** Release script location */ - readonly releaseScript: string | undefined + readonly publishScript: string | undefined /** Initialize the plugin with it's options */ constructor(options: IVersionFilePluginOptions) { this.versionFile = options.versionFile ?? "VERSION"; - this.releaseScript = options.releaseScript + this.publishScript = options.publishScript } @@ -112,9 +112,9 @@ export default class VersionFilePlugin implements IPlugin { auto.hooks.publish.tapPromise(this.name, async () => { // Call release script if provided - if(this.releaseScript){ - auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); - await execPromise(this.releaseScript, ["release"]) + if(this.publishScript){ + auto.logger.log.info(`Calling release script in repo at ${this.publishScript}`); + await execPromise(this.publishScript, ["release"]) } else { auto.logger.log.info("Skipping calling release script in repo since none was provided"); } @@ -138,9 +138,9 @@ export default class VersionFilePlugin implements IPlugin { await writeNewVersion(auto, canaryVersion, this.versionFile) // Ship canary release if release script is provided - if(this.releaseScript){ - auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); - await execPromise(this.releaseScript, ["snapshot"]); + if(this.publishScript){ + auto.logger.log.info(`Calling release script in repo at ${this.publishScript}`); + await execPromise(this.publishScript, ["snapshot"]); } else { auto.logger.log.info("Skipping calling release script in repo since none was provided"); } @@ -177,9 +177,9 @@ export default class VersionFilePlugin implements IPlugin { await writeNewVersion(auto, prefixedVersion, this.versionFile) // ship next release if release script is provided - if(this.releaseScript){ - auto.logger.log.info(`Calling release script in repo at ${this.releaseScript}`); - await execPromise(this.releaseScript, ["snapshot"]); + if(this.publishScript){ + auto.logger.log.info(`Calling release script in repo at ${this.publishScript}`); + await execPromise(this.publishScript, ["snapshot"]); } else { auto.logger.log.info("Skipping calling release script in repo since none was provided"); } From c645dc8ae120145db7758627fa3d644e90ab539a Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Mon, 29 Nov 2021 13:26:45 -0800 Subject: [PATCH 10/16] Fix issue with getting last release in canary builds with no previous versions --- plugins/version-file/src/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/version-file/src/index.ts b/plugins/version-file/src/index.ts index 9b7245cea..dd8a2c719 100644 --- a/plugins/version-file/src/index.ts +++ b/plugins/version-file/src/index.ts @@ -126,9 +126,11 @@ export default class VersionFilePlugin implements IPlugin { auto.hooks.canary.tapPromise(this.name, async ({ bump, canaryIdentifier}) => { // Figure out canary version - const lastRelease = await auto.git!.getLatestRelease(); - const [, latestTag = lastRelease] = await auto.git!.getLatestTagInBranch() - const current = await auto.getCurrentVersion(latestTag); + const lastRelease = + (await auto.git!.getLatestRelease()) || + (await auto.git?.getLastTagNotInBaseBranch(prereleaseBranch)) || + (await getPreviousVersion(auto, this.versionFile)); + const current = await auto.getCurrentVersion(lastRelease); const nextVersion = inc(current, bump as ReleaseType); const canaryVersion = `${nextVersion}-${canaryIdentifier}`; From 5f1618ec943d81eb103a13cb69b8fa3608d5ec96 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Mon, 29 Nov 2021 14:54:31 -0800 Subject: [PATCH 11/16] change plugin name to match convention --- plugins/version-file/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/version-file/src/index.ts b/plugins/version-file/src/index.ts index dd8a2c719..808e9a2f7 100644 --- a/plugins/version-file/src/index.ts +++ b/plugins/version-file/src/index.ts @@ -48,7 +48,7 @@ function makeCanaryNotes(canaryVersion: string){ /** Plugin to orchestrate releases in a repo where version is maintained in a flat file */ export default class VersionFilePlugin implements IPlugin { /** The name of the plugin */ - name = 'VersionFile'; + name = 'version-file'; /** Version file location */ readonly versionFile: string; From 367ddcdb50f73d10e979b2f35add7dceabb8da56 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Tue, 30 Nov 2021 14:31:22 -0800 Subject: [PATCH 12/16] remove duplicate dash in canary version names --- plugins/version-file/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/version-file/src/index.ts b/plugins/version-file/src/index.ts index 808e9a2f7..6892a7946 100644 --- a/plugins/version-file/src/index.ts +++ b/plugins/version-file/src/index.ts @@ -132,7 +132,7 @@ export default class VersionFilePlugin implements IPlugin { (await getPreviousVersion(auto, this.versionFile)); const current = await auto.getCurrentVersion(lastRelease); const nextVersion = inc(current, bump as ReleaseType); - const canaryVersion = `${nextVersion}-${canaryIdentifier}`; + const canaryVersion = `${nextVersion}${canaryIdentifier}`; auto.logger.log.info(`Marking version as ${canaryVersion}`); From 475950b3ba6058175fcefec7a559d2c84a8b3fa9 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Tue, 21 Dec 2021 14:36:59 -0500 Subject: [PATCH 13/16] fix failing test --- plugins/version-file/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/version-file/src/index.ts b/plugins/version-file/src/index.ts index 6892a7946..808e9a2f7 100644 --- a/plugins/version-file/src/index.ts +++ b/plugins/version-file/src/index.ts @@ -132,7 +132,7 @@ export default class VersionFilePlugin implements IPlugin { (await getPreviousVersion(auto, this.versionFile)); const current = await auto.getCurrentVersion(lastRelease); const nextVersion = inc(current, bump as ReleaseType); - const canaryVersion = `${nextVersion}${canaryIdentifier}`; + const canaryVersion = `${nextVersion}-${canaryIdentifier}`; auto.logger.log.info(`Marking version as ${canaryVersion}`); From 59292fb086f9527133ceedcd38f72889d3d4c827 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Wed, 22 Dec 2021 15:21:43 -0500 Subject: [PATCH 14/16] Fix version in commit string not being replaced. Align versioning scheme with other plugins --- plugins/version-file/__tests__/version-file.test.ts | 12 ++++++------ plugins/version-file/src/index.ts | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/version-file/__tests__/version-file.test.ts b/plugins/version-file/__tests__/version-file.test.ts index ec7c482ec..4fe99a28b 100644 --- a/plugins/version-file/__tests__/version-file.test.ts +++ b/plugins/version-file/__tests__/version-file.test.ts @@ -76,8 +76,8 @@ describe("Version File Write Operations", () => { await hooks.version.promise({bump: SEMVER.major}) expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("2.0.0") // check that the proper git operations were performed - expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "'\"Bump version to: %s [skip ci]\"'"]); - expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "2.0.0"]); + expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "Bump version to: v2.0.0 [skip ci]"]); + expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "v2.0.0"]); }); test("It should version the file properly for minor releases", async () => { @@ -97,8 +97,8 @@ describe("Version File Write Operations", () => { await hooks.version.promise({bump: SEMVER.minor}) expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("1.1.0"); // check that the proper git operations were performed - expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "'\"Bump version to: %s [skip ci]\"'"]); - expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "1.1.0"]); + expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "Bump version to: v1.1.0 [skip ci]"]); + expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "v1.1.0"]); }); test("It should version the file properly for patch releases", async () => { @@ -118,8 +118,8 @@ describe("Version File Write Operations", () => { await hooks.version.promise({bump: SEMVER.patch}) expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("1.0.1"); // check that the proper git operations were performed - expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "'\"Bump version to: %s [skip ci]\"'"]); - expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "1.0.1"]); + expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "Bump version to: v1.0.1 [skip ci]"]); + expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "v1.0.1"]); }); }) diff --git a/plugins/version-file/src/index.ts b/plugins/version-file/src/index.ts index 808e9a2f7..7865ff9bc 100644 --- a/plugins/version-file/src/index.ts +++ b/plugins/version-file/src/index.ts @@ -4,7 +4,6 @@ import * as t from "io-ts"; import * as fs from "fs"; import { inc, ReleaseType } from "semver"; -const VERSION_COMMIT_MESSAGE = `'"Bump version to: %s [skip ci]"'`; const readFile = promisify(fs.readFile); const writeFile = promisify(fs.writeFile); @@ -97,10 +96,10 @@ export default class VersionFilePlugin implements IPlugin { if (newVersion){ // Seal versions via commit and tag await writeNewVersion(auto, newVersion, this.versionFile) - await execPromise("git", ["commit", "-am", VERSION_COMMIT_MESSAGE]); + await execPromise("git", ["commit", "-am", `Bump version to: v${newVersion} [skip ci]`]); await execPromise("git", [ "tag", - newVersion + `v${newVersion}` ]); auto.logger.verbose.info("Successfully versioned repo"); } else { From ceba7a215a28cf8500f7672510aced5d1e614cf4 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Thu, 3 Feb 2022 09:27:37 -0800 Subject: [PATCH 15/16] Make sure quotes are included in commit message --- plugins/version-file/__tests__/version-file.test.ts | 2 +- plugins/version-file/src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/version-file/__tests__/version-file.test.ts b/plugins/version-file/__tests__/version-file.test.ts index 4fe99a28b..dee60187a 100644 --- a/plugins/version-file/__tests__/version-file.test.ts +++ b/plugins/version-file/__tests__/version-file.test.ts @@ -118,7 +118,7 @@ describe("Version File Write Operations", () => { await hooks.version.promise({bump: SEMVER.patch}) expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("1.0.1"); // check that the proper git operations were performed - expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "Bump version to: v1.0.1 [skip ci]"]); + expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "\"Bump version to: v1.0.1 [skip ci]\""]); expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "v1.0.1"]); }); }) diff --git a/plugins/version-file/src/index.ts b/plugins/version-file/src/index.ts index 7865ff9bc..87a16c74e 100644 --- a/plugins/version-file/src/index.ts +++ b/plugins/version-file/src/index.ts @@ -96,7 +96,7 @@ export default class VersionFilePlugin implements IPlugin { if (newVersion){ // Seal versions via commit and tag await writeNewVersion(auto, newVersion, this.versionFile) - await execPromise("git", ["commit", "-am", `Bump version to: v${newVersion} [skip ci]`]); + await execPromise("git", ["commit", "-am", `"Bump version to: v${newVersion} [skip ci]"`]); await execPromise("git", [ "tag", `v${newVersion}` From a9cac5d8188a1fb0ce17fa8a4666df7b7c39ee11 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Thu, 3 Feb 2022 10:13:01 -0800 Subject: [PATCH 16/16] Fix more tests --- plugins/version-file/__tests__/version-file.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/version-file/__tests__/version-file.test.ts b/plugins/version-file/__tests__/version-file.test.ts index dee60187a..003bf83a4 100644 --- a/plugins/version-file/__tests__/version-file.test.ts +++ b/plugins/version-file/__tests__/version-file.test.ts @@ -76,7 +76,7 @@ describe("Version File Write Operations", () => { await hooks.version.promise({bump: SEMVER.major}) expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("2.0.0") // check that the proper git operations were performed - expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "Bump version to: v2.0.0 [skip ci]"]); + expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "\"Bump version to: v2.0.0 [skip ci]\""]); expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "v2.0.0"]); }); @@ -97,7 +97,7 @@ describe("Version File Write Operations", () => { await hooks.version.promise({bump: SEMVER.minor}) expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("1.1.0"); // check that the proper git operations were performed - expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "Bump version to: v1.1.0 [skip ci]"]); + expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "\"Bump version to: v1.1.0 [skip ci]\""]); expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "v1.1.0"]); });