2021-12-22 08:37:47 +00:00
|
|
|
import semver, { ReleaseType } from 'semver';
|
2022-03-03 09:35:26 +00:00
|
|
|
import { logger } from '../../../logger';
|
|
|
|
import { regEx } from '../../../util/regex';
|
2021-03-02 20:44:55 +00:00
|
|
|
import type { BumpPackageVersionResult } from '../types';
|
2021-01-17 07:48:00 +00:00
|
|
|
|
|
|
|
export function bumpPackageVersion(
|
|
|
|
content: string,
|
|
|
|
currentValue: string,
|
|
|
|
bumpVersion: ReleaseType | string
|
|
|
|
): BumpPackageVersionResult {
|
|
|
|
logger.debug(
|
|
|
|
{ bumpVersion, currentValue },
|
|
|
|
'Checking if we should bump build.sbt version'
|
|
|
|
);
|
|
|
|
let bumpedContent = content;
|
2021-12-22 08:37:47 +00:00
|
|
|
const bumpedVersion = semver.inc(currentValue, bumpVersion as ReleaseType);
|
2021-02-16 10:26:46 +00:00
|
|
|
if (!bumpedVersion) {
|
2021-01-17 07:48:00 +00:00
|
|
|
logger.warn('Version incremental failed');
|
|
|
|
return { bumpedContent };
|
|
|
|
}
|
|
|
|
bumpedContent = content.replace(
|
2021-10-20 04:38:49 +00:00
|
|
|
regEx(/^(version\s*:=\s*).*$/m),
|
2021-02-16 10:26:46 +00:00
|
|
|
`$1"${bumpedVersion}"`
|
2021-01-17 07:48:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if (bumpedContent === content) {
|
|
|
|
logger.debug('Version was already bumped');
|
|
|
|
} else {
|
2022-11-07 11:29:02 +00:00
|
|
|
logger.debug(`Bumped build.sbt version to ${bumpedVersion}`);
|
2021-01-17 07:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return { bumpedContent };
|
|
|
|
}
|