Skip to content

feat: rc on bump version script #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ _touch_pot:
fi
touch $@

# Usage: make bump updateType=patch
# Usage:
# make bump updateType=patch
# make bump updateType=patch bumpRc=true
.PHONY: bump
bump:
node scripts/bump-version.js $(updateType)
node scripts/bump-version.js $(updateType) $(if $(bumpRc),--bumpRc)
26 changes: 17 additions & 9 deletions scripts/bump-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ function updateAndroidBuildVersion() {
/**
* @typedef {'major'|'minor'|'patch'|'rc'|'release'} UpdateType
*/

/**
* Calculates the next version number based on the current version and the update type
* @param {UpdateType} _updateType
* @param {string} currentVersionString
* @param [options]
* @param {boolean} [options.addRc=false] Whether to also add an rc version to the other increment
* @returns {{rcVersion: number, updatedVersionString: string, mainVersionString: string}}
*/
function calculateNewVersion(_updateType, currentVersionString) {
function calculateNewVersion(_updateType, currentVersionString, { addRc = false } = {}) {
const versionNameRegex = /(\d+)\.(\d+)\.(\d+)(-rc\.)?(\d+)?/;
const versionNameMatch = currentVersionString.match(versionNameRegex);
let major = parseInt(versionNameMatch[1], 10);
Expand All @@ -48,16 +49,16 @@ function calculateNewVersion(_updateType, currentVersionString) {
major += 1;
minor = 0;
patch = 0;
rc = null;
rc = addRc ? 1 : null;
break;
case 'minor':
minor += 1;
patch = 0;
rc = null;
rc = addRc ? 1 : null;
break;
case 'patch':
patch += 1;
rc = null;
rc = addRc ? 1 : null;
break;
case 'rc':
if (rc) {
Expand Down Expand Up @@ -87,17 +88,22 @@ function calculateNewVersion(_updateType, currentVersionString) {
* Updates the version number on package.json and returns an object containing the updated values
* to be used on other file updates
* @param {UpdateType} _updateType
* @param {boolean} [forceRcBump=false] Whether to force the rc version to be bumped
* @returns {{rcVersion: number, updatedVersionString: string, mainVersionString: string}}
*/
function updatePackageJson(_updateType) {
function updatePackageJson(_updateType, forceRcBump) {
const packageJsonPath = path.join(__dirname, '..', 'package.json');
const packageJsonFile = fs.readFileSync(packageJsonPath, 'utf8');

// Look for the line containing "version"
const versionNameRegex = /"version": "(.+)"/;
const versionNameMatch = packageJsonFile.match(versionNameRegex);
const currentVersionString = versionNameMatch[1];
const updatedVersionObj = calculateNewVersion(_updateType, currentVersionString);
const updatedVersionObj = calculateNewVersion(
_updateType,
currentVersionString,
{ addRc: forceRcBump }
);

// Replace the version code on the file contents
const updatedPackageJsonFile = packageJsonFile.replace(versionNameRegex, `"version": "${updatedVersionObj.updatedVersionString}"`);
Expand Down Expand Up @@ -202,16 +208,18 @@ const updateType = process.argv[2];
// and exit processing with an error
if (!['major', 'minor', 'patch', 'rc', 'release'].includes(updateType)) {
console.error(`Invalid update type: ${updateType}`);
console.log('Usage: node scripts/bump-version.js <updateType>');
console.log('Usage: node scripts/bump-version.js <updateType> [--bumpRc]');
console.log('Where <updateType> can be "major", "minor", "patch", "rc" or "release"');
process.exit(1);
}

const forceRcBump = process.argv[3]?.toLowerCase() === '--bumprc';

const {
updatedVersionString,
mainVersionString,
rcVersion
} = updatePackageJson(updateType);
} = updatePackageJson(updateType, forceRcBump);
updatePackageLockJson(updatedVersionString);
updateAndroidBuildVersion();
updateVersionAndroid(updatedVersionString);
Expand Down