-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(helmv3): Add support for bumpVersion (#7670)
- Loading branch information
1 parent
8844549
commit ad50398
Showing
14 changed files
with
179 additions
and
19 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,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`lib/manager/helmv3/update .bumpPackageVersion() increments 1`] = ` | ||
"apiVersion: v2 | ||
name: test | ||
version: 0.0.3 | ||
" | ||
`; | ||
|
||
exports[`lib/manager/helmv3/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import yaml from 'js-yaml'; | ||
import * as helmv3Updater from './update'; | ||
|
||
describe('lib/manager/helmv3/update', () => { | ||
describe('.bumpPackageVersion()', () => { | ||
const content = yaml.safeDump({ | ||
apiVersion: 'v2', | ||
name: 'test', | ||
version: '0.0.2', | ||
}); | ||
it('increments', () => { | ||
const res = helmv3Updater.bumpPackageVersion(content, '0.0.2', 'patch'); | ||
expect(res).toMatchSnapshot(); | ||
expect(res).not.toEqual(content); | ||
}); | ||
it('no ops', () => { | ||
const res = helmv3Updater.bumpPackageVersion(content, '0.0.1', 'patch'); | ||
expect(res).toEqual(content); | ||
}); | ||
it('updates', () => { | ||
const res = helmv3Updater.bumpPackageVersion(content, '0.0.1', 'minor'); | ||
expect(res).toMatchSnapshot(); | ||
expect(res).not.toEqual(content); | ||
}); | ||
it('returns content if bumping errors', () => { | ||
const res = helmv3Updater.bumpPackageVersion( | ||
content, | ||
'0.0.2', | ||
true as any | ||
); | ||
expect(res).toEqual(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { ReleaseType, inc } from 'semver'; | ||
import { logger } from '../../logger'; | ||
|
||
export function bumpPackageVersion( | ||
content: string, | ||
currentValue: string, | ||
bumpVersion: ReleaseType | string | ||
): string { | ||
logger.debug( | ||
{ bumpVersion, currentValue }, | ||
'Checking if we should bump Chart.yaml version' | ||
); | ||
let newChartVersion: string; | ||
try { | ||
newChartVersion = inc(currentValue, bumpVersion as ReleaseType); | ||
if (!newChartVersion) { | ||
throw new Error('semver inc failed'); | ||
} | ||
logger.debug({ newChartVersion }); | ||
const bumpedContent = content.replace( | ||
/^(version:\s*).*$/m, | ||
`$1${newChartVersion}` | ||
); | ||
if (bumpedContent === content) { | ||
logger.debug('Version was already bumped'); | ||
} else { | ||
logger.debug('Bumped Chart.yaml version'); | ||
} | ||
return bumpedContent; | ||
} catch (err) { | ||
logger.warn( | ||
{ | ||
content, | ||
currentValue, | ||
bumpVersion, | ||
}, | ||
'Failed to bumpVersion' | ||
); | ||
return 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
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