mirror of
https://github.com/hashicorp/setup-terraform.git
synced 2025-12-16 08:32:34 +00:00
Allow to specify range specification instead of fixed version (#38)
That allows to install for example the latest bug-fix version of terraform 1.12.* even if 1.13 is already installed. Co-authored-by: Matthew Sanabria <24284972+sudomateo@users.noreply.github.com>
This commit is contained in:
parent
e255dfd077
commit
af8505ef0a
5 changed files with 348 additions and 51 deletions
56
dist/index.js
vendored
56
dist/index.js
vendored
|
|
@ -2068,14 +2068,23 @@ function findLatest (allVersions) {
|
|||
// Find specific version given list of all available
|
||||
function findSpecific (allVersions, version) {
|
||||
core.debug(`Parsing version list for version ${version}`);
|
||||
return allVersions.versions[version];
|
||||
}
|
||||
|
||||
const versionObj = allVersions.versions[version];
|
||||
|
||||
if (!versionObj) {
|
||||
throw new Error(`Could not find Terraform version ${version} in version list`);
|
||||
// Find specific version given list of all available
|
||||
function findLatestMatchingSpecification (allVersions, version) {
|
||||
core.debug(`Parsing version list for latest matching specification ${version}`);
|
||||
const versionList = [];
|
||||
for (const _version in allVersions.versions) {
|
||||
versionList.push(_version);
|
||||
}
|
||||
const bestMatchVersion = semver.maxSatisfying(versionList, version);
|
||||
if (!bestMatchVersion) {
|
||||
throw new Error(`Could not find Terraform version matching ${version} in version list`);
|
||||
}
|
||||
core.info(`Latest version satisfying ${version} is ${bestMatchVersion}`);
|
||||
|
||||
return versionObj;
|
||||
return allVersions.versions[bestMatchVersion];
|
||||
}
|
||||
|
||||
async function downloadMetadata () {
|
||||
|
|
@ -2215,30 +2224,37 @@ async function run () {
|
|||
// Download metadata about all versions of Terraform CLI
|
||||
const versionMetadata = await downloadMetadata();
|
||||
|
||||
const specificMatch = findSpecific(versionMetadata, version);
|
||||
// Find latest or a specific version like 0.1.0
|
||||
const versionObj = version.toLowerCase() === 'latest' ? findLatest(versionMetadata) : findSpecific(versionMetadata, version);
|
||||
const versionObj = version.toLowerCase() === 'latest'
|
||||
? findLatest(versionMetadata) : specificMatch || findLatestMatchingSpecification(versionMetadata, version);
|
||||
|
||||
// Get the build available for this runner's OS and a 64 bit architecture
|
||||
const buildObj = getBuild(versionObj, osPlat, osArch);
|
||||
if (versionObj) {
|
||||
// Get the build available for this runner's OS and a 64 bit architecture
|
||||
const buildObj = getBuild(versionObj, osPlat, osArch);
|
||||
|
||||
// Download requested version
|
||||
const pathToCLI = await downloadCLI(buildObj.url);
|
||||
// Download requested version
|
||||
const pathToCLI = await downloadCLI(buildObj.url);
|
||||
|
||||
// Install our wrapper
|
||||
if (wrapper) {
|
||||
await installWrapper(pathToCLI);
|
||||
}
|
||||
// Install our wrapper
|
||||
if (wrapper) {
|
||||
await installWrapper(pathToCLI);
|
||||
}
|
||||
|
||||
// Add to path
|
||||
core.addPath(pathToCLI);
|
||||
// Add to path
|
||||
core.addPath(pathToCLI);
|
||||
|
||||
// Add credentials to file if they are provided
|
||||
if (credentialsHostname && credentialsToken) {
|
||||
await addCredentials(credentialsHostname, credentialsToken, osPlat);
|
||||
// Add credentials to file if they are provided
|
||||
if (credentialsHostname && credentialsToken) {
|
||||
await addCredentials(credentialsHostname, credentialsToken, osPlat);
|
||||
}
|
||||
return versionObj;
|
||||
} else {
|
||||
core.setFailed(`Could not find Terraform version ${version} in version list`);
|
||||
}
|
||||
} catch (error) {
|
||||
core.error(error);
|
||||
throw new Error(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue