Skip to content

Commit

Permalink
fix(terraform): handle greater than with full version (#9632)
Browse files Browse the repository at this point in the history
  • Loading branch information
secustor committed Apr 19, 2021
1 parent 8b8d776 commit df2f451
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
24 changes: 24 additions & 0 deletions lib/versioning/hashicorp/index.spec.ts
Expand Up @@ -67,6 +67,30 @@ describe('semver.getNewValue()', () => {
newVersion: '2.0.7',
})
).toEqual('~> 2.0.0');
expect(
semver.getNewValue({
currentValue: '~> 0.14.0',
rangeStrategy: 'replace',
currentVersion: '0.14.1',
newVersion: '0.15.0',
})
).toEqual('~> 0.15.0');
expect(
semver.getNewValue({
currentValue: '~> 0.14.0',
rangeStrategy: 'replace',
currentVersion: '0.14.1',
newVersion: '0.15.1',
})
).toEqual('~> 0.15.0');
expect(
semver.getNewValue({
currentValue: '~> 0.14.6',
rangeStrategy: 'replace',
currentVersion: '0.14.6',
newVersion: '0.15.0',
})
).toEqual('~> 0.15.0');
});
it('handles comma dividers', () => {
expect(
Expand Down
12 changes: 8 additions & 4 deletions lib/versioning/hashicorp/index.ts
Expand Up @@ -36,10 +36,14 @@ function getNewValue({
newVersion,
}: NewValueConfig): string {
if (/~>\s*0\.\d+/.test(currentValue) && npm.getMajor(newVersion) === 0) {
return currentValue.replace(
/(~>\s*0\.).*$/,
`$1${npm.getMinor(newVersion)}`
);
const testFullVersion = /(~>\s*0\.)(\d+)\.\d$/;
let replaceValue = '';
if (testFullVersion.test(currentValue)) {
replaceValue = `$1${npm.getMinor(newVersion)}.0`;
} else {
replaceValue = `$1${npm.getMinor(newVersion)}$3`;
}
return currentValue.replace(/(~>\s*0\.)(\d+)(.*)$/, replaceValue);
}
// handle special ~> 1.2 case
if (/(~>\s*)\d+\.\d+$/.test(currentValue)) {
Expand Down

0 comments on commit df2f451

Please sign in to comment.