forked from renovatebot/renovate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(manager/helm-values): Add support for bumpVersion (renovatebot#2…
…6441) Signed-off-by: kvanzuijlen <[email protected]>
- Loading branch information
1 parent
4705e13
commit 24cd593
Showing
8 changed files
with
257 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { z } from 'zod'; | ||
import { Yaml } from '../../../util/schema-utils'; | ||
|
||
export const ChartDefinition = z | ||
.object({ | ||
apiVersion: z.string().regex(/v([12])/), | ||
name: z.string().min(1), | ||
version: z.string().min(1), | ||
}) | ||
.partial(); | ||
export type ChartDefinition = z.infer<typeof ChartDefinition>; | ||
|
||
export const ChartDefinitionYaml = Yaml.pipe(ChartDefinition); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import yaml from 'js-yaml'; | ||
import { fs } from '../../../../test/util'; | ||
import * as helmValuesUpdater from './update'; | ||
|
||
jest.mock('../../../util/fs'); | ||
|
||
describe('modules/manager/helm-values/update', () => { | ||
describe('.bumpPackageVersion()', () => { | ||
const chartContent = yaml.dump({ | ||
apiVersion: 'v2', | ||
name: 'test', | ||
version: '0.0.2', | ||
}); | ||
const helmValuesContent = yaml.dump({ | ||
image: { | ||
registry: 'docker.io', | ||
repository: 'docker/whalesay', | ||
tag: '1.0.0', | ||
}, | ||
}); | ||
|
||
beforeEach(() => { | ||
fs.readLocalFile.mockResolvedValueOnce(chartContent); | ||
}); | ||
|
||
it('increments', async () => { | ||
const { bumpedContent } = await helmValuesUpdater.bumpPackageVersion( | ||
helmValuesContent, | ||
'0.0.2', | ||
'patch', | ||
'test/values.yaml', | ||
); | ||
expect(bumpedContent).toEqual(helmValuesContent); | ||
}); | ||
|
||
it('no ops', async () => { | ||
const { bumpedContent } = await helmValuesUpdater.bumpPackageVersion( | ||
helmValuesContent, | ||
'0.0.1', | ||
'patch', | ||
'values.yaml', | ||
); | ||
expect(bumpedContent).toEqual(helmValuesContent); | ||
}); | ||
|
||
it('updates', async () => { | ||
const { bumpedContent } = await helmValuesUpdater.bumpPackageVersion( | ||
helmValuesContent, | ||
'0.0.1', | ||
'minor', | ||
'test/values.yaml', | ||
); | ||
expect(bumpedContent).toEqual(helmValuesContent); | ||
}); | ||
|
||
it('returns content if bumping errors', async () => { | ||
const { bumpedContent } = await helmValuesUpdater.bumpPackageVersion( | ||
helmValuesContent, | ||
'0.0.2', | ||
true as any, | ||
'values.yaml', | ||
); | ||
expect(bumpedContent).toEqual(helmValuesContent); | ||
}); | ||
|
||
it('returns content if retrieving Chart.yaml fails', async () => { | ||
fs.readLocalFile.mockReset(); | ||
fs.readLocalFile.mockRejectedValueOnce(null); | ||
const { bumpedContent } = await helmValuesUpdater.bumpPackageVersion( | ||
helmValuesContent, | ||
'0.0.2', | ||
'minor', | ||
'values.yaml', | ||
); | ||
expect(bumpedContent).toEqual(helmValuesContent); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ReleaseType, inc } from 'semver'; | ||
import { logger } from '../../../logger'; | ||
import type { BumpPackageVersionResult } from '../types'; | ||
import { getSiblingChartYamlContent } from './util'; | ||
|
||
export async function bumpPackageVersion( | ||
content: string, | ||
currentValue: string, | ||
bumpVersion: ReleaseType, | ||
packageFile: string, | ||
): Promise<BumpPackageVersionResult> { | ||
logger.debug( | ||
{ bumpVersion, currentValue }, | ||
'Checking if we should bump Chart.yaml version', | ||
); | ||
const chartYamlContent = await getSiblingChartYamlContent(packageFile); | ||
const newChartVersion = inc(currentValue, bumpVersion); | ||
if (!newChartVersion || chartYamlContent === null) { | ||
logger.warn( | ||
{ | ||
chartYamlContent, | ||
currentValue, | ||
bumpVersion, | ||
}, | ||
'Failed to bumpVersion', | ||
); | ||
return { | ||
bumpedContent: content, | ||
}; | ||
} | ||
logger.debug({ newChartVersion }); | ||
const bumpedContent = chartYamlContent?.replace( | ||
/^(version:\s*).*$/m, | ||
`$1${newChartVersion}`, | ||
); | ||
if (bumpedContent === chartYamlContent) { | ||
logger.debug('Version was already bumped'); | ||
} else { | ||
logger.debug('Bumped Chart.yaml version'); | ||
} | ||
return { | ||
bumpedContent: content, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters