-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* DO NOT REMOVE ME UNLESS YOU KNOW WHAT YOU'RE DOING!! | ||
*/ | ||
|
||
const {execSync} = require("child_process") | ||
const fs = require("fs") | ||
|
||
// Fetch the latest changes from the main branch | ||
execSync("git fetch origin master") | ||
|
||
const packageJsons = execSync("git ls-files 'packages/*/package.json'") | ||
.toString() | ||
.split("\n") | ||
.filter(Boolean) | ||
|
||
// Assert that the package.json files exist | ||
if (packageJsons.length === 0) { | ||
console.error("Error: No package.json files found.") | ||
process.exit(1) // Fail the CI | ||
} | ||
|
||
for (const packageJson of packageJsons) { | ||
// Get the current version from package.json | ||
const newPackageJson = JSON.parse(fs.readFileSync(packageJson, "utf8")) | ||
const newPackageName = newPackageJson.name | ||
const newVersion = newPackageJson.version | ||
|
||
// Get the version from the main branch (or latest release) | ||
const prevPackageJson = JSON.parse( | ||
execSync(`git show origin/master:${packageJson}`).toString() | ||
) | ||
const prevPackageName = prevPackageJson.name | ||
const prevVersion = prevPackageJson.version | ||
|
||
// Assert that the package names match | ||
if (newPackageName !== prevPackageName) { | ||
console.error( | ||
`Error: Package name mismatch for ${newPackageName} (${prevPackageName} -> ${newPackageName}).` | ||
) | ||
process.exit(1) // Fail the CI | ||
} | ||
|
||
// Extract major, minor, and patch numbers | ||
const newMajor = parseInt(newVersion.split(".")[0]) | ||
const prevMajor = parseInt(prevVersion.split(".")[0]) | ||
|
||
// Check if it's a major version bump | ||
if (newMajor > prevMajor) { | ||
console.error( | ||
`Error: Major version bump detected for ${newPackageName} (${prevVersion} -> ${newVersion}).` | ||
) | ||
process.exit(1) // Fail the CI | ||
} | ||
|
||
console.log( | ||
`Version bump allowed for ${newPackageName}: ${prevVersion} -> ${newVersion}` | ||
) | ||
} | ||
|
||
process.exit(0) // Allow the CI to pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters