Skip to content

Commit 9b314f4

Browse files
committed
Make replaceVersionInPackageJson dry-run-aware
1 parent d694648 commit 9b314f4

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎pr-checks/update-release-branch.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export function getCurrentVersion(): string | undefined {
160160
* replace the version in package.json textually.
161161
*/
162162
export function replaceVersionInPackageJson(
163+
options: DryRunOption,
163164
prevVersion: string,
164165
newVersion: string,
165166
): void {
@@ -176,7 +177,13 @@ export function replaceVersionInPackageJson(
176177
prevLineIsCodeql = line.includes('"name": "codeql",');
177178
}
178179

179-
fs.writeFileSync(PACKAGE_JSON, `${output.join("\n")}\n`, "utf8");
180+
if (!options.dryRun) {
181+
fs.writeFileSync(PACKAGE_JSON, `${output.join("\n")}\n`, "utf8");
182+
} else {
183+
console.info(
184+
`[DRY RUN] Would have replaced '${prevVersion}' with '${newVersion}' in package.json`,
185+
);
186+
}
180187
}
181188

182189
/** Represents commits returned by the GitHub API (relevant fields only). */
@@ -672,7 +679,7 @@ export async function prepareNewBranch(
672679
console.log(`Setting version number to '${version}' in package.json`);
673680
const currentPkgVersion = getCurrentVersion();
674681
if (currentPkgVersion) {
675-
replaceVersionInPackageJson(currentPkgVersion, version);
682+
replaceVersionInPackageJson(options, currentPkgVersion, version);
676683
}
677684
runGit(["add", "package.json"], {
678685
dryRun: options.dryRun,

0 commit comments

Comments
 (0)