0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/modules/manager/pep621/update.ts
renovate[bot] eb8c08079e
chore(deps): update typescript-eslint monorepo to v8 (major) (#30750)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2024-08-14 10:33:02 +00:00

49 lines
1.2 KiB
TypeScript

import { inc } from '@renovatebot/pep440';
import type { 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,
): BumpPackageVersionResult {
logger.debug(
{ bumpVersion, currentValue },
'Checking if we should bump pyproject.toml version',
);
let bumpedContent = content;
try {
const newProjectVersion = inc(currentValue, bumpVersion);
if (!newProjectVersion) {
throw new Error('pep440 inc failed');
}
logger.debug(`newProjectVersion: ${newProjectVersion}`);
bumpedContent = content.replace(
regEx(`^(?<version>version[ \\t]*=[ \\t]*['"])[^'"]*`, 'm'),
`$<version>${newProjectVersion}`,
);
if (bumpedContent === content) {
logger.debug('Version was already bumped');
} else {
logger.debug('Bumped pyproject.toml version');
}
} catch {
logger.warn(
{
content,
currentValue,
bumpVersion,
manager: 'pep621',
},
'Failed to bumpVersion',
);
}
return { bumpedContent };
}