chore: refactors downloadCLI

see:
-https://github.com/opentofu/setup-opentofu/pull/2#discussion_r1356503597
- https://github.com/opentofu/setup-opentofu/pull/2#discussion_r1356504741

Signed-off-by: Dmitry Kisler <admin@dkisler.com>
This commit is contained in:
Dmitry Kisler 2023-10-12 17:46:15 +02:00
parent ff4f92709b
commit 6196ddd9f5
No known key found for this signature in database
GPG key ID: 46C0A987D58548F6
2 changed files with 18 additions and 10 deletions

14
dist/index.js vendored
View file

@ -145,11 +145,15 @@ function mapOS (os) {
return os; return os;
} }
async function downloadCLI (url) { async function downloadAndExtractCLI (url) {
core.debug(`Downloading OpenTofu CLI from ${url}`); core.debug(`Downloading OpenTofu CLI from ${url}`);
const pathToCLIZip = await tc.downloadTool(url); const pathToCLIZip = await tc.downloadTool(url);
let pathToCLI = ''; if (!pathToCLIZip) {
throw new Error(`Unable to download OpenTofu from ${url}`);
}
let pathToCLI;
core.debug('Extracting OpenTofu CLI zip file'); core.debug('Extracting OpenTofu CLI zip file');
if (os.platform().startsWith('win')) { if (os.platform().startsWith('win')) {
@ -164,8 +168,8 @@ async function downloadCLI (url) {
core.debug(`OpenTofu CLI path is ${pathToCLI}.`); core.debug(`OpenTofu CLI path is ${pathToCLI}.`);
if (!pathToCLIZip || !pathToCLI) { if (!pathToCLI) {
throw new Error(`Unable to download OpenTofu from ${url}`); throw new Error('Unable to unzip OpenTofu');
} }
return pathToCLI; return pathToCLI;
@ -254,7 +258,7 @@ async function run () {
} }
// Download requested version // Download requested version
const pathToCLI = await downloadCLI(build.url); const pathToCLI = await downloadAndExtractCLI(build.url);
// Install our wrapper // Install our wrapper
if (wrapper) { if (wrapper) {

View file

@ -34,11 +34,15 @@ function mapOS (os) {
return os; return os;
} }
async function downloadCLI (url) { async function downloadAndExtractCLI (url) {
core.debug(`Downloading OpenTofu CLI from ${url}`); core.debug(`Downloading OpenTofu CLI from ${url}`);
const pathToCLIZip = await tc.downloadTool(url); const pathToCLIZip = await tc.downloadTool(url);
let pathToCLI = ''; if (!pathToCLIZip) {
throw new Error(`Unable to download OpenTofu from ${url}`);
}
let pathToCLI;
core.debug('Extracting OpenTofu CLI zip file'); core.debug('Extracting OpenTofu CLI zip file');
if (os.platform().startsWith('win')) { if (os.platform().startsWith('win')) {
@ -53,8 +57,8 @@ async function downloadCLI (url) {
core.debug(`OpenTofu CLI path is ${pathToCLI}.`); core.debug(`OpenTofu CLI path is ${pathToCLI}.`);
if (!pathToCLIZip || !pathToCLI) { if (!pathToCLI) {
throw new Error(`Unable to download OpenTofu from ${url}`); throw new Error('Unable to unzip OpenTofu');
} }
return pathToCLI; return pathToCLI;
@ -143,7 +147,7 @@ async function run () {
} }
// Download requested version // Download requested version
const pathToCLI = await downloadCLI(build.url); const pathToCLI = await downloadAndExtractCLI(build.url);
// Install our wrapper // Install our wrapper
if (wrapper) { if (wrapper) {