Skip to content

Commit 52799a0

Browse files
authored
Merge pull request #2472 from KetanReddy/bugfix/version-file-tags
Respect `noVersionPrefix` option in the Version File plugin
2 parents 32f3d78 + 8e8e7c7 commit 52799a0

File tree

2 files changed

+58
-16
lines changed

2 files changed

+58
-16
lines changed

plugins/version-file/__tests__/version-file.test.ts

+54-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Auto, { SEMVER } from '@auto-it/core';
22
import mockFs from "mock-fs";
33
import fs from "fs";
4-
import BazelPlugin from '../src';
4+
import VersionFilePlugin from '../src';
55
import { makeHooks } from '@auto-it/core/dist/utils/make-hooks';
66
import { dummyLog } from "@auto-it/core/dist/utils/logger";
77

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

3333
plugin.apply({
@@ -44,7 +44,7 @@ describe('Version File Read Operations', () => {
4444
mockFs({
4545
"VERSIONFILE": `1.0.0`,
4646
});
47-
const plugin = new BazelPlugin({versionFile: "VERSIONFILE"});
47+
const plugin = new VersionFilePlugin({versionFile: "VERSIONFILE"});
4848
const hooks = makeHooks();
4949

5050
plugin.apply({
@@ -63,14 +63,19 @@ describe("Version File Write Operations", () => {
6363
mockFs({
6464
"VERSION": `1.0.0`,
6565
});
66-
const plugin = new BazelPlugin({});
66+
const plugin = new VersionFilePlugin({});
6767
const hooks = makeHooks();
6868

69+
const prefixRelease: (a: string) => string = (version: string) => {
70+
return `v${version}`;
71+
};
72+
6973
plugin.apply({
7074
hooks,
7175
remote: "origin",
7276
baseBranch: "main",
7377
logger: dummyLog(),
78+
prefixRelease
7479
} as Auto);
7580

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

95+
const prefixRelease: (a: string) => string = (version: string) => {
96+
return `v${version}`;
97+
};
98+
9099
plugin.apply({
91100
hooks,
92101
remote: "origin",
93102
baseBranch: "main",
94103
logger: dummyLog(),
104+
prefixRelease
95105
} as Auto);
96106

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

121+
const prefixRelease: (a: string) => string = (version: string) => {
122+
return `v${version}`;
123+
};
124+
111125
plugin.apply({
112126
hooks,
113127
remote: "origin",
114128
baseBranch: "main",
115129
logger: dummyLog(),
130+
prefixRelease
116131
} as Auto);
117132

118133
await hooks.version.promise({bump: SEMVER.patch})
@@ -121,14 +136,40 @@ describe("Version File Write Operations", () => {
121136
expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "\"Bump version to: v1.0.1 [skip ci]\""]);
122137
expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "v1.0.1"]);
123138
});
139+
140+
test("It should version the file properly for without a prefix", async () => {
141+
mockFs({
142+
"VERSION": `1.0.0`,
143+
});
144+
const plugin = new VersionFilePlugin({});
145+
const hooks = makeHooks();
146+
147+
const prefixRelease: (a: string) => string = (version: string) => {
148+
return `${version}`;
149+
};
150+
151+
plugin.apply({
152+
hooks,
153+
remote: "origin",
154+
baseBranch: "main",
155+
logger: dummyLog(),
156+
prefixRelease
157+
} as Auto);
158+
159+
await hooks.version.promise({bump: SEMVER.patch})
160+
expect(fs.readFileSync("VERSION", "utf-8")).toStrictEqual("1.0.1");
161+
// check that the proper git operations were performed
162+
expect(execPromise).toHaveBeenNthCalledWith(1, "git", ["commit", "-am", "\"Bump version to: 1.0.1 [skip ci]\""]);
163+
expect(execPromise).toHaveBeenNthCalledWith(2, "git", ["tag", "1.0.1"]);
164+
});
124165
})
125166

126167
describe("Test Release Types", () => {
127168
test("Full release with no release script", async () => {
128169
mockFs({
129170
"VERSION": `1.0.0`,
130171
});
131-
const plugin = new BazelPlugin({});
172+
const plugin = new VersionFilePlugin({});
132173
const hooks = makeHooks();
133174

134175
plugin.apply({
@@ -148,7 +189,7 @@ describe("Test Release Types", () => {
148189
mockFs({
149190
"VERSION": `1.0.0`,
150191
});
151-
const plugin = new BazelPlugin({publishScript:"./tools/release.sh"});
192+
const plugin = new VersionFilePlugin({publishScript:"./tools/release.sh"});
152193
const hooks = makeHooks();
153194

154195
plugin.apply({
@@ -171,7 +212,7 @@ describe("Test Release Types", () => {
171212
mockFs({
172213
"VERSION": `1.0.0`,
173214
});
174-
const plugin = new BazelPlugin({});
215+
const plugin = new VersionFilePlugin({});
175216
const hooks = makeHooks();
176217

177218
plugin.apply(({
@@ -199,7 +240,7 @@ describe("Test Release Types", () => {
199240
mockFs({
200241
"VERSION": `1.0.0`,
201242
});
202-
const plugin = new BazelPlugin({publishScript:"./tools/release.sh"});
243+
const plugin = new VersionFilePlugin({publishScript:"./tools/release.sh"});
203244
const hooks = makeHooks();
204245

205246
plugin.apply(({
@@ -235,7 +276,7 @@ describe("Test Release Types", () => {
235276
mockFs({
236277
"VERSION": `1.0.0`,
237278
});
238-
const plugin = new BazelPlugin({});
279+
const plugin = new VersionFilePlugin({});
239280
const hooks = makeHooks();
240281

241282
plugin.apply(({
@@ -272,7 +313,7 @@ describe("Test Release Types", () => {
272313
mockFs({
273314
"VERSION": `1.0.0`,
274315
});
275-
const plugin = new BazelPlugin({publishScript:"./tools/release.sh"});
316+
const plugin = new VersionFilePlugin({publishScript:"./tools/release.sh"});
276317
const hooks = makeHooks();
277318

278319
plugin.apply(({
@@ -311,7 +352,7 @@ describe("Test Release Types", () => {
311352
mockFs({
312353
VERSION: `1.0.0`,
313354
});
314-
const plugin = new BazelPlugin({
355+
const plugin = new VersionFilePlugin({
315356
publishScript: "./tools/release.sh",
316357
publishScriptReleaseTypeArgs: {
317358
publish: ["args", "for", "publish"],

plugins/version-file/src/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default class VersionFilePlugin implements IPlugin {
7070
/** Release script location */
7171
readonly publishScript: string | undefined
7272

73-
/** */
73+
/** Args to pass to the release script based on release type */
7474
readonly publishScriptReleaseTypeArgs: ReleaseTypeArgs;
7575

7676
/** Initialize the plugin with it's options */
@@ -120,10 +120,11 @@ export default class VersionFilePlugin implements IPlugin {
120120
if (newVersion){
121121
// Seal versions via commit and tag
122122
await writeNewVersion(auto, newVersion, this.versionFile)
123-
await execPromise("git", ["commit", "-am", `"Bump version to: v${newVersion} [skip ci]"`]);
123+
const prefixedVersion = auto.prefixRelease(newVersion)
124+
await execPromise("git", ["commit", "-am", `"Bump version to: ${prefixedVersion} [skip ci]"`]);
124125
await execPromise("git", [
125126
"tag",
126-
`v${newVersion}`
127+
prefixedVersion
127128
]);
128129
auto.logger.verbose.info("Successfully versioned repo");
129130
} else {

0 commit comments

Comments
 (0)