Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect noVersionPrefix option in the Version File plugin #2472

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions plugins/version-file/__tests__/version-file.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Auto, { SEMVER } from '@auto-it/core';
import mockFs from "mock-fs";
import fs from "fs";
import BazelPlugin from '../src';
import VersionFilePlugin from '../src';
import { makeHooks } from '@auto-it/core/dist/utils/make-hooks';
import { dummyLog } from "@auto-it/core/dist/utils/logger";

Expand All @@ -27,7 +27,7 @@ describe('Version File Read Operations', () => {
mockFs({
"VERSION": `1.0.0`,
});
const plugin = new BazelPlugin({});
const plugin = new VersionFilePlugin({});
const hooks = makeHooks();

plugin.apply({
Expand All @@ -44,7 +44,7 @@ describe('Version File Read Operations', () => {
mockFs({
"VERSIONFILE": `1.0.0`,
});
const plugin = new BazelPlugin({versionFile: "VERSIONFILE"});
const plugin = new VersionFilePlugin({versionFile: "VERSIONFILE"});
const hooks = makeHooks();

plugin.apply({
Expand All @@ -63,14 +63,19 @@ describe("Version File Write Operations", () => {
mockFs({
"VERSION": `1.0.0`,
});
const plugin = new BazelPlugin({});
const plugin = new VersionFilePlugin({});
const hooks = makeHooks();

const prefixRelease: (a: string) => string = (version: string) => {
return `v${version}`;
};

plugin.apply({
hooks,
remote: "origin",
baseBranch: "main",
logger: dummyLog(),
prefixRelease
} as Auto);

await hooks.version.promise({bump: SEMVER.major})
Expand All @@ -84,14 +89,19 @@ describe("Version File Write Operations", () => {
mockFs({
"VERSION": `1.0.0`,
});
const plugin = new BazelPlugin({});
const plugin = new VersionFilePlugin({});
const hooks = makeHooks();

const prefixRelease: (a: string) => string = (version: string) => {
return `v${version}`;
};

plugin.apply({
hooks,
remote: "origin",
baseBranch: "main",
logger: dummyLog(),
prefixRelease
} as Auto);

await hooks.version.promise({bump: SEMVER.minor})
Expand All @@ -105,14 +115,19 @@ describe("Version File Write Operations", () => {
mockFs({
"VERSION": `1.0.0`,
});
const plugin = new BazelPlugin({});
const plugin = new VersionFilePlugin({});
const hooks = makeHooks();

const prefixRelease: (a: string) => string = (version: string) => {
return `v${version}`;
};

plugin.apply({
hooks,
remote: "origin",
baseBranch: "main",
logger: dummyLog(),
prefixRelease
} as Auto);

await hooks.version.promise({bump: SEMVER.patch})
Expand All @@ -121,14 +136,40 @@ describe("Version File Write Operations", () => {
expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "\"Bump version to: v1.0.1 [skip ci]\""]);
expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "v1.0.1"]);
});

test("It should version the file properly for without a prefix", async () => {
mockFs({
"VERSION": `1.0.0`,
});
const plugin = new VersionFilePlugin({});
const hooks = makeHooks();

const prefixRelease: (a: string) => string = (version: string) => {
return `${version}`;
};

plugin.apply({
hooks,
remote: "origin",
baseBranch: "main",
logger: dummyLog(),
prefixRelease
} 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: 1.0.1 [skip ci]\""]);
expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "1.0.1"]);
});
})

describe("Test Release Types", () => {
test("Full release with no release script", async () => {
mockFs({
"VERSION": `1.0.0`,
});
const plugin = new BazelPlugin({});
const plugin = new VersionFilePlugin({});
const hooks = makeHooks();

plugin.apply({
Expand All @@ -148,7 +189,7 @@ describe("Test Release Types", () => {
mockFs({
"VERSION": `1.0.0`,
});
const plugin = new BazelPlugin({publishScript:"./tools/release.sh"});
const plugin = new VersionFilePlugin({publishScript:"./tools/release.sh"});
const hooks = makeHooks();

plugin.apply({
Expand All @@ -171,7 +212,7 @@ describe("Test Release Types", () => {
mockFs({
"VERSION": `1.0.0`,
});
const plugin = new BazelPlugin({});
const plugin = new VersionFilePlugin({});
const hooks = makeHooks();

plugin.apply(({
Expand Down Expand Up @@ -199,7 +240,7 @@ describe("Test Release Types", () => {
mockFs({
"VERSION": `1.0.0`,
});
const plugin = new BazelPlugin({publishScript:"./tools/release.sh"});
const plugin = new VersionFilePlugin({publishScript:"./tools/release.sh"});
const hooks = makeHooks();

plugin.apply(({
Expand Down Expand Up @@ -235,7 +276,7 @@ describe("Test Release Types", () => {
mockFs({
"VERSION": `1.0.0`,
});
const plugin = new BazelPlugin({});
const plugin = new VersionFilePlugin({});
const hooks = makeHooks();

plugin.apply(({
Expand Down Expand Up @@ -272,7 +313,7 @@ describe("Test Release Types", () => {
mockFs({
"VERSION": `1.0.0`,
});
const plugin = new BazelPlugin({publishScript:"./tools/release.sh"});
const plugin = new VersionFilePlugin({publishScript:"./tools/release.sh"});
const hooks = makeHooks();

plugin.apply(({
Expand Down Expand Up @@ -311,7 +352,7 @@ describe("Test Release Types", () => {
mockFs({
VERSION: `1.0.0`,
});
const plugin = new BazelPlugin({
const plugin = new VersionFilePlugin({
publishScript: "./tools/release.sh",
publishScriptReleaseTypeArgs: {
publish: ["args", "for", "publish"],
Expand Down
7 changes: 4 additions & 3 deletions plugins/version-file/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class VersionFilePlugin implements IPlugin {
/** Release script location */
readonly publishScript: string | undefined

/** */
/** Args to pass to the release script based on release type */
readonly publishScriptReleaseTypeArgs: ReleaseTypeArgs;

/** Initialize the plugin with it's options */
Expand Down Expand Up @@ -120,10 +120,11 @@ 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]"`]);
const prefixedVersion = auto.prefixRelease(newVersion)
await execPromise("git", ["commit", "-am", `"Bump version to: ${prefixedVersion} [skip ci]"`]);
await execPromise("git", [
"tag",
`v${newVersion}`
prefixedVersion
]);
auto.logger.verbose.info("Successfully versioned repo");
} else {
Expand Down
Loading