-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(helm-values): Support for bumpVersion (#8240)
- Loading branch information
Showing
12 changed files
with
410 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`lib/manager/helm-values/update .bumpPackageVersion() increments 1`] = ` | ||
"apiVersion: v2 | ||
name: test | ||
version: 0.0.3 | ||
" | ||
`; | ||
|
||
exports[`lib/manager/helm-values/update .bumpPackageVersion() updates 1`] = ` | ||
"apiVersion: v2 | ||
name: test | ||
version: 0.1.0 | ||
" | ||
`; |
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,85 @@ | ||
import yaml from 'js-yaml'; | ||
import { fs } from '../../../test/util'; | ||
import * as helmValuesUpdater from './update'; | ||
|
||
describe('lib/manager/helm-values/update', () => { | ||
describe('.bumpPackageVersion()', () => { | ||
const chartContent = yaml.safeDump({ | ||
apiVersion: 'v2', | ||
name: 'test', | ||
version: '0.0.2', | ||
}); | ||
const helmValuesContent = yaml.safeDump({ | ||
image: { | ||
registry: 'docker.io', | ||
repository: 'docker/whalesay', | ||
tag: '1.0.0', | ||
}, | ||
}); | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
fs.readLocalFile = jest.fn(); | ||
fs.readLocalFile.mockResolvedValueOnce(chartContent); | ||
}); | ||
it('increments', async () => { | ||
const { | ||
bumpedContent, | ||
bumpedFiles, | ||
} = await helmValuesUpdater.bumpPackageVersion( | ||
helmValuesContent, | ||
'0.0.2', | ||
'patch', | ||
'values.yaml' | ||
); | ||
expect(bumpedContent).toEqual(helmValuesContent); | ||
expect(bumpedFiles).toHaveLength(1); | ||
const bumpedFile = bumpedFiles[0]; | ||
expect(bumpedFile.fileName).toEqual('Chart.yaml'); | ||
expect(bumpedFile.newContent).toMatchSnapshot(); | ||
}); | ||
it('no ops', async () => { | ||
const { | ||
bumpedContent, | ||
bumpedFiles, | ||
} = await helmValuesUpdater.bumpPackageVersion( | ||
helmValuesContent, | ||
'0.0.1', | ||
'patch', | ||
'values.yaml' | ||
); | ||
expect(bumpedContent).toEqual(helmValuesContent); | ||
expect(bumpedFiles).toHaveLength(1); | ||
const bumpedFile = bumpedFiles[0]; | ||
expect(bumpedFile.newContent).toEqual(chartContent); | ||
}); | ||
it('updates', async () => { | ||
const { | ||
bumpedContent, | ||
bumpedFiles, | ||
} = await helmValuesUpdater.bumpPackageVersion( | ||
helmValuesContent, | ||
'0.0.1', | ||
'minor', | ||
'values.yaml' | ||
); | ||
expect(bumpedContent).toEqual(helmValuesContent); | ||
expect(bumpedFiles).toHaveLength(1); | ||
const bumpedFile = bumpedFiles[0]; | ||
expect(bumpedFile.fileName).toEqual('Chart.yaml'); | ||
expect(bumpedFile.newContent).toMatchSnapshot(); | ||
}); | ||
it('returns content if bumping errors', async () => { | ||
const { | ||
bumpedContent, | ||
bumpedFiles, | ||
} = await helmValuesUpdater.bumpPackageVersion( | ||
helmValuesContent, | ||
'0.0.2', | ||
true as any, | ||
'values.yaml' | ||
); | ||
expect(bumpedContent).toEqual(helmValuesContent); | ||
expect(bumpedFiles).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
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,51 @@ | ||
import { ReleaseType, inc } from 'semver'; | ||
import { logger } from '../../logger'; | ||
import { getSiblingFileName } from '../../util/fs'; | ||
import { BumpPackageVersionResult } from '../common'; | ||
import { getSiblingChartYamlContent } from './util'; | ||
|
||
export async function bumpPackageVersion( | ||
content: string, | ||
currentValue: string, | ||
bumpVersion: ReleaseType | string, | ||
packageFile: string | ||
): Promise<BumpPackageVersionResult> { | ||
logger.debug( | ||
{ bumpVersion, currentValue }, | ||
'Checking if we should bump Chart.yaml version' | ||
); | ||
const chartFileName = getSiblingFileName(packageFile, 'Chart.yaml'); | ||
const chartYamlContent = await getSiblingChartYamlContent(packageFile); | ||
try { | ||
const newChartVersion = inc(currentValue, bumpVersion as ReleaseType); | ||
if (!newChartVersion) { | ||
throw new Error('semver inc failed'); | ||
} | ||
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, | ||
bumpedFiles: [{ fileName: chartFileName, newContent: bumpedContent }], | ||
}; | ||
} catch (err) { | ||
logger.warn( | ||
{ | ||
chartYamlContent, | ||
currentValue, | ||
bumpVersion, | ||
}, | ||
'Failed to bumpVersion' | ||
); | ||
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
Oops, something went wrong.