mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-15 00:56:26 +00:00
dca3418bbd
Moves datasource, manager, platform and versioning code from lib/ into new lib/modules/ BREAKING CHANGE: External tools must update paths to datasource, manager, platform and versioning
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import semver, { ReleaseType } from 'semver';
|
|
import { logger } from '../../../logger';
|
|
import { regEx } from '../../../util/regex';
|
|
import type { BumpPackageVersionResult } from '../types';
|
|
|
|
export function bumpPackageVersion(
|
|
content: string,
|
|
currentValue: string,
|
|
bumpVersion: ReleaseType | string
|
|
): BumpPackageVersionResult {
|
|
logger.debug(
|
|
{ bumpVersion, currentValue },
|
|
'Checking if we should bump Chart.yaml version'
|
|
);
|
|
let newChartVersion: string;
|
|
let bumpedContent = content;
|
|
try {
|
|
newChartVersion = semver.inc(currentValue, bumpVersion as ReleaseType);
|
|
if (!newChartVersion) {
|
|
throw new Error('semver inc failed');
|
|
}
|
|
logger.debug({ newChartVersion });
|
|
bumpedContent = content.replace(
|
|
regEx(`^(?<version>version:\\s*).*$`, 'm'),
|
|
`$<version>${newChartVersion}`
|
|
);
|
|
if (bumpedContent === content) {
|
|
logger.debug('Version was already bumped');
|
|
} else {
|
|
logger.debug('Bumped Chart.yaml version');
|
|
}
|
|
} catch (err) {
|
|
logger.warn(
|
|
{
|
|
content,
|
|
currentValue,
|
|
bumpVersion,
|
|
},
|
|
'Failed to bumpVersion'
|
|
);
|
|
}
|
|
return { bumpedContent };
|
|
}
|