-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Terraform): renovate required terraform version (#8791)
- Loading branch information
Showing
5 changed files
with
78 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as datasourceGithubTags from '../../datasource/github-tags'; | ||
import { logger } from '../../logger'; | ||
import { PackageDependency } from '../common'; | ||
import { | ||
ExtractionResult, | ||
TerraformDependencyTypes, | ||
keyValueExtractionRegex, | ||
} from './util'; | ||
|
||
export function extractTerraformRequiredVersion( | ||
startingLine: number, | ||
lines: string[] | ||
): ExtractionResult { | ||
const deps: PackageDependency[] = []; | ||
let lineNumber = startingLine; | ||
let braceCounter = 0; | ||
do { | ||
// istanbul ignore if | ||
if (lineNumber > lines.length - 1) { | ||
logger.debug(`Malformed Terraform file detected.`); | ||
} | ||
|
||
const line = lines[lineNumber]; | ||
// `{` will be counted wit +1 and `}` with -1. Therefore if we reach braceCounter == 0. We have found the end of the terraform block | ||
const openBrackets = (line.match(/\{/g) || []).length; | ||
const closedBrackets = (line.match(/\}/g) || []).length; | ||
braceCounter = braceCounter + openBrackets - closedBrackets; | ||
|
||
const kvMatch = keyValueExtractionRegex.exec(line); | ||
if (kvMatch && kvMatch.groups.key === 'required_version') { | ||
const dep: PackageDependency = { | ||
currentValue: kvMatch.groups.value, | ||
lineNumber, | ||
managerData: { | ||
terraformDependencyType: TerraformDependencyTypes.terraform_version, | ||
}, | ||
}; | ||
deps.push(dep); | ||
// returning starting line as required_providers are also in the terraform block | ||
// if we would return the position of the required_version line we would potentially skip the providers | ||
return { lineNumber: startingLine, dependencies: deps }; | ||
} | ||
|
||
lineNumber += 1; | ||
} while (braceCounter !== 0); | ||
return null; | ||
} | ||
|
||
export function analyseTerraformVersion(dep: PackageDependency): void { | ||
/* eslint-disable no-param-reassign */ | ||
dep.datasource = datasourceGithubTags.id; | ||
dep.depName = 'hashicorp/terraform'; | ||
dep.extractVersion = 'v(?<version>.*)$'; | ||
/* eslint-enable no-param-reassign */ | ||
} |
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