fix: better validation before bumping package version (#23684)

This commit is contained in:
Michael Kriese 2023-08-08 11:50:42 +02:00 committed by GitHub
parent 2f99b3cf25
commit 29cec2cb91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 17 deletions

View file

@ -14,6 +14,7 @@ export function bumpPackageVersion(
);
let newChartVersion: string | null;
let bumpedContent = content;
try {
newChartVersion = semver.inc(currentValue, bumpVersion);
if (!newChartVersion) {

View file

@ -55,7 +55,7 @@ export function updateDependency({
export function bumpPackageVersion(
content: string,
currentValue: string | undefined,
currentValue: string,
bumpVersion: ReleaseType
): BumpPackageVersionResult {
logger.debug(
@ -64,11 +64,6 @@ export function bumpPackageVersion(
);
let bumpedContent = content;
if (!currentValue) {
logger.warn('Unable to bump pom.xml version, pom.xml has no version');
return { bumpedContent };
}
if (!semver.valid(currentValue)) {
logger.warn(
{ currentValue },

View file

@ -23,6 +23,7 @@ export function bumpPackageVersion(
// TODO: types (#7154)
let newPjVersion: string | null;
let bumpedContent = content;
try {
if (isMirrorBumpVersion(bumpVersion)) {
const mirrorPackage = bumpVersion.replace('mirror:', '');

View file

@ -7,7 +7,7 @@ import { findVersion } from './util';
export function bumpPackageVersion(
content: string,
currentValue: string | undefined,
currentValue: string,
bumpVersion: ReleaseType
): BumpPackageVersionResult {
logger.debug(
@ -16,11 +16,6 @@ export function bumpPackageVersion(
);
let bumpedContent = content;
if (!currentValue) {
logger.warn('Unable to bump project version, project has no version');
return { bumpedContent };
}
if (!semver.valid(currentValue)) {
logger.warn(
{ currentValue },

View file

@ -476,6 +476,7 @@ describe('workers/repository/update/branch/get-updated', () => {
branchName: '',
bumpVersion: 'patch',
manager: 'npm',
packageFileVersion: 'old version',
});
npm.updateDependency.mockReturnValue('old version');
npm.bumpPackageVersion.mockReturnValue({ bumpedContent: 'new version' });
@ -497,6 +498,7 @@ describe('workers/repository/update/branch/get-updated', () => {
branchName: '',
bumpVersion: 'patch',
manager: 'helmv3',
packageFileVersion: '0.0.1',
});
autoReplace.doAutoReplace.mockResolvedValueOnce('version: 0.0.1');
helmv3.bumpPackageVersion.mockReturnValue({

View file

@ -173,10 +173,14 @@ export async function getUpdatedPackageFiles(
);
firstUpdate = false;
if (res) {
if (bumpPackageVersion && upgrade.bumpVersion) {
if (
bumpPackageVersion &&
upgrade.bumpVersion &&
upgrade.packageFileVersion
) {
const { bumpedContent } = await bumpPackageVersion(
res,
upgrade.packageFileVersion!,
upgrade.packageFileVersion,
upgrade.bumpVersion
);
res = bumpedContent;
@ -202,10 +206,15 @@ export async function getUpdatedPackageFiles(
fileContent: packageFileContent!,
upgrade,
});
if (bumpPackageVersion && upgrade.bumpVersion) {
if (
newContent &&
bumpPackageVersion &&
upgrade.bumpVersion &&
upgrade.packageFileVersion
) {
const { bumpedContent } = await bumpPackageVersion(
newContent!,
upgrade.packageFileVersion!,
newContent,
upgrade.packageFileVersion,
upgrade.bumpVersion
);
newContent = bumpedContent;