Skip to content

Commit

Permalink
Document pre-release behavior (#73)
Browse files Browse the repository at this point in the history
* Add user agent reporting to terraform download
* Upgrade js-releases dependency
  • Loading branch information
aeschright authored Dec 8, 2020
1 parent 32c4f59 commit 5d2ec20
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ The action supports the following inputs:
- `terraform_version` - (optional) The version of Terraform CLI to install. Instead of a full version string,
you can also specify a constraint string (see [Semver Ranges](https://www.npmjs.com/package/semver#ranges)
for available range specifications). Examples are: `<0.14.0`, `~0.13.0`, `0.13.x` (all three installing
the latest available 0.13 version). Prerelease versions are always ignored. The special value of `latest`
installs the latest version of Terraform CLI. Defaults to `latest`.
the latest available 0.13 version). Prerelease versions can be specified and a range will stay within the
given tag such as `beta` or `rc`. If no version is given, it will default to `latest`.

- `terraform_wrapper` - (optional) Whether to install a wrapper to wrap subsequent calls of
the `terraform` binary and expose its STDOUT, STDERR, and exit code as outputs
Expand Down
19 changes: 11 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,7 @@ async function run () {
const osArch = os.arch();

core.debug(`Finding releases for Terraform version ${version}`);
const release = await releases.getRelease('terraform', version);
const release = await releases.getRelease('terraform', version, 'GitHub Action: Setup Terraform');
const platform = mapOS(osPlatform);
const arch = mapArch(osArch);
core.debug(`Getting build for Terraform version ${release.version}: ${platform} ${arch}`);
Expand Down Expand Up @@ -52497,27 +52497,30 @@ class Release {
}
}
exports.Release = Release;
function getRelease(product, version, userAgent) {
function getRelease(product, version, userAgent, includePrerelease) {
return __awaiter(this, void 0, void 0, function* () {
const validVersion = semver.validRange(version); // "latest" will return invalid but that's ok because we'll select it by default
const validVersion = semver.validRange(version, { includePrerelease, loose: true }); // "latest" will return invalid but that's ok because we'll select it by default
const indexUrl = `${releasesUrl}/${product}/index.json`;
const headers = userAgent ? { 'User-Agent': userAgent } : null;
const body = yield utils_1.httpsRequest(indexUrl, { headers });
const response = JSON.parse(body);
let release;
if (!validVersion) { // pick the latest release
version = Object.keys(response.versions).sort(semver.rcompare)[0];
if (!validVersion) { // pick the latest release (prereleases will be skipped for safety, set an explicit version instead)
const releaseVersions = Object.keys(response.versions).filter(v => !semver.prerelease(v));
version = releaseVersions.sort((a, b) => semver.rcompare(a, b))[0];
release = new Release(response.versions[version]);
}
else {
release = matchVersion(response.versions, validVersion);
release = matchVersion(response.versions, validVersion, includePrerelease);
}
return release;
});
}
exports.getRelease = getRelease;
function matchVersion(versions, range) {
const version = semver.maxSatisfying(Object.keys(versions), range);
function matchVersion(versions, range, includePrerelease) {
// If a prerelease version range is given, it will match in that series (0.14-rc0, 0.14-rc1)
// https://www.npmjs.com/package/semver#prerelease-tags
const version = semver.maxSatisfying(Object.keys(versions), range, { includePrerelease });
if (version) {
return new Release(versions[version]);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/setup-terraform.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async function run () {
const osArch = os.arch();

core.debug(`Finding releases for Terraform version ${version}`);
const release = await releases.getRelease('terraform', version);
const release = await releases.getRelease('terraform', version, 'GitHub Action: Setup Terraform');
const platform = mapOS(osPlatform);
const arch = mapArch(osArch);
core.debug(`Getting build for Terraform version ${release.version}: ${platform} ${arch}`);
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@actions/github": "^4.0.0",
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.6.1",
"@hashicorp/js-releases": "^1.1.0"
"@hashicorp/js-releases": "^1.2.0"
},
"devDependencies": {
"@zeit/ncc": "0.22.1",
Expand Down

0 comments on commit 5d2ec20

Please sign in to comment.