mirror of
https://github.com/opentofu/setup-opentofu.git
synced 2026-11-26 18:30:54 +01:00
Update Node.js runtime to 24 (#91)
Signed-off-by: Dawid Jóźwiak <5508474+Operativ@users.noreply.github.com> Signed-off-by: James Humphries <james@james-humphries.co.uk> Signed-off-by: Diogenes Fernandes <diofeher@gmail.com> Co-authored-by: Dawid Jóźwiak <5508474+Operativ@users.noreply.github.com> Co-authored-by: Diogenes Fernandes <diofeher@gmail.com>
This commit is contained in:
19 files changed
+44738
-43700
No files matched your search
@@ -11,9 +11,9 @@ jobs:
|
|||||||
name: Check dist/ directory
|
name: Check dist/ directory
|
||||||
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@2826fb8353263a138210fc017301ce5767a9c0d4
|
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@2826fb8353263a138210fc017301ce5767a9c0d4
|
||||||
with:
|
with:
|
||||||
node-version: "20.19.1"
|
node-version: "24.14.0"
|
||||||
test:
|
test:
|
||||||
name: Test
|
name: Test
|
||||||
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@2826fb8353263a138210fc017301ce5767a9c0d4
|
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@2826fb8353263a138210fc017301ce5767a9c0d4
|
||||||
with:
|
with:
|
||||||
node-version: "20.19.1"
|
node-version: "24.14.0"
|
||||||
@@ -13,7 +13,7 @@ jobs:
|
|||||||
tag:
|
tag:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
- run: |
|
- run: |
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
git tag --force "$(grep '^v[1-2]\.[0-9]\+\.[0-9]\+\(.*\)\?$' <<< ${GITHUB_REF#refs/*/} | sed 's/^v\([1-2]\)\..*/v\1/')"
|
git tag --force "$(grep '^v[1-2]\.[0-9]\+\.[0-9]\+\(.*\)\?$' <<< ${GITHUB_REF#refs/*/} | sed 's/^v\([1-2]\)\..*/v\1/')"
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ jobs:
|
|||||||
tofu-version-files: ['./.github/workflows/data/local/.opentofu-version']
|
tofu-version-files: ['./.github/workflows/data/local/.opentofu-version']
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Setup OpenTofu - ${{ matrix['tofu-version-files'] }}
|
- name: Setup OpenTofu - ${{ matrix['tofu-version-files'] }}
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -43,7 +43,7 @@ jobs:
|
|||||||
tofu-wrapper: [true, false]
|
tofu-wrapper: [true, false]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Setup OpenTofu - ${{ matrix['tofu-versions'] }}
|
- name: Setup OpenTofu - ${{ matrix['tofu-versions'] }}
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -66,7 +66,7 @@ jobs:
|
|||||||
tofu-wrapper: [true, false]
|
tofu-wrapper: [true, false]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Setup OpenTofu
|
- name: Setup OpenTofu
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -103,7 +103,7 @@ jobs:
|
|||||||
working-directory: ./.github/workflows/data/local
|
working-directory: ./.github/workflows/data/local
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Setup OpenTofu
|
- name: Setup OpenTofu
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -133,7 +133,7 @@ jobs:
|
|||||||
TF_CLOUD_API_TOKEN: 'XXXXXXXXXXXXXX.atlasv1.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
TF_CLOUD_API_TOKEN: 'XXXXXXXXXXXXXX.atlasv1.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Setup OpenTofu
|
- name: Setup OpenTofu
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -162,7 +162,7 @@ jobs:
|
|||||||
TF_CLOUD_API_TOKEN: 'XXXXXXXXXXXXXX.atlasv1.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
TF_CLOUD_API_TOKEN: 'XXXXXXXXXXXXXX.atlasv1.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Setup OpenTofu
|
- name: Setup OpenTofu
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -190,7 +190,7 @@ jobs:
|
|||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Setup OpenTofu
|
- name: Setup OpenTofu
|
||||||
uses: ./
|
uses: ./
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
#!/bin/sh
|
|
||||||
. "$(dirname "$0")/_/husky.sh"
|
|
||||||
|
|
||||||
npm run lint || (npm install && npm run lint)
|
npm run lint || (npm install && npm run lint)
|
||||||
npm run test
|
npm run test
|
||||||
npm audit --audit-level=high
|
npm audit --audit-level=high
|
||||||
|
|||||||
+1
-1
@@ -43,5 +43,5 @@ branding:
|
|||||||
icon: 'box'
|
icon: 'box'
|
||||||
color: 'yellow'
|
color: 'yellow'
|
||||||
runs:
|
runs:
|
||||||
using: 'node20'
|
using: 'node24'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
Vendored
+19154
-21052
File diff suppressed because it is too large.
Load diff
Vendored
+18043
-15087
File diff suppressed because it is too large.
Load diff
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"type": "module"
|
||||||
|
}
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) HashiCorp, Inc.
|
* Copyright (c) HashiCorp, Inc.
|
||||||
|
* Copyright (c) OpenTofu
|
||||||
* SPDX-License-Identifier: MPL-2.0
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const core = require('@actions/core');
|
import { setFailed } from '@actions/core';
|
||||||
|
|
||||||
const setup = require('./lib/setup-tofu');
|
import setup from './lib/setup-tofu.js';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
await setup();
|
await setup();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
setFailed(error.message);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
+43
-26
@@ -1,24 +1,30 @@
|
|||||||
/**
|
/**
|
||||||
|
* Copyright (c) HashiCorp, Inc.
|
||||||
* Copyright (c) OpenTofu
|
* Copyright (c) OpenTofu
|
||||||
* SPDX-License-Identifier: MPL-2.0
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { HttpClient, HttpCodes } from '@actions/http-client';
|
||||||
|
import semver from 'semver';
|
||||||
|
|
||||||
class Build {
|
class Build {
|
||||||
constructor (version, name) {
|
constructor (version, name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.url = 'https://github.com/opentofu/opentofu/releases/download/v' + version + '/' + name;
|
this.url = `https://github.com/opentofu/opentofu/releases/download/v${version}/${name}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Release {
|
class Release {
|
||||||
constructor (releaseMeta) {
|
constructor (releaseMeta) {
|
||||||
this.version = releaseMeta.id.replace('v', '');
|
this.version = releaseMeta.id.replace('v', '');
|
||||||
this.builds = releaseMeta.files.map(asset => new Build(this.version, asset));
|
this.builds = releaseMeta.files.map(
|
||||||
|
(asset) => new Build(this.version, asset)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getBuild (platform, arch) {
|
getBuild (platform, arch) {
|
||||||
const requiredName = `tofu_${this.version}_${platform}_${arch}.zip`;
|
const requiredName = `tofu_${this.version}_${platform}_${arch}.zip`;
|
||||||
return this.builds.find(build => build.name === requiredName);
|
return this.builds.find((build) => build.name === requiredName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,10 +34,9 @@ class Release {
|
|||||||
* @return {Array<Release>} Releases.
|
* @return {Array<Release>} Releases.
|
||||||
*/
|
*/
|
||||||
async function fetchReleases (githubToken) {
|
async function fetchReleases (githubToken) {
|
||||||
const hc = require('@actions/http-client');
|
|
||||||
const userAgent = 'opentofu/setup-opentofu';
|
const userAgent = 'opentofu/setup-opentofu';
|
||||||
|
|
||||||
const http = new hc.HttpClient(userAgent);
|
const http = new HttpClient(userAgent);
|
||||||
|
|
||||||
const url = 'https://get.opentofu.org/tofu/api.json';
|
const url = 'https://get.opentofu.org/tofu/api.json';
|
||||||
|
|
||||||
@@ -41,29 +46,34 @@ async function fetchReleases (githubToken) {
|
|||||||
|
|
||||||
const resp = await http.get(url, headers);
|
const resp = await http.get(url, headers);
|
||||||
|
|
||||||
if (resp.message.statusCode !== hc.HttpCodes.OK) {
|
if (resp.message.statusCode !== HttpCodes.OK) {
|
||||||
throw new Error('failed fetching releases (' + resp.message.statusCode + ')');
|
throw new Error(
|
||||||
|
'failed fetching releases (' + resp.message.statusCode + ')'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = await resp.readBody();
|
const body = await resp.readBody();
|
||||||
const releasesMeta = JSON.parse(body);
|
const releasesMeta = JSON.parse(body);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
const versions = releasesMeta.versions;
|
const versions = releasesMeta.versions;
|
||||||
|
|
||||||
return versions.map(releaseMeta => new Release(releaseMeta));
|
return versions.map((releaseMeta) => new Release(releaseMeta));
|
||||||
}
|
}
|
||||||
|
|
||||||
const semver = require('semver');
|
|
||||||
|
|
||||||
async function findLatestVersion (versions) {
|
async function findLatestVersion (versions) {
|
||||||
return versions.filter((v) => semver.prerelease(v) === null).sort((a, b) => semver.rcompare(a, b))[0];
|
return versions
|
||||||
|
.filter((v) => semver.prerelease(v) === null)
|
||||||
|
.sort((a, b) => semver.rcompare(a, b))[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findLatestVersionInRange (versions, range) {
|
async function findLatestVersionInRange (versions, range) {
|
||||||
return semver.maxSatisfying(versions, range, { prerelease: true, loose: true });
|
return semver.maxSatisfying(versions, range, {
|
||||||
|
prerelease: true,
|
||||||
|
loose: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,12 +84,21 @@ async function findLatestVersionInRange (versions, range) {
|
|||||||
* @param {function} fetchReleasesFn: Optional function to fetch releases.
|
* @param {function} fetchReleasesFn: Optional function to fetch releases.
|
||||||
* @return {Release} Release.
|
* @return {Release} Release.
|
||||||
*/
|
*/
|
||||||
async function getRelease (version, githubToken, fetchReleasesFn = fetchReleases) {
|
async function getRelease (
|
||||||
|
version,
|
||||||
|
githubToken,
|
||||||
|
fetchReleasesFn = fetchReleases
|
||||||
|
) {
|
||||||
const latestVersionLabel = 'latest';
|
const latestVersionLabel = 'latest';
|
||||||
|
|
||||||
const versionsRange = semver.validRange(version, { prerelease: true, loose: true });
|
const versionsRange = semver.validRange(version, {
|
||||||
|
prerelease: true,
|
||||||
|
loose: true
|
||||||
|
});
|
||||||
if (versionsRange === null && version !== latestVersionLabel) {
|
if (versionsRange === null && version !== latestVersionLabel) {
|
||||||
throw new Error('Input version cannot be used, see semver: https://semver.org/spec/v2.0.0.html');
|
throw new Error(
|
||||||
|
'Input version cannot be used, see semver: https://semver.org/spec/v2.0.0.html'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const releases = await fetchReleasesFn(githubToken);
|
const releases = await fetchReleasesFn(githubToken);
|
||||||
@@ -88,24 +107,22 @@ async function getRelease (version, githubToken, fetchReleasesFn = fetchReleases
|
|||||||
throw new Error('No tofu releases found, please contact OpenTofu');
|
throw new Error('No tofu releases found, please contact OpenTofu');
|
||||||
}
|
}
|
||||||
|
|
||||||
const versionsFound = releases.map(release => release.version);
|
const versionsFound = releases.map((release) => release.version);
|
||||||
let versionSelected;
|
let versionSelected;
|
||||||
if (version === latestVersionLabel) {
|
if (version === latestVersionLabel) {
|
||||||
versionSelected = await findLatestVersion(versionsFound);
|
versionSelected = await findLatestVersion(versionsFound);
|
||||||
} else {
|
} else {
|
||||||
versionSelected = await findLatestVersionInRange(versionsFound, versionsRange);
|
versionSelected = await findLatestVersionInRange(
|
||||||
|
versionsFound,
|
||||||
|
versionsRange
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (versionSelected === null) {
|
if (versionSelected === null) {
|
||||||
throw new Error('No matching version found');
|
throw new Error('No matching version found');
|
||||||
}
|
}
|
||||||
|
|
||||||
return releases.find(release => release.version === versionSelected);
|
return releases.find((release) => release.version === versionSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that the export is defined as adaptor to replace hashicorp/js-releases
|
export { getRelease, Release };
|
||||||
// See: https://github.com/hashicorp/setup-terraform/blob/e192cfcbae6c6ed207c277ed7624131996c9bf13/lib/setup-terraform.js#L15
|
|
||||||
module.exports = {
|
|
||||||
getRelease,
|
|
||||||
Release
|
|
||||||
};
|
|
||||||
+87
-66
@@ -5,15 +5,26 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Node.js core
|
// Node.js core
|
||||||
const fs = require('fs').promises;
|
import { promises as fs } from 'fs';
|
||||||
const os = require('os');
|
import { platform, arch } from 'os';
|
||||||
const path = require('path');
|
import { sep, resolve, dirname } from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
// External
|
// External
|
||||||
const core = require('@actions/core');
|
import {
|
||||||
const tc = require('@actions/tool-cache');
|
debug,
|
||||||
const io = require('@actions/io');
|
error as logError,
|
||||||
const releases = require('./releases');
|
exportVariable,
|
||||||
|
getInput,
|
||||||
|
warning,
|
||||||
|
addPath
|
||||||
|
} from '@actions/core';
|
||||||
|
import { downloadTool, extractZip, find, cacheDir } from '@actions/tool-cache';
|
||||||
|
import { mv, cp, mkdirP } from '@actions/io';
|
||||||
|
import { getRelease } from './releases.js';
|
||||||
|
|
||||||
|
// __dirname is not available in ES modules, so we need to construct it ourselves
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
// arch in [arm, x32, x64...] (https://nodejs.org/api/os.html#os_os_arch)
|
// arch in [arm, x32, x64...] (https://nodejs.org/api/os.html#os_os_arch)
|
||||||
// return value in [amd64, 386, arm]
|
// return value in [amd64, 386, arm]
|
||||||
@@ -35,8 +46,8 @@ function mapOS (os) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function downloadAndExtractCLI (url) {
|
async function downloadAndExtractCLI (url) {
|
||||||
core.debug(`Downloading OpenTofu CLI from ${url}`);
|
debug(`Downloading OpenTofu CLI from ${url}`);
|
||||||
const pathToCLIZip = await tc.downloadTool(url);
|
const pathToCLIZip = await downloadTool(url);
|
||||||
|
|
||||||
if (!pathToCLIZip) {
|
if (!pathToCLIZip) {
|
||||||
throw new Error(`Unable to download OpenTofu from ${url}`);
|
throw new Error(`Unable to download OpenTofu from ${url}`);
|
||||||
@@ -44,18 +55,18 @@ async function downloadAndExtractCLI (url) {
|
|||||||
|
|
||||||
let pathToCLI;
|
let pathToCLI;
|
||||||
|
|
||||||
core.debug('Extracting OpenTofu CLI zip file');
|
debug('Extracting OpenTofu CLI zip file');
|
||||||
if (os.platform().startsWith('win')) {
|
if (platform().startsWith('win')) {
|
||||||
core.debug(`OpenTofu CLI Download Path is ${pathToCLIZip}`);
|
debug(`OpenTofu CLI Download Path is ${pathToCLIZip}`);
|
||||||
const fixedPathToCLIZip = `${pathToCLIZip}.zip`;
|
const fixedPathToCLIZip = `${pathToCLIZip}.zip`;
|
||||||
await io.mv(pathToCLIZip, fixedPathToCLIZip);
|
await mv(pathToCLIZip, fixedPathToCLIZip);
|
||||||
core.debug(`Moved download to ${fixedPathToCLIZip}`);
|
debug(`Moved download to ${fixedPathToCLIZip}`);
|
||||||
pathToCLI = await tc.extractZip(fixedPathToCLIZip);
|
pathToCLI = await extractZip(fixedPathToCLIZip);
|
||||||
} else {
|
} else {
|
||||||
pathToCLI = await tc.extractZip(pathToCLIZip);
|
pathToCLI = await extractZip(pathToCLIZip);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(`OpenTofu CLI path is ${pathToCLI}.`);
|
debug(`OpenTofu CLI path is ${pathToCLI}.`);
|
||||||
|
|
||||||
if (!pathToCLI) {
|
if (!pathToCLI) {
|
||||||
throw new Error('Unable to unzip OpenTofu');
|
throw new Error('Unable to unzip OpenTofu');
|
||||||
@@ -68,32 +79,34 @@ async function installWrapper (pathToCLI) {
|
|||||||
let source, target;
|
let source, target;
|
||||||
|
|
||||||
// If we're on Windows, then the executable ends with .exe
|
// If we're on Windows, then the executable ends with .exe
|
||||||
const exeSuffix = os.platform().startsWith('win') ? '.exe' : '';
|
const exeSuffix = platform().startsWith('win') ? '.exe' : '';
|
||||||
|
|
||||||
// Rename tofu(.exe) to tofu-bin(.exe)
|
// Rename tofu(.exe) to tofu-bin(.exe)
|
||||||
try {
|
try {
|
||||||
source = [pathToCLI, `tofu${exeSuffix}`].join(path.sep);
|
source = [pathToCLI, `tofu${exeSuffix}`].join(sep);
|
||||||
target = [pathToCLI, `tofu-bin${exeSuffix}`].join(path.sep);
|
target = [pathToCLI, `tofu-bin${exeSuffix}`].join(sep);
|
||||||
core.debug(`Moving ${source} to ${target}.`);
|
debug(`Moving ${source} to ${target}.`);
|
||||||
await io.mv(source, target);
|
await mv(source, target);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.error(`Unable to move ${source} to ${target}.`);
|
logError(`Unable to move ${source} to ${target}.`);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install our wrapper as tofu
|
// Install our wrapper as tofu
|
||||||
try {
|
try {
|
||||||
source = path.resolve([__dirname, '..', 'wrapper', 'dist', 'index.js'].join(path.sep));
|
source = resolve(
|
||||||
target = [pathToCLI, 'tofu'].join(path.sep);
|
[__dirname, '..', 'wrapper', 'dist', 'index.js'].join(sep)
|
||||||
core.debug(`Copying ${source} to ${target}.`);
|
);
|
||||||
await io.cp(source, target);
|
target = [pathToCLI, 'tofu'].join(sep);
|
||||||
|
debug(`Copying ${source} to ${target}.`);
|
||||||
|
await cp(source, target);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.error(`Unable to copy ${source} to ${target}.`);
|
logError(`Unable to copy ${source} to ${target}.`);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export a new environment variable, so our wrapper can locate the binary
|
// Export a new environment variable, so our wrapper can locate the binary
|
||||||
core.exportVariable('TOFU_CLI_PATH', pathToCLI);
|
exportVariable('TOFU_CLI_PATH', pathToCLI);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add credentials to CLI Configuration File
|
// Add credentials to CLI Configuration File
|
||||||
@@ -105,37 +118,43 @@ async function addCredentials (credentialsHostname, credentialsToken, osPlat) {
|
|||||||
credentials "${credentialsHostname}" {
|
credentials "${credentialsHostname}" {
|
||||||
token = "${credentialsToken}"
|
token = "${credentialsToken}"
|
||||||
}`.trim();
|
}`.trim();
|
||||||
// eslint-enable
|
// eslint-enable
|
||||||
|
|
||||||
// default to OS-specific path
|
// default to OS-specific path
|
||||||
let credsFile = osPlat === 'win32'
|
let credsFile =
|
||||||
? `${process.env.APPDATA}/tofu.rc`
|
osPlat === 'win32'
|
||||||
: `${process.env.HOME}/.tofurc`;
|
? `${process.env.APPDATA}/tofu.rc`
|
||||||
|
: `${process.env.HOME}/.tofurc`;
|
||||||
|
|
||||||
// override with TF_CLI_CONFIG_FILE environment variable
|
// override with TF_CLI_CONFIG_FILE environment variable
|
||||||
credsFile = process.env.TF_CLI_CONFIG_FILE ? process.env.TF_CLI_CONFIG_FILE : credsFile;
|
credsFile = process.env.TF_CLI_CONFIG_FILE
|
||||||
|
? process.env.TF_CLI_CONFIG_FILE
|
||||||
|
: credsFile;
|
||||||
|
|
||||||
// get containing folder
|
// get containing folder
|
||||||
const credsFolder = path.dirname(credsFile);
|
const credsFolder = dirname(credsFile);
|
||||||
|
|
||||||
core.debug(`Creating ${credsFolder}`);
|
debug(`Creating ${credsFolder}`);
|
||||||
await io.mkdirP(credsFolder);
|
await mkdirP(credsFolder);
|
||||||
|
|
||||||
core.debug(`Adding credentials to ${credsFile}`);
|
debug(`Adding credentials to ${credsFile}`);
|
||||||
await fs.writeFile(credsFile, creds);
|
await fs.writeFile(credsFile, creds);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function run () {
|
async function run () {
|
||||||
try {
|
try {
|
||||||
// Gather GitHub Actions inputs
|
// Gather GitHub Actions inputs
|
||||||
let version = core.getInput('tofu_version');
|
let version = getInput('tofu_version');
|
||||||
const versionFile = core.getInput('tofu_version_file');
|
const versionFile = getInput('tofu_version_file');
|
||||||
const credentialsHostname = core.getInput('cli_config_credentials_hostname');
|
const credentialsHostname = getInput('cli_config_credentials_hostname');
|
||||||
const credentialsToken = core.getInput('cli_config_credentials_token');
|
const credentialsToken = getInput('cli_config_credentials_token');
|
||||||
const wrapper = core.getInput('tofu_wrapper') === 'true';
|
const wrapper = getInput('tofu_wrapper') === 'true';
|
||||||
const useCache = core.getInput('cache') === 'true';
|
const useCache = getInput('cache') === 'true';
|
||||||
let githubToken = core.getInput('github_token');
|
let githubToken = getInput('github_token');
|
||||||
if (githubToken === '' && !(process.env.FORGEJO_ACTIONS || process.env.GITEA_ACTIONS)) {
|
if (
|
||||||
|
githubToken === '' &&
|
||||||
|
!(process.env.FORGEJO_ACTIONS || process.env.GITEA_ACTIONS)
|
||||||
|
) {
|
||||||
// Only default to the environment variable when running in GitHub Actions. Don't do this for other CI systems
|
// Only default to the environment variable when running in GitHub Actions. Don't do this for other CI systems
|
||||||
// that may set the GITHUB_TOKEN environment variable.
|
// that may set the GITHUB_TOKEN environment variable.
|
||||||
githubToken = process.env.GITHUB_TOKEN;
|
githubToken = process.env.GITHUB_TOKEN;
|
||||||
@@ -144,49 +163,51 @@ async function run () {
|
|||||||
// If tofu_version_file is provided, read the version from the file
|
// If tofu_version_file is provided, read the version from the file
|
||||||
if (versionFile) {
|
if (versionFile) {
|
||||||
try {
|
try {
|
||||||
core.debug(`Reading OpenTofu version from file: ${versionFile}`);
|
debug(`Reading OpenTofu version from file: ${versionFile}`);
|
||||||
const fileVersion = await fs.readFile(versionFile, 'utf8');
|
const fileVersion = await fs.readFile(versionFile, 'utf8');
|
||||||
const trimmedVersion = fileVersion.trim();
|
const trimmedVersion = fileVersion.trim();
|
||||||
if (trimmedVersion) {
|
if (trimmedVersion) {
|
||||||
version = trimmedVersion;
|
version = trimmedVersion;
|
||||||
core.debug(`Using version from file: ${version}`);
|
debug(`Using version from file: ${version}`);
|
||||||
} else {
|
} else {
|
||||||
core.warning(
|
warning(
|
||||||
`Version file ${versionFile} is empty, using tofu_version input: ${version}`
|
`Version file ${versionFile} is empty, using tofu_version input: ${version}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.warning(
|
warning(
|
||||||
`Failed to read version from file ${versionFile}: ${error.message}. Using tofu_version input: ${version}`
|
`Failed to read version from file ${versionFile}: ${error.message}. Using tofu_version input: ${version}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gather OS details
|
// Gather OS details
|
||||||
const osPlatform = os.platform();
|
const osPlatform = platform();
|
||||||
const osArch = os.arch();
|
const osArch = arch();
|
||||||
|
|
||||||
core.debug(`Finding releases for OpenTofu version ${version}`);
|
debug(`Finding releases for OpenTofu version ${version}`);
|
||||||
const release = await releases.getRelease(version, githubToken);
|
const release = await getRelease(version, githubToken);
|
||||||
const platform = mapOS(osPlatform);
|
const buildPlatform = mapOS(osPlatform);
|
||||||
const arch = mapArch(osArch);
|
const buildArch = mapArch(osArch);
|
||||||
const build = release.getBuild(platform, arch);
|
const build = release.getBuild(buildPlatform, buildArch);
|
||||||
if (!build) {
|
if (!build) {
|
||||||
throw new Error(`OpenTofu version ${version} not available for ${platform} and ${arch}`);
|
throw new Error(
|
||||||
|
`OpenTofu version ${version} not available for ${buildPlatform} and ${buildArch}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download requested version if not cached
|
// Download requested version if not cached
|
||||||
let pathToCLI;
|
let pathToCLI;
|
||||||
if (useCache) {
|
if (useCache) {
|
||||||
const cachedPath = tc.find('tofu', release.version, arch);
|
const cachedPath = find('tofu', release.version, buildArch);
|
||||||
if (cachedPath) {
|
if (cachedPath) {
|
||||||
core.debug(`Using cached OpenTofu version ${release.version} from ${cachedPath}`);
|
debug(`Using cached OpenTofu version ${release.version} from ${cachedPath}`);
|
||||||
pathToCLI = cachedPath;
|
pathToCLI = cachedPath;
|
||||||
} else {
|
} else {
|
||||||
core.debug(`OpenTofu version ${release.version} not found in cache, downloading...`);
|
debug(`OpenTofu version ${release.version} not found in cache, downloading...`);
|
||||||
const extractedPath = await downloadAndExtractCLI(build.url);
|
const extractedPath = await downloadAndExtractCLI(build.url);
|
||||||
core.debug(`Caching OpenTofu version ${release.version} to tool cache`);
|
debug(`Caching OpenTofu version ${release.version} to tool cache`);
|
||||||
pathToCLI = await tc.cacheDir(extractedPath, 'tofu', release.version, arch);
|
pathToCLI = await cacheDir(extractedPath, 'tofu', release.version, buildArch);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pathToCLI = await downloadAndExtractCLI(build.url);
|
pathToCLI = await downloadAndExtractCLI(build.url);
|
||||||
@@ -198,7 +219,7 @@ async function run () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add to path
|
// Add to path
|
||||||
core.addPath(pathToCLI);
|
addPath(pathToCLI);
|
||||||
|
|
||||||
// Add credentials to file if they are provided
|
// Add credentials to file if they are provided
|
||||||
if (credentialsHostname && credentialsToken) {
|
if (credentialsHostname && credentialsToken) {
|
||||||
@@ -206,9 +227,9 @@ async function run () {
|
|||||||
}
|
}
|
||||||
return release;
|
return release;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.error(error);
|
logError(error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = run;
|
export default run;
|
||||||
+183
-160
@@ -1,175 +1,198 @@
|
|||||||
const pkg = require('../releases');
|
/**
|
||||||
|
* Copyright (c) HashiCorp, Inc.
|
||||||
|
* Copyright (c) OpenTofu
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Release, getRelease } from '../releases.js';
|
||||||
|
|
||||||
describe('getRelease', () => {
|
describe('getRelease', () => {
|
||||||
function mockFetchReleases () {
|
function mockFetchReleases () {
|
||||||
const mockReleasesMeta = [{
|
const mockReleasesMeta = [
|
||||||
id: 'v1.7.0-alpha2',
|
{
|
||||||
files: [
|
id: 'v1.7.0-alpha2',
|
||||||
'tofu_1.7.0-alpha2_386.apk',
|
files: [
|
||||||
'tofu_1.7.0-alpha2_386.deb',
|
'tofu_1.7.0-alpha2_386.apk',
|
||||||
'tofu_1.7.0-alpha2_386.rpm',
|
'tofu_1.7.0-alpha2_386.deb',
|
||||||
'tofu_1.7.0-alpha2_amd64.apk',
|
'tofu_1.7.0-alpha2_386.rpm',
|
||||||
'tofu_1.7.0-alpha2_amd64.deb',
|
'tofu_1.7.0-alpha2_amd64.apk',
|
||||||
'tofu_1.7.0-alpha2_amd64.rpm',
|
'tofu_1.7.0-alpha2_amd64.deb',
|
||||||
'tofu_1.7.0-alpha2_arm.apk',
|
'tofu_1.7.0-alpha2_amd64.rpm',
|
||||||
'tofu_1.7.0-alpha2_arm.deb',
|
'tofu_1.7.0-alpha2_arm.apk',
|
||||||
'tofu_1.7.0-alpha2_arm.rpm',
|
'tofu_1.7.0-alpha2_arm.deb',
|
||||||
'tofu_1.7.0-alpha2_arm64.apk',
|
'tofu_1.7.0-alpha2_arm.rpm',
|
||||||
'tofu_1.7.0-alpha2_arm64.deb',
|
'tofu_1.7.0-alpha2_arm64.apk',
|
||||||
'tofu_1.7.0-alpha2_arm64.rpm',
|
'tofu_1.7.0-alpha2_arm64.deb',
|
||||||
'tofu_1.7.0-alpha2_darwin_arm64.zip',
|
'tofu_1.7.0-alpha2_arm64.rpm',
|
||||||
'tofu_1.7.0-alpha2_freebsd_386.zip',
|
'tofu_1.7.0-alpha2_darwin_arm64.zip',
|
||||||
'tofu_1.7.0-alpha2_freebsd_amd64.zip',
|
'tofu_1.7.0-alpha2_freebsd_386.zip',
|
||||||
'tofu_1.7.0-alpha2_freebsd_arm.zip',
|
'tofu_1.7.0-alpha2_freebsd_amd64.zip',
|
||||||
'tofu_1.7.0-alpha2_linux_386.zip',
|
'tofu_1.7.0-alpha2_freebsd_arm.zip',
|
||||||
'tofu_1.7.0-alpha2_linux_amd64.zip',
|
'tofu_1.7.0-alpha2_linux_386.zip',
|
||||||
'tofu_1.7.0-alpha2_linux_arm.zip',
|
'tofu_1.7.0-alpha2_linux_amd64.zip',
|
||||||
'tofu_1.7.0-alpha2_linux_arm64.zip',
|
'tofu_1.7.0-alpha2_linux_arm.zip',
|
||||||
'tofu_1.7.0-alpha2_openbsd_386.zip',
|
'tofu_1.7.0-alpha2_linux_arm64.zip',
|
||||||
'tofu_1.7.0-alpha2_openbsd_amd64.zip',
|
'tofu_1.7.0-alpha2_openbsd_386.zip',
|
||||||
'tofu_1.7.0-alpha2_SHA256SUMS',
|
'tofu_1.7.0-alpha2_openbsd_amd64.zip',
|
||||||
'tofu_1.7.0-alpha2_SHA256SUMS.pem',
|
'tofu_1.7.0-alpha2_SHA256SUMS',
|
||||||
'tofu_1.7.0-alpha2_SHA256SUMS.sig',
|
'tofu_1.7.0-alpha2_SHA256SUMS.pem',
|
||||||
'tofu_1.7.0-alpha2_solaris_amd64.zip',
|
'tofu_1.7.0-alpha2_SHA256SUMS.sig',
|
||||||
'tofu_1.7.0-alpha2_windows_386.zip',
|
'tofu_1.7.0-alpha2_solaris_amd64.zip',
|
||||||
'tofu_1.7.0-alpha2_windows_amd64.zip'
|
'tofu_1.7.0-alpha2_windows_386.zip',
|
||||||
]
|
'tofu_1.7.0-alpha2_windows_amd64.zip'
|
||||||
}, {
|
]
|
||||||
id: 'v1.6.0',
|
},
|
||||||
files: [
|
{
|
||||||
'tofu_1.6.0_386.apk',
|
id: 'v1.6.0',
|
||||||
'tofu_1.6.0_386.deb',
|
files: [
|
||||||
'tofu_1.6.0_386.rpm',
|
'tofu_1.6.0_386.apk',
|
||||||
'tofu_1.6.0_amd64.apk',
|
'tofu_1.6.0_386.deb',
|
||||||
'tofu_1.6.0_amd64.deb',
|
'tofu_1.6.0_386.rpm',
|
||||||
'tofu_1.6.0_amd64.rpm',
|
'tofu_1.6.0_amd64.apk',
|
||||||
'tofu_1.6.0_arm.apk',
|
'tofu_1.6.0_amd64.deb',
|
||||||
'tofu_1.6.0_arm.deb',
|
'tofu_1.6.0_amd64.rpm',
|
||||||
'tofu_1.6.0_arm.rpm',
|
'tofu_1.6.0_arm.apk',
|
||||||
'tofu_1.6.0_arm64.apk',
|
'tofu_1.6.0_arm.deb',
|
||||||
'tofu_1.6.0_arm64.deb',
|
'tofu_1.6.0_arm.rpm',
|
||||||
'tofu_1.6.0_arm64.rpm',
|
'tofu_1.6.0_arm64.apk',
|
||||||
'tofu_1.6.0_darwin_arm64.zip',
|
'tofu_1.6.0_arm64.deb',
|
||||||
'tofu_1.6.0_freebsd_386.zip',
|
'tofu_1.6.0_arm64.rpm',
|
||||||
'tofu_1.6.0_freebsd_amd64.zip',
|
'tofu_1.6.0_darwin_arm64.zip',
|
||||||
'tofu_1.6.0_freebsd_arm.zip',
|
'tofu_1.6.0_freebsd_386.zip',
|
||||||
'tofu_1.6.0_linux_386.zip',
|
'tofu_1.6.0_freebsd_amd64.zip',
|
||||||
'tofu_1.6.0_linux_amd64.zip',
|
'tofu_1.6.0_freebsd_arm.zip',
|
||||||
'tofu_1.6.0_linux_arm.zip',
|
'tofu_1.6.0_linux_386.zip',
|
||||||
'tofu_1.6.0_linux_arm64.zip',
|
'tofu_1.6.0_linux_amd64.zip',
|
||||||
'tofu_1.6.0_openbsd_386.zip',
|
'tofu_1.6.0_linux_arm.zip',
|
||||||
'tofu_1.6.0_openbsd_amd64.zip',
|
'tofu_1.6.0_linux_arm64.zip',
|
||||||
'tofu_1.6.0_SHA256SUMS',
|
'tofu_1.6.0_openbsd_386.zip',
|
||||||
'tofu_1.6.0_SHA256SUMS.pem',
|
'tofu_1.6.0_openbsd_amd64.zip',
|
||||||
'tofu_1.6.0_SHA256SUMS.sig',
|
'tofu_1.6.0_SHA256SUMS',
|
||||||
'tofu_1.6.0_solaris_amd64.zip',
|
'tofu_1.6.0_SHA256SUMS.pem',
|
||||||
'tofu_1.6.0_windows_386.zip',
|
'tofu_1.6.0_SHA256SUMS.sig',
|
||||||
'tofu_1.6.0_windows_amd64.zip']
|
'tofu_1.6.0_solaris_amd64.zip',
|
||||||
}, {
|
'tofu_1.6.0_windows_386.zip',
|
||||||
id: 'v1.6.0-alpha2',
|
'tofu_1.6.0_windows_amd64.zip'
|
||||||
files: [
|
]
|
||||||
'tofu_1.6.0-alpha2_386.apk',
|
},
|
||||||
'tofu_1.6.0-alpha2_386.deb',
|
{
|
||||||
'tofu_1.6.0-alpha2_386.rpm',
|
id: 'v1.6.0-alpha2',
|
||||||
'tofu_1.6.0-alpha2_amd64.apk',
|
files: [
|
||||||
'tofu_1.6.0-alpha2_amd64.deb',
|
'tofu_1.6.0-alpha2_386.apk',
|
||||||
'tofu_1.6.0-alpha2_amd64.rpm',
|
'tofu_1.6.0-alpha2_386.deb',
|
||||||
'tofu_1.6.0-alpha2_arm.apk',
|
'tofu_1.6.0-alpha2_386.rpm',
|
||||||
'tofu_1.6.0-alpha2_arm.deb',
|
'tofu_1.6.0-alpha2_amd64.apk',
|
||||||
'tofu_1.6.0-alpha2_arm.rpm',
|
'tofu_1.6.0-alpha2_amd64.deb',
|
||||||
'tofu_1.6.0-alpha2_arm64.apk',
|
'tofu_1.6.0-alpha2_amd64.rpm',
|
||||||
'tofu_1.6.0-alpha2_arm64.deb',
|
'tofu_1.6.0-alpha2_arm.apk',
|
||||||
'tofu_1.6.0-alpha2_arm64.rpm',
|
'tofu_1.6.0-alpha2_arm.deb',
|
||||||
'tofu_1.6.0-alpha2_darwin_arm64.zip',
|
'tofu_1.6.0-alpha2_arm.rpm',
|
||||||
'tofu_1.6.0-alpha2_freebsd_386.zip',
|
'tofu_1.6.0-alpha2_arm64.apk',
|
||||||
'tofu_1.6.0-alpha2_freebsd_amd64.zip',
|
'tofu_1.6.0-alpha2_arm64.deb',
|
||||||
'tofu_1.6.0-alpha2_freebsd_arm.zip',
|
'tofu_1.6.0-alpha2_arm64.rpm',
|
||||||
'tofu_1.6.0-alpha2_linux_386.zip',
|
'tofu_1.6.0-alpha2_darwin_arm64.zip',
|
||||||
'tofu_1.6.0-alpha2_linux_amd64.zip',
|
'tofu_1.6.0-alpha2_freebsd_386.zip',
|
||||||
'tofu_1.6.0-alpha2_linux_arm.zip',
|
'tofu_1.6.0-alpha2_freebsd_amd64.zip',
|
||||||
'tofu_1.6.0-alpha2_linux_arm64.zip',
|
'tofu_1.6.0-alpha2_freebsd_arm.zip',
|
||||||
'tofu_1.6.0-alpha2_openbsd_386.zip',
|
'tofu_1.6.0-alpha2_linux_386.zip',
|
||||||
'tofu_1.6.0-alpha2_openbsd_amd64.zip',
|
'tofu_1.6.0-alpha2_linux_amd64.zip',
|
||||||
'tofu_1.6.0-alpha2_SHA256SUMS',
|
'tofu_1.6.0-alpha2_linux_arm.zip',
|
||||||
'tofu_1.6.0-alpha2_SHA256SUMS.pem',
|
'tofu_1.6.0-alpha2_linux_arm64.zip',
|
||||||
'tofu_1.6.0-alpha2_SHA256SUMS.sig',
|
'tofu_1.6.0-alpha2_openbsd_386.zip',
|
||||||
'tofu_1.6.0-alpha2_solaris_amd64.zip',
|
'tofu_1.6.0-alpha2_openbsd_amd64.zip',
|
||||||
'tofu_1.6.0-alpha2_windows_386.zip',
|
'tofu_1.6.0-alpha2_SHA256SUMS',
|
||||||
'tofu_1.6.0-alpha2_windows_amd64.zip'
|
'tofu_1.6.0-alpha2_SHA256SUMS.pem',
|
||||||
]
|
'tofu_1.6.0-alpha2_SHA256SUMS.sig',
|
||||||
}, {
|
'tofu_1.6.0-alpha2_solaris_amd64.zip',
|
||||||
id: 'v1.6.0-alpha1',
|
'tofu_1.6.0-alpha2_windows_386.zip',
|
||||||
files: [
|
'tofu_1.6.0-alpha2_windows_amd64.zip'
|
||||||
'tofu_1.6.0-alpha1_386.apk',
|
]
|
||||||
'tofu_1.6.0-alpha1_386.deb',
|
},
|
||||||
'tofu_1.6.0-alpha1_386.rpm',
|
{
|
||||||
'tofu_1.6.0-alpha1_amd64.apk',
|
id: 'v1.6.0-alpha1',
|
||||||
'tofu_1.6.0-alpha1_amd64.deb',
|
files: [
|
||||||
'tofu_1.6.0-alpha1_amd64.rpm',
|
'tofu_1.6.0-alpha1_386.apk',
|
||||||
'tofu_1.6.0-alpha1_arm.apk',
|
'tofu_1.6.0-alpha1_386.deb',
|
||||||
'tofu_1.6.0-alpha1_arm.deb',
|
'tofu_1.6.0-alpha1_386.rpm',
|
||||||
'tofu_1.6.0-alpha1_arm.rpm',
|
'tofu_1.6.0-alpha1_amd64.apk',
|
||||||
'tofu_1.6.0-alpha1_arm64.apk',
|
'tofu_1.6.0-alpha1_amd64.deb',
|
||||||
'tofu_1.6.0-alpha1_arm64.deb',
|
'tofu_1.6.0-alpha1_amd64.rpm',
|
||||||
'tofu_1.6.0-alpha1_arm64.rpm',
|
'tofu_1.6.0-alpha1_arm.apk',
|
||||||
'tofu_1.6.0-alpha1_darwin_amd64.zip',
|
'tofu_1.6.0-alpha1_arm.deb',
|
||||||
'tofu_1.6.0-alpha1_darwin_arm64.zip',
|
'tofu_1.6.0-alpha1_arm.rpm',
|
||||||
'tofu_1.6.0-alpha1_freebsd_386.zip',
|
'tofu_1.6.0-alpha1_arm64.apk',
|
||||||
'tofu_1.6.0-alpha1_freebsd_amd64.zip',
|
'tofu_1.6.0-alpha1_arm64.deb',
|
||||||
'tofu_1.6.0-alpha1_freebsd_arm.zip',
|
'tofu_1.6.0-alpha1_arm64.rpm',
|
||||||
'tofu_1.6.0-alpha1_linux_386.zip',
|
'tofu_1.6.0-alpha1_darwin_amd64.zip',
|
||||||
'tofu_1.6.0-alpha1_linux_amd64.zip',
|
'tofu_1.6.0-alpha1_darwin_arm64.zip',
|
||||||
'tofu_1.6.0-alpha1_linux_arm.zip',
|
'tofu_1.6.0-alpha1_freebsd_386.zip',
|
||||||
'tofu_1.6.0-alpha1_linux_arm64.zip',
|
'tofu_1.6.0-alpha1_freebsd_amd64.zip',
|
||||||
'tofu_1.6.0-alpha1_openbsd_386.zip',
|
'tofu_1.6.0-alpha1_freebsd_arm.zip',
|
||||||
'tofu_1.6.0-alpha1_openbsd_amd64.zip',
|
'tofu_1.6.0-alpha1_linux_386.zip',
|
||||||
'tofu_1.6.0-alpha1_SHA256SUMS',
|
'tofu_1.6.0-alpha1_linux_amd64.zip',
|
||||||
'tofu_1.6.0-alpha1_SHA256SUMS.pem',
|
'tofu_1.6.0-alpha1_linux_arm.zip',
|
||||||
'tofu_1.6.0-alpha1_SHA256SUMS.sig',
|
'tofu_1.6.0-alpha1_linux_arm64.zip',
|
||||||
'tofu_1.6.0-alpha1_solaris_amd64.zip',
|
'tofu_1.6.0-alpha1_openbsd_386.zip',
|
||||||
'tofu_1.6.0-alpha1_windows_386.zip',
|
'tofu_1.6.0-alpha1_openbsd_amd64.zip',
|
||||||
'tofu_1.6.0-alpha1_windows_amd64.zip'
|
'tofu_1.6.0-alpha1_SHA256SUMS',
|
||||||
]
|
'tofu_1.6.0-alpha1_SHA256SUMS.pem',
|
||||||
}];
|
'tofu_1.6.0-alpha1_SHA256SUMS.sig',
|
||||||
|
'tofu_1.6.0-alpha1_solaris_amd64.zip',
|
||||||
|
'tofu_1.6.0-alpha1_windows_386.zip',
|
||||||
|
'tofu_1.6.0-alpha1_windows_amd64.zip'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
return mockReleasesMeta.map(el => new pkg.Release(el));
|
return mockReleasesMeta.map((el) => new Release(el));
|
||||||
}
|
}
|
||||||
|
|
||||||
it.each(
|
it.each([
|
||||||
[
|
['latest', '1.6.0'],
|
||||||
['latest', '1.6.0'],
|
['<1.6.0-beta', '1.6.0-alpha2'],
|
||||||
['<1.6.0-beta', '1.6.0-alpha2'],
|
['>1.6.0-alpha1', '1.6.0'],
|
||||||
['>1.6.0-alpha1', '1.6.0'],
|
['>1.6.0-alpha1 <1.6.0', '1.6.0-alpha2'],
|
||||||
['>1.6.0-alpha1 <1.6.0', '1.6.0-alpha2'],
|
['~1.6.0-alpha', '1.6.0'],
|
||||||
['~1.6.0-alpha', '1.6.0'],
|
['<=1.6.0-alpha1', '1.6.0-alpha1'],
|
||||||
['<=1.6.0-alpha1', '1.6.0-alpha1'],
|
['>1.5.0', '1.6.0'],
|
||||||
['>1.5.0', '1.6.0'],
|
['>1.5.0', '1.6.0'],
|
||||||
['>1.5.0', '1.6.0'],
|
['>1.7.0-alpha', '1.7.0-alpha2']
|
||||||
['>1.7.0-alpha', '1.7.0-alpha2']
|
])("happy path: getRelease('%s') -> '%s'", async (input, wantVersion) => {
|
||||||
]
|
const want = mockFetchReleases().find((el) => el.version === wantVersion);
|
||||||
)('happy path: getRelease(\'%s\') -> \'%s\'', async (input, wantVersion) => {
|
const gotRelease = await getRelease(input, '', mockFetchReleases);
|
||||||
const want = mockFetchReleases().find(el => el.version === wantVersion);
|
|
||||||
const gotRelease = await pkg.getRelease(input, '', mockFetchReleases);
|
|
||||||
expect(gotRelease).toEqual(want);
|
expect(gotRelease).toEqual(want);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each(
|
it.each([
|
||||||
[
|
[
|
||||||
['foo', 'Input version cannot be used, see semver: https://semver.org/spec/v2.0.0.html', mockFetchReleases],
|
'foo',
|
||||||
['2.0', 'No matching version found', mockFetchReleases],
|
'Input version cannot be used, see semver: https://semver.org/spec/v2.0.0.html',
|
||||||
['latest', 'No tofu releases found, please contact OpenTofu', async () => {
|
mockFetchReleases
|
||||||
|
],
|
||||||
|
['2.0', 'No matching version found', mockFetchReleases],
|
||||||
|
[
|
||||||
|
'latest',
|
||||||
|
'No tofu releases found, please contact OpenTofu',
|
||||||
|
async () => {
|
||||||
return null;
|
return null;
|
||||||
}],
|
}
|
||||||
['latest', 'No tofu releases found, please contact OpenTofu', async () => {
|
],
|
||||||
|
[
|
||||||
|
'latest',
|
||||||
|
'No tofu releases found, please contact OpenTofu',
|
||||||
|
async () => {
|
||||||
return [];
|
return [];
|
||||||
}]
|
}
|
||||||
]
|
]
|
||||||
)('unhappy path: getRelease(\'%s\') -> throw Error(\'%s\')', async (input, wantErrorMessage, mockFetchReleasesFn) => {
|
])(
|
||||||
try {
|
"unhappy path: getRelease('%s') -> throw Error('%s')",
|
||||||
await pkg.getRelease(input, '', mockFetchReleasesFn);
|
async (input, wantErrorMessage, mockFetchReleasesFn) => {
|
||||||
expect(true).toBe(false);
|
try {
|
||||||
} catch (e) {
|
await getRelease(input, '', mockFetchReleasesFn);
|
||||||
expect(e.message).toBe(wantErrorMessage);
|
expect(true).toBe(false);
|
||||||
|
} catch (e) {
|
||||||
|
expect(e.message).toBe(wantErrorMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
});
|
});
|
||||||
+65
-43
@@ -1,31 +1,52 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) HashiCorp, Inc.
|
||||||
|
* Copyright (c) OpenTofu
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { jest } from '@jest/globals';
|
||||||
|
|
||||||
// Node.js core
|
// Node.js core
|
||||||
const fs = require('fs').promises;
|
import { promises as fs } from 'fs';
|
||||||
const os = require('os');
|
import { tmpdir } from 'os';
|
||||||
const path = require('path');
|
import { join } from 'path';
|
||||||
|
|
||||||
// External
|
// Set up mocks BEFORE dynamic imports
|
||||||
const core = require('@actions/core');
|
jest.unstable_mockModule('@actions/core', () => ({
|
||||||
|
getInput: jest.fn(),
|
||||||
|
setOutput: jest.fn(),
|
||||||
|
setFailed: jest.fn(),
|
||||||
|
debug: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
warning: jest.fn(),
|
||||||
|
addPath: jest.fn(),
|
||||||
|
exportVariable: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
// First party
|
jest.unstable_mockModule('@actions/io', () => ({
|
||||||
const releases = require('../releases');
|
|
||||||
const setup = require('../setup-tofu');
|
|
||||||
|
|
||||||
// Mock dependencies
|
|
||||||
jest.mock('@actions/core');
|
|
||||||
jest.mock('@actions/io', () => ({
|
|
||||||
mv: jest.fn(),
|
mv: jest.fn(),
|
||||||
cp: jest.fn(),
|
cp: jest.fn(),
|
||||||
mkdirP: jest.fn()
|
mkdirP: jest.fn()
|
||||||
}));
|
}));
|
||||||
jest.mock('@actions/tool-cache', () => ({
|
|
||||||
|
jest.unstable_mockModule('@actions/tool-cache', () => ({
|
||||||
downloadTool: jest.fn(),
|
downloadTool: jest.fn(),
|
||||||
extractZip: jest.fn(),
|
extractZip: jest.fn(),
|
||||||
find: jest.fn(),
|
find: jest.fn(),
|
||||||
cacheDir: jest.fn()
|
cacheDir: jest.fn()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Mock releases.js so setup-tofu.js can be tested in isolation
|
jest.unstable_mockModule('../releases.js', () => ({
|
||||||
jest.mock('../releases');
|
getRelease: jest.fn(),
|
||||||
|
Release: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Dynamic imports pick up the mocks
|
||||||
|
const { getInput, warning } = await import('@actions/core');
|
||||||
|
const tc = await import('@actions/tool-cache');
|
||||||
|
const io = await import('@actions/io');
|
||||||
|
const { getRelease } = await import('../releases.js');
|
||||||
|
const { default: setup } = await import('../setup-tofu.js');
|
||||||
|
|
||||||
// Set up global test fixtures
|
// Set up global test fixtures
|
||||||
const fallbackVersion = 'latest';
|
const fallbackVersion = 'latest';
|
||||||
@@ -38,13 +59,11 @@ let versionFileName = '.opentofu-version';
|
|||||||
describe('setup-tofu', () => {
|
describe('setup-tofu', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Mock dependencies
|
// Mock dependencies
|
||||||
const tc = require('@actions/tool-cache');
|
|
||||||
tc.downloadTool.mockResolvedValue('/mock/download/path');
|
tc.downloadTool.mockResolvedValue('/mock/download/path');
|
||||||
tc.extractZip.mockResolvedValue('/mock/extract/path');
|
tc.extractZip.mockResolvedValue('/mock/extract/path');
|
||||||
tc.find.mockReturnValue(null); // Default to cache miss
|
tc.find.mockReturnValue(null); // Default to cache miss
|
||||||
tc.cacheDir.mockResolvedValue('/mock/cached/path');
|
tc.cacheDir.mockResolvedValue('/mock/cached/path');
|
||||||
|
|
||||||
const io = require('@actions/io');
|
|
||||||
io.mv.mockResolvedValue();
|
io.mv.mockResolvedValue();
|
||||||
io.cp.mockResolvedValue();
|
io.cp.mockResolvedValue();
|
||||||
io.mkdirP.mockResolvedValue();
|
io.mkdirP.mockResolvedValue();
|
||||||
@@ -53,16 +72,16 @@ describe('setup-tofu', () => {
|
|||||||
version: '1.10.5',
|
version: '1.10.5',
|
||||||
getBuild: jest.fn().mockReturnValue({ url: 'mock-url' })
|
getBuild: jest.fn().mockReturnValue({ url: 'mock-url' })
|
||||||
};
|
};
|
||||||
releases.getRelease.mockResolvedValue(mockRelease);
|
getRelease.mockResolvedValue(mockRelease);
|
||||||
|
|
||||||
// Write version file to temporary directory
|
// Write version file to temporary directory
|
||||||
tempDirPath = path.join(os.tmpdir(), 'setup-tofu-');
|
tempDirPath = join(tmpdir(), 'setup-tofu-');
|
||||||
tempDir = await fs.mkdtemp(tempDirPath);
|
tempDir = await fs.mkdtemp(tempDirPath);
|
||||||
versionFile = path.join(tempDir, versionFileName);
|
versionFile = join(tempDir, versionFileName);
|
||||||
await fs.writeFile(versionFile, `${version}\n`);
|
await fs.writeFile(versionFile, `${version}\n`);
|
||||||
|
|
||||||
// Mock action inputs to return default values
|
// Mock action inputs to return default values
|
||||||
core.getInput.mockImplementation((name) => {
|
getInput.mockImplementation((name) => {
|
||||||
const defaults = {
|
const defaults = {
|
||||||
tofu_version: fallbackVersion,
|
tofu_version: fallbackVersion,
|
||||||
tofu_version_file: versionFile,
|
tofu_version_file: versionFile,
|
||||||
@@ -93,8 +112,9 @@ describe('setup-tofu', () => {
|
|||||||
|
|
||||||
await setup();
|
await setup();
|
||||||
|
|
||||||
expect(releases.getRelease).toHaveBeenCalledWith(
|
expect(getRelease).toHaveBeenCalledWith(
|
||||||
version, process.env.GITHUB_TOKEN
|
version,
|
||||||
|
process.env.GITHUB_TOKEN
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(fs.readFile).toHaveBeenCalled();
|
expect(fs.readFile).toHaveBeenCalled();
|
||||||
@@ -105,10 +125,10 @@ describe('setup-tofu', () => {
|
|||||||
|
|
||||||
version = ' ';
|
version = ' ';
|
||||||
versionFileName = '.opentofu-version-empty';
|
versionFileName = '.opentofu-version-empty';
|
||||||
versionFile = path.join(tempDir, versionFileName);
|
versionFile = join(tempDir, versionFileName);
|
||||||
await fs.writeFile(versionFile, `${version}\n`);
|
await fs.writeFile(versionFile, `${version}\n`);
|
||||||
|
|
||||||
core.getInput.mockImplementation((name) => {
|
getInput.mockImplementation((name) => {
|
||||||
if (name === 'tofu_version_file') {
|
if (name === 'tofu_version_file') {
|
||||||
return versionFile;
|
return versionFile;
|
||||||
}
|
}
|
||||||
@@ -120,11 +140,12 @@ describe('setup-tofu', () => {
|
|||||||
|
|
||||||
await setup();
|
await setup();
|
||||||
|
|
||||||
expect(releases.getRelease).toHaveBeenCalledWith(
|
expect(getRelease).toHaveBeenCalledWith(
|
||||||
fallbackVersion, process.env.GITHUB_TOKEN
|
fallbackVersion,
|
||||||
|
process.env.GITHUB_TOKEN
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(core.warning).toHaveBeenCalledWith(
|
expect(warning).toHaveBeenCalledWith(
|
||||||
expect.stringContaining(`Version file ${versionFile} is empty`)
|
expect.stringContaining(`Version file ${versionFile} is empty`)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -135,9 +156,9 @@ describe('setup-tofu', () => {
|
|||||||
jest.spyOn(fs, 'readFile');
|
jest.spyOn(fs, 'readFile');
|
||||||
|
|
||||||
versionFileName = '.opentofu-version-file-does-not-exist';
|
versionFileName = '.opentofu-version-file-does-not-exist';
|
||||||
versionFile = path.join(tempDir, versionFileName);
|
versionFile = join(tempDir, versionFileName);
|
||||||
|
|
||||||
core.getInput.mockImplementation((name) => {
|
getInput.mockImplementation((name) => {
|
||||||
if (name === 'tofu_version_file') {
|
if (name === 'tofu_version_file') {
|
||||||
return versionFile;
|
return versionFile;
|
||||||
}
|
}
|
||||||
@@ -149,12 +170,15 @@ describe('setup-tofu', () => {
|
|||||||
|
|
||||||
await setup();
|
await setup();
|
||||||
|
|
||||||
expect(releases.getRelease).toHaveBeenCalledWith(
|
expect(getRelease).toHaveBeenCalledWith(
|
||||||
fallbackVersion, process.env.GITHUB_TOKEN
|
fallbackVersion,
|
||||||
|
process.env.GITHUB_TOKEN
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(core.warning).toHaveBeenCalledWith(
|
expect(warning).toHaveBeenCalledWith(
|
||||||
expect.stringContaining(`Failed to read version from file ${versionFile}`)
|
expect.stringContaining(
|
||||||
|
`Failed to read version from file ${versionFile}`
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(fs.readFile).toHaveBeenCalled();
|
expect(fs.readFile).toHaveBeenCalled();
|
||||||
@@ -163,7 +187,7 @@ describe('setup-tofu', () => {
|
|||||||
it('should not read file when tofu_version_file is not provided', async () => {
|
it('should not read file when tofu_version_file is not provided', async () => {
|
||||||
jest.spyOn(fs, 'readFile');
|
jest.spyOn(fs, 'readFile');
|
||||||
|
|
||||||
core.getInput.mockImplementation((name) => {
|
getInput.mockImplementation((name) => {
|
||||||
if (name === 'tofu_version') {
|
if (name === 'tofu_version') {
|
||||||
return fallbackVersion;
|
return fallbackVersion;
|
||||||
}
|
}
|
||||||
@@ -172,8 +196,9 @@ describe('setup-tofu', () => {
|
|||||||
|
|
||||||
await setup();
|
await setup();
|
||||||
|
|
||||||
expect(releases.getRelease).toHaveBeenCalledWith(
|
expect(getRelease).toHaveBeenCalledWith(
|
||||||
fallbackVersion, process.env.GITHUB_TOKEN
|
fallbackVersion,
|
||||||
|
process.env.GITHUB_TOKEN
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(fs.readFile).not.toHaveBeenCalled();
|
expect(fs.readFile).not.toHaveBeenCalled();
|
||||||
@@ -182,10 +207,9 @@ describe('setup-tofu', () => {
|
|||||||
|
|
||||||
describe('caching functionality', () => {
|
describe('caching functionality', () => {
|
||||||
it('should use cached version when cache is enabled and found', async () => {
|
it('should use cached version when cache is enabled and found', async () => {
|
||||||
const tc = require('@actions/tool-cache');
|
|
||||||
tc.find.mockReturnValue('/mock/cached/path');
|
tc.find.mockReturnValue('/mock/cached/path');
|
||||||
|
|
||||||
core.getInput.mockImplementation((name) => {
|
getInput.mockImplementation((name) => {
|
||||||
const defaults = {
|
const defaults = {
|
||||||
tofu_version: fallbackVersion,
|
tofu_version: fallbackVersion,
|
||||||
tofu_version_file: '',
|
tofu_version_file: '',
|
||||||
@@ -207,10 +231,9 @@ describe('setup-tofu', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should download and cache when cache is enabled but not found', async () => {
|
it('should download and cache when cache is enabled but not found', async () => {
|
||||||
const tc = require('@actions/tool-cache');
|
|
||||||
tc.find.mockReturnValue(null); // Cache miss
|
tc.find.mockReturnValue(null); // Cache miss
|
||||||
|
|
||||||
core.getInput.mockImplementation((name) => {
|
getInput.mockImplementation((name) => {
|
||||||
const defaults = {
|
const defaults = {
|
||||||
tofu_version: fallbackVersion,
|
tofu_version: fallbackVersion,
|
||||||
tofu_version_file: '',
|
tofu_version_file: '',
|
||||||
@@ -232,10 +255,9 @@ describe('setup-tofu', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not use cache when cache is disabled', async () => {
|
it('should not use cache when cache is disabled', async () => {
|
||||||
const tc = require('@actions/tool-cache');
|
|
||||||
tc.find.mockReturnValue('/mock/cached/path');
|
tc.find.mockReturnValue('/mock/cached/path');
|
||||||
|
|
||||||
core.getInput.mockImplementation((name) => {
|
getInput.mockImplementation((name) => {
|
||||||
const defaults = {
|
const defaults = {
|
||||||
tofu_version: fallbackVersion,
|
tofu_version: fallbackVersion,
|
||||||
tofu_version_file: '',
|
tofu_version_file: '',
|
||||||
|
|||||||
Generated
+7082
-7191
File diff suppressed because it is too large.
Load diff
+39
-37
@@ -1,39 +1,41 @@
|
|||||||
{
|
{
|
||||||
"name": "setup-opentofu",
|
"name": "setup-opentofu",
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"description": "Setup OpenTofu CLI for GitHub Actions",
|
"description": "Setup OpenTofu CLI for GitHub Actions",
|
||||||
"license": "MPL-2.0",
|
"type": "module",
|
||||||
"publisher": "OpenTofu",
|
"license": "MPL-2.0",
|
||||||
"main": "index.js",
|
"publisher": "OpenTofu",
|
||||||
"repository": {
|
"main": "index.js",
|
||||||
"type": "git",
|
"repository": {
|
||||||
"url": "https://github.com/opentofu/setup-opentofu.git"
|
"type": "git",
|
||||||
},
|
"url": "https://github.com/opentofu/setup-opentofu.git"
|
||||||
"scripts": {
|
},
|
||||||
"test": "semistandard --env jest && jest --coverage",
|
"scripts": {
|
||||||
"lint": "semistandard --env jest --fix",
|
"test": "semistandard --env jest && node --experimental-vm-modules ./node_modules/jest/bin/jest.js --coverage",
|
||||||
"build": "ncc build wrapper/tofu.js --out wrapper/dist && ncc build index.js --out dist",
|
"lint": "semistandard --env jest --fix",
|
||||||
"prepare": "husky install",
|
"build": "ncc build wrapper/tofu.js --out wrapper/dist && ncc build index.js --out dist",
|
||||||
"format-check": "echo \"unimplemented for actions/reusable-workflows basic-validation\""
|
"prepare": "husky install",
|
||||||
},
|
"format-check": "echo \"unimplemented for actions/reusable-workflows basic-validation\""
|
||||||
"keywords": [],
|
},
|
||||||
"author": "",
|
"keywords": [],
|
||||||
"dependencies": {
|
"author": "",
|
||||||
"@actions/core": "2.0.2",
|
"dependencies": {
|
||||||
"@actions/exec": "2.0.0",
|
"@actions/core": "^3.0.0",
|
||||||
"@actions/io": "2.0.0",
|
"@actions/exec": "^3.0.0",
|
||||||
"@actions/tool-cache": "2.0.2",
|
"@actions/http-client": "^4.0.0",
|
||||||
"semver": "7.7.3"
|
"@actions/io": "^3.0.2",
|
||||||
},
|
"@actions/tool-cache": "^4.0.0",
|
||||||
"devDependencies": {
|
"semver": "^7.7.4"
|
||||||
"@vercel/ncc": "0.38.4",
|
},
|
||||||
"husky": "9.1.7",
|
"devDependencies": {
|
||||||
"jest": "30.2.0",
|
"@vercel/ncc": "0.38.4",
|
||||||
"semistandard": "17.0.0"
|
"husky": "9.1.7",
|
||||||
},
|
"jest": "^30.3.0",
|
||||||
"semistandard": {
|
"semistandard": "17.0.0"
|
||||||
"ignore": [
|
},
|
||||||
"**/dist/**"
|
"semistandard": {
|
||||||
]
|
"ignore": [
|
||||||
}
|
"**/dist/**"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) HashiCorp, Inc.
|
* Copyright (c) HashiCorp, Inc.
|
||||||
|
* Copyright (c) OpenTofu
|
||||||
* SPDX-License-Identifier: MPL-2.0
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@
|
|||||||
* // Log out STDOUT contents
|
* // Log out STDOUT contents
|
||||||
* console.log(listener.contents);
|
* console.log(listener.contents);
|
||||||
*/
|
*/
|
||||||
class OutputListener {
|
export default class OutputListener {
|
||||||
constructor (stream) {
|
constructor (stream) {
|
||||||
this._buff = [];
|
this._buff = [];
|
||||||
this._stream = stream;
|
this._stream = stream;
|
||||||
@@ -35,10 +36,6 @@ class OutputListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get contents () {
|
get contents () {
|
||||||
return this._buff
|
return this._buff.map((chunk) => chunk.toString()).join('');
|
||||||
.map(chunk => chunk.toString())
|
|
||||||
.join('');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = OutputListener;
|
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) HashiCorp, Inc.
|
* Copyright (c) HashiCorp, Inc.
|
||||||
|
* Copyright (c) OpenTofu
|
||||||
* SPDX-License-Identifier: MPL-2.0
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const os = require('os');
|
import os from 'os';
|
||||||
const path = require('path');
|
import path from 'path';
|
||||||
|
|
||||||
module.exports = (() => {
|
const tofuBin = (() => {
|
||||||
// If we're on Windows, then the executable ends with .exe
|
// If we're on Windows, then the executable ends with .exe
|
||||||
const exeSuffix = os.platform().startsWith('win') ? '.exe' : '';
|
const exeSuffix = os.platform().startsWith('win') ? '.exe' : '';
|
||||||
|
|
||||||
return [process.env.TOFU_CLI_PATH, `tofu-bin${exeSuffix}`].join(path.sep);
|
return [process.env.TOFU_CLI_PATH, `tofu-bin${exeSuffix}`].join(path.sep);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
export default tofuBin;
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) HashiCorp, Inc.
|
* Copyright (c) HashiCorp, Inc.
|
||||||
|
* Copyright (c) OpenTofu
|
||||||
* SPDX-License-Identifier: MPL-2.0
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const OutputListener = require('../lib/output-listener');
|
import OutputListener from '../lib/output-listener.js';
|
||||||
const { PassThrough } = require('stream');
|
import { PassThrough } from 'stream';
|
||||||
|
|
||||||
describe('output-listener', () => {
|
describe('output-listener', () => {
|
||||||
it('receives and exposes data', () => {
|
it('receives and exposes data', () => {
|
||||||
const stream = new PassThrough();
|
const stream = new PassThrough();
|
||||||
|
|||||||
+11
-10
@@ -1,20 +1,21 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
/**
|
/**
|
||||||
* Copyright (c) HashiCorp, Inc.
|
* Copyright (c) HashiCorp, Inc.
|
||||||
|
* Copyright (c) OpenTofu
|
||||||
* SPDX-License-Identifier: MPL-2.0
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const io = require('@actions/io');
|
import { which } from '@actions/io';
|
||||||
const core = require('@actions/core');
|
import { setOutput, setFailed } from '@actions/core';
|
||||||
const { exec } = require('@actions/exec');
|
import { exec } from '@actions/exec';
|
||||||
|
|
||||||
const OutputListener = require('./lib/output-listener');
|
import OutputListener from './lib/output-listener.js';
|
||||||
const pathToCLI = require('./lib/tofu-bin');
|
import pathToCLI from './lib/tofu-bin.js';
|
||||||
|
|
||||||
async function checkTofu () {
|
async function checkTofu () {
|
||||||
// Setting check to `true` will cause `which` to throw if tofu isn't found
|
// Setting check to `true` will cause `which` to throw if tofu isn't found
|
||||||
const check = true;
|
const check = true;
|
||||||
return io.which(pathToCLI, check);
|
return which(pathToCLI, check);
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
@@ -39,9 +40,9 @@ async function checkTofu () {
|
|||||||
const exitCode = await exec(pathToCLI, args, options);
|
const exitCode = await exec(pathToCLI, args, options);
|
||||||
|
|
||||||
// Set outputs, result, exitcode, and stderr
|
// Set outputs, result, exitcode, and stderr
|
||||||
core.setOutput('stdout', stdout.contents);
|
setOutput('stdout', stdout.contents);
|
||||||
core.setOutput('stderr', stderr.contents);
|
setOutput('stderr', stderr.contents);
|
||||||
core.setOutput('exitcode', exitCode.toString(10));
|
setOutput('exitcode', exitCode.toString(10));
|
||||||
|
|
||||||
if (exitCode === 0 || exitCode === 2) {
|
if (exitCode === 0 || exitCode === 2) {
|
||||||
// A exitCode of 0 is considered a success
|
// A exitCode of 0 is considered a success
|
||||||
@@ -52,5 +53,5 @@ async function checkTofu () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A non-zero exitCode is considered an error
|
// A non-zero exitCode is considered an error
|
||||||
core.setFailed(`OpenTofu exited with code ${exitCode}.`);
|
setFailed(`OpenTofu exited with code ${exitCode}.`);
|
||||||
})();
|
})();
|
||||||
Reference in new issue
Block a user