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 newChartVersion: string | null;
let bumpedContent = content; let bumpedContent = content;
try { try {
newChartVersion = semver.inc(currentValue, bumpVersion); newChartVersion = semver.inc(currentValue, bumpVersion);
if (!newChartVersion) { if (!newChartVersion) {

View file

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

View file

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

View file

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

View file

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

View file

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