Skip to content

Commit

Permalink
Merge pull request #3 from drashland/fix-pre-release-version-replacing
Browse files Browse the repository at this point in the history
fix: Fix pre release bump not updating other versions
  • Loading branch information
ebebbington authored Nov 5, 2020
2 parents 5555e61 + ff89a39 commit 60ab495
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 144 deletions.
53 changes: 38 additions & 15 deletions ci/bumper_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,9 @@ export class BumperService {
return this.bumpForPreRelease(files, write);
}

files.forEach((file) => {
file.replaceWith = file.replaceWith.replace(
"{{ latestDenoVersion }}",
this.latest_versions.deno,
);

file.replaceWith = file.replaceWith.replace(
"{{ latestStdVersion }}",
this.latest_versions.deno_std,
);

file.replaceWith = file.replaceWith.replace(
"{{ latestDrashVersion }}",
this.latest_versions.drash,
);
files = this.replaceVersionVariables(files);

files.forEach((file) => {
ret.push(this.writeFile(file, write));
});

Expand Down Expand Up @@ -157,6 +144,8 @@ export class BumperService {
this.parsed_args.branch.indexOf("v") + 1,
); // 1.0.5

files = this.replaceVersionVariables(files)

files.forEach((file) => {
file.replaceWith = file.replaceWith.replace(
"{{ thisModulesLatestVersion }}",
Expand Down Expand Up @@ -289,4 +278,38 @@ export class BumperService {

return "";
}

//////////////////////////////////////////////////////////////////////////////
// FILE MARKER - METHODS - PRIVATE ///////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

/**
* Replaces template variables with what values they should have
*
* @param files - The list of files to replace the `replaceWith` with
*
* @example
* Say `file.replaceWith` is `{{ latestStdVersion }}`, this method will replace that with
* the latest std version
*/
private replaceVersionVariables (files: File[]): File[] {
files.forEach((file) => {
file.replaceWith = file.replaceWith.replace(
"{{ latestDenoVersion }}",
this.latest_versions.deno,
);

file.replaceWith = file.replaceWith.replace(
"{{ latestStdVersion }}",
this.latest_versions.deno_std,
);

file.replaceWith = file.replaceWith.replace(
"{{ latestDrashVersion }}",
this.latest_versions.drash,
);
});

return files
}
}
262 changes: 133 additions & 129 deletions tests/ci/bumper_service_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,134 +5,6 @@ const b = new BumperService("rhum");
const c = new BumperService("rhum", ["--version=v1.2.3"]);
const d = new BumperService("my-cool-module-dude-omg-yea");

Rhum.testPlan(async () => {
Rhum.testSuite("constructor()", () => {
Rhum.testCase("sets module_name", () => {
Rhum.asserts.assertEquals(
b.getModuleName(),
"rhum",
);
});
Rhum.testCase("sets parsed_args", () => {
Rhum.asserts.assertEquals(
b.getParsedArgs(),
{},
);
Rhum.asserts.assertEquals(
c.getParsedArgs(),
{
branch: "v1.2.3",
},
);
});
Rhum.testCase("sets is_for_pre_release", () => {
Rhum.asserts.assertEquals(
b.isForPreRelease(),
false,
);
Rhum.asserts.assertEquals(
c.isForPreRelease(),
true,
);
});
Rhum.testCase("sets latest_versions", async () => {
const versions = {
rhum: await c.getModulesLatestVersion("rhum"),
deno: await c.getModulesLatestVersion("deno"),
deno_std: await c.getModulesLatestVersion("std"),
drash: await c.getModulesLatestVersion("drash"),
};
Rhum.asserts.assertEquals(
await c.getLatestVersions(),
versions,
);
});
Rhum.testCase(
"defaults to (Module not found) if latest version can't be found",
async () => {
const versions = {
"my-cool-module-dude-omg-yea": "(Module not found)",
deno: await c.getModulesLatestVersion("deno"),
deno_std: await c.getModulesLatestVersion("std"),
drash: await c.getModulesLatestVersion("drash"),
};
Rhum.asserts.assertEquals(
await d.getLatestVersions(),
versions,
);
},
);
});

await Rhum.testSuite("bump", async () => {
const files = await b.bump([
{
filename: "./tests/data/master.yml",
replaceTheRegex: /deno: \[".+"\]/g,
replaceWith: `deno: ["{{ latestDenoVersion }}"]`,
},
{
filename: "./tests/data/bumper.yml",
replaceTheRegex: /deno: \[".+"\]/g,
replaceWith: `deno: ["{{ latestDenoVersion }}"]`,
},
{
filename: "./tests/data/pre_release.yml",
replaceTheRegex: /deno: \[".+"\]/g,
replaceWith: `deno: ["{{ latestDenoVersion }}"]`,
},
], false);

const master = files[0];
const bumper = files[1];
const preRelease = files[2];

Rhum.testCase("bumps master.yml correctly", () => {
Rhum.asserts.assertEquals(master, data_bumpMaster);
});
Rhum.testCase("bumps bumper.yml correctly", () => {
Rhum.asserts.assertEquals(bumper, data_bumpBumper);
});
Rhum.testCase("bumps pre_release.yml correctly", () => {
Rhum.asserts.assertEquals(preRelease, data_bumpPreRelease);
});
});

await Rhum.testSuite("bump for pre-release", async () => {
const files = await c.bump([
{
filename: "./tests/data/README.md",
replaceTheRegex: /rhum\@v.+mod.ts"/g,
replaceWith: `rhum@v{{ thisModulesLatestVersion }}/mod.ts"`,
},
{
filename: "./tests/data/egg.json",
replaceTheRegex: /"version": ".+"/,
replaceWith: `"version": "{{ thisModulesLatestVersion }}"`,
},
{
filename: "./tests/data/mod.ts",
replaceTheRegex: /version = ".+"/g,
replaceWith: `version = "v{{ thisModulesLatestVersion }}"`,
},
], false);

const readme = files[0];
const eggJson = files[1];
const mod = files[2];

Rhum.testCase("bumps README.md correctly", () => {
Rhum.asserts.assertEquals(readme, data_bumpReadme);
});
Rhum.testCase("bumps egg.json correctly", () => {
Rhum.asserts.assertEquals(eggJson, data_bumpEggJson);
});
Rhum.testCase("bumps mod.ts correctly", () => {
Rhum.asserts.assertEquals(mod, data_bumpMod);
});
});
});

////////////////////////////////////////////////////////////////////////////////
// DATA PROVIDERS //////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -361,7 +233,7 @@ const data_bumpEggJson = `{
`;

const data_bumpMod =
`import { assertions, asserts } from "./src/rhum_asserts.ts";
`import { assertions, asserts } from "./src/rhum_asserts.ts";
import type {
ITestCase,
ITestPlan,
Expand All @@ -378,3 +250,135 @@ const encoder = new TextEncoder();
export type { Constructor, Stubbed } from "./src/types.ts";
export { MockBuilder } from "./src/mock_builder.ts";
`;

////////////////////////////////////////////////////////////////////////////////
// TESTS ///////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

Rhum.testPlan(async () => {
Rhum.testSuite("constructor()", () => {
Rhum.testCase("sets module_name", () => {
Rhum.asserts.assertEquals(
b.getModuleName(),
"rhum",
);
});
Rhum.testCase("sets parsed_args", () => {
Rhum.asserts.assertEquals(
b.getParsedArgs(),
{},
);
Rhum.asserts.assertEquals(
c.getParsedArgs(),
{
branch: "v1.2.3",
},
);
});
Rhum.testCase("sets is_for_pre_release", () => {
Rhum.asserts.assertEquals(
b.isForPreRelease(),
false,
);
Rhum.asserts.assertEquals(
c.isForPreRelease(),
true,
);
});
Rhum.testCase("sets latest_versions", async () => {
const versions = {
rhum: await c.getModulesLatestVersion("rhum"),
deno: await c.getModulesLatestVersion("deno"),
deno_std: await c.getModulesLatestVersion("std"),
drash: await c.getModulesLatestVersion("drash"),
};
Rhum.asserts.assertEquals(
await c.getLatestVersions(),
versions,
);
});
Rhum.testCase(
"defaults to (Module not found) if latest version can't be found",
async () => {
const versions = {
"my-cool-module-dude-omg-yea": "(Module not found)",
deno: await c.getModulesLatestVersion("deno"),
deno_std: await c.getModulesLatestVersion("std"),
drash: await c.getModulesLatestVersion("drash"),
};
Rhum.asserts.assertEquals(
await d.getLatestVersions(),
versions,
);
},
);
});

await Rhum.testSuite("bump", async () => {
const files = await b.bump([
{
filename: "./tests/data/master.yml",
replaceTheRegex: /deno: \[".+"\]/g,
replaceWith: `deno: ["{{ latestDenoVersion }}"]`,
},
{
filename: "./tests/data/bumper.yml",
replaceTheRegex: /deno: \[".+"\]/g,
replaceWith: `deno: ["{{ latestDenoVersion }}"]`,
},
{
filename: "./tests/data/pre_release.yml",
replaceTheRegex: /deno: \[".+"\]/g,
replaceWith: `deno: ["{{ latestDenoVersion }}"]`,
},
], false);

const master = files[0];
const bumper = files[1];
const preRelease = files[2];

Rhum.testCase("bumps master.yml correctly", () => {
Rhum.asserts.assertEquals(master, data_bumpMaster);
});
Rhum.testCase("bumps bumper.yml correctly", () => {
Rhum.asserts.assertEquals(bumper, data_bumpBumper);
});
Rhum.testCase("bumps pre_release.yml correctly", () => {
Rhum.asserts.assertEquals(preRelease, data_bumpPreRelease);
});
});

await Rhum.testSuite("bump for pre-release", async () => {
const files = await c.bump([
{
filename: "./tests/data/README.md",
replaceTheRegex: /rhum\@v.+mod.ts"/g,
replaceWith: `rhum@v{{ thisModulesLatestVersion }}/mod.ts"`,
},
{
filename: "./tests/data/egg.json",
replaceTheRegex: /"version": ".+"/,
replaceWith: `"version": "{{ thisModulesLatestVersion }}"`,
},
{
filename: "./tests/data/mod.ts",
replaceTheRegex: /version = ".+"/g,
replaceWith: `version = "v{{ thisModulesLatestVersion }}"`,
},
], false);

const readme = files[0];
const eggJson = files[1];
const mod = files[2];

Rhum.testCase("bumps README.md correctly", () => {
Rhum.asserts.assertEquals(readme, data_bumpReadme);
});
Rhum.testCase("bumps egg.json correctly", () => {
Rhum.asserts.assertEquals(eggJson, data_bumpEggJson);
});
Rhum.testCase("bumps mod.ts correctly", () => {
Rhum.asserts.assertEquals(mod, data_bumpMod);
});
});
});

0 comments on commit 60ab495

Please sign in to comment.