Skip to content

Commit

Permalink
feat(): patch renovate post execution mode
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Feb 4, 2024
1 parent 5ebc9d8 commit 8eef82c
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 14 deletions.
37 changes: 23 additions & 14 deletions packages/create-next-repo/src/patches/patchInternalRenovate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@ describe("patchInternalRenovate", () => {
mockFsReadJsonSync.mockReturnValueOnce({
packageRules: [
{
matchDepTypes: ["devDependencies"],
matchUpdateTypes: ["minor", "patch"],
automerge: true,
excludePackagePatterns: ["^@next-core/", "^@next-libs/"],
enabled: false,
},
{
groupName: "next-core packages",
matchPackagePatterns: ["^@next-core/"],
automerge: false,
matchUpdateTypes: ["major"],
enabled: false,
},
{
groupName: "next-core packages",
matchPackagePatterns: ["^@next-core/"],
matchUpdateTypes: ["major"],
enabled: false,
matchUpdateTypes: ["minor", "patch"],
},
{
groupName: "next-libs packages",
matchPackagePatterns: ["^@next-libs/"],
separateMajorMinor: false,
},
],
});
Expand All @@ -49,14 +53,18 @@ describe("patchInternalRenovate", () => {
{
packageRules: [
{
matchDepTypes: ["devDependencies"],
matchUpdateTypes: ["minor", "patch"],
automerge: true,
excludePackagePatterns: ["^@next-core/", "^@next-libs/"],
enabled: false,
},
{
matchPackagePatterns: ["^@next-core/"],
matchUpdateTypes: ["major"],
enabled: false,
},
{
groupName: "next-core packages",
matchPackagePatterns: ["^@next-core/"],
automerge: false,
matchUpdateTypes: ["minor", "patch"],
postUpgradeTasks: {
commands: [
"yarn renew",
Expand All @@ -65,6 +73,7 @@ describe("patchInternalRenovate", () => {
"yarn-deduplicate yarn.lock",
"yarn",
],
executionMode: "branch",
fileFilters: [
"**/*",
".gitignore",
Expand All @@ -76,9 +85,9 @@ describe("patchInternalRenovate", () => {
},
},
{
matchPackagePatterns: ["^@next-core/"],
matchUpdateTypes: ["major"],
enabled: false,
groupName: "next-libs packages",
matchPackagePatterns: ["^@next-libs/"],
separateMajorMinor: false,
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function patchInternalRenovate(dest: string): Promise<void> {
"yarn-deduplicate yarn.lock",
"yarn",
],
executionMode: "branch",
fileFilters: [
"**/*",
".gitignore",
Expand Down
5 changes: 5 additions & 0 deletions packages/dev-dependencies/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
onlyAutoMergePatchVersions,
enableLernaWithNx,
updateRenovateForV2,
updateRenovatePostExecutionMode,
} = require("./patches");

function initAndGetDevDependenciesVersion() {
Expand Down Expand Up @@ -204,6 +205,10 @@ module.exports = async function patch() {
updateRenovateForV2();
}

if (semver.lt(currentRenewVersion, "1.18.0")) {
updateRenovatePostExecutionMode();
}

updateDevDependenciesVersion();
};

Expand Down
1 change: 1 addition & 0 deletions packages/dev-dependencies/patches/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ exports.migrateLazyBricksWithJest = require("./migrateLazyBricksWithJest");
exports.onlyAutoMergePatchVersions = require("./onlyAutoMergePatchVersions");
exports.enableLernaWithNx = require("./enableLernaWithNx");
exports.updateRenovateForV2 = require("./updateRenovateForV2");
exports.updateRenovatePostExecutionMode = require("./updateRenovatePostExecutionMode");
1 change: 1 addition & 0 deletions packages/dev-dependencies/patches/updateRenovateForV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function updateRenovateForV2() {
"yarn-deduplicate yarn.lock",
"yarn",
],
executionMode: "branch",
fileFilters: [
"**/*",
".gitignore",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe("updateRenovateForV2", () => {
"yarn-deduplicate yarn.lock",
"yarn",
],
executionMode: "branch",
fileFilters: [
"**/*",
".gitignore",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const path = require("path");
const { readJson, writeJsonFile } = require("../utils");

function updateRenovatePostExecutionMode() {
const renovateJsonPath = path.resolve("renovate.json");
const renovateJson = readJson(renovateJsonPath);

if (
renovateJson.postUpgradeTasks &&
renovateJson.postUpgradeTasks.executionMode !== "branch"
) {
renovateJson.postUpgradeTasks.executionMode = "branch";
writeJsonFile(renovateJsonPath, renovateJson);
}
}

module.exports = updateRenovatePostExecutionMode;
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const updateRenovatePostExecutionMode = require("./updateRenovatePostExecutionMode");
const { writeJsonFile, readJson } = require("../utils");

jest.mock("../utils");

describe("updateRenovatePostExecutionMode", () => {
afterEach(() => {
jest.clearAllMocks();
});

it("should ignore if no postUpgradeTasks", () => {
readJson.mockReturnValueOnce({
packageRules: [
{
groupName: "next-core packages",
},
],
});
updateRenovatePostExecutionMode();
expect(writeJsonFile).not.toBeCalled();
});

it("should update fileFilters", () => {
readJson.mockReturnValueOnce({
postUpgradeTasks: {
commands: ["yarn renew"],
},
});
updateRenovatePostExecutionMode();
expect(writeJsonFile).toBeCalledWith(
expect.stringContaining("renovate.json"),
{
postUpgradeTasks: {
commands: ["yarn renew"],
executionMode: "branch",
},
}
);
});
});

0 comments on commit 8eef82c

Please sign in to comment.