diff --git a/README.md b/README.md index 7fe8953..1629ad0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ The `scalr-action` action is an action written in JavaScript that sets up the Scalr and Terraform CLI. The action does the following: -- Downloads (and caching) the latest version of [Scalr CLI](https://github.com/Scalr/scalr-cli) and adds it to the `PATH`. +- Downloads (and caching) a specific (or latest) version of [Scalr CLI](https://github.com/Scalr/scalr-cli) and adds it to the `PATH`. - Dowloads (and caching) a specific (or autodetected) version of Terraform CLI and adds it to the `PATH`. - Configures the Scalr CLI and [Terraform CLI configuration file](https://www.terraform.io/docs/commands/cli-config.html) with a Scalr Hostname and Token. - Optionally: Installs a script to wrap following calls of the `terraform` binary. Exposes the STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode`. Enabled by default @@ -76,6 +76,8 @@ The action supports the following inputs: - `scalr_workspace` - The Scalr workspace ID you plan on working in. This is required if you want to auto-detect Terraform version. +- `scalr_cli_version` - The version of Scalr CLI. The latest version will be used if this is not specified. + - `terraform_version` - The version of Terraform CLI. This must match the version set in your Scalr Workspace. It will be autodetected if left empty and workspace is set. - `terraform_wrapper` - Whether or not to install a wrapper to wrap calls of the `terraform` binary and expose its STDOUT, STDERR, and exit code diff --git a/action.yml b/action.yml index 97338a9..45d3123 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,9 @@ inputs: scalr_workspace: description: 'The Scalr workspace ID you plan on working in. This is required if you want to autodetect Terraform version.' required: false + scalr_cli_version: + description: 'The Scalr CLI version to install. Defaults to the latest.' + required: false terraform_version: description: 'The version of Terraform CLI to install. Should match the version set in your Scalr Workspace. Will be autodetected if left empty and workspace is set.' required: false diff --git a/src/terraform.js b/src/terraform.js index cab279b..4023d42 100644 --- a/src/terraform.js +++ b/src/terraform.js @@ -17,6 +17,7 @@ const { stdout } = require('process'); const hostname = core.getInput('scalr_hostname', { required: true }) const token = core.getInput('scalr_token', { required: true }) const workspace = core.getInput('scalr_workspace') + let cli_version = core.getInput('scalr_cli_version') let version = core.getInput('terraform_version') const wrapper = core.getInput('terraform_wrapper') === 'true'; const output = core.getInput('terraform_output') @@ -24,10 +25,13 @@ const { stdout } = require('process'); const platform = {'win32':'windows'}[os.platform()] || os.platform() const arch = {'x32':'386', 'x64':'amd64'}[os.arch()] || os.arch() - core.info('Fetch latest version of Scalr CLI') - let latest = await axios.head('https://github.com/scalr/scalr-cli/releases/latest') - let ver = new URL(latest.request.res.responseUrl).pathname.split('/').pop().replace('v', ''); - let url = `https://github.com/Scalr/scalr-cli/releases/download/v${ver}/scalr-cli_${ver}_${platform}_${arch}.zip` + if (!cli_version) { + core.info('Fetch latest version of Scalr CLI') + let latest = await axios.head('https://github.com/scalr/scalr-cli/releases/latest') + cli_version = new URL(latest.request.res.responseUrl).pathname.split('/').pop(); + } + cli_version = cli_version.replace('v', ''); + let url = `https://github.com/Scalr/scalr-cli/releases/download/v${cli_version}/scalr-cli_${cli_version}_${platform}_${arch}.zip` core.info(`Downloading compressed Scalr CLI binary from ${url}`) const zip2 = await toolcache.downloadTool(url) @@ -103,4 +107,4 @@ const { stdout } = require('process'); } catch(error) { core.setFailed(error.message) -} })(); \ No newline at end of file +} })();