From 678377bd80075b8771c3940a5c24f63200fcfad1 Mon Sep 17 00:00:00 2001 From: Jonathan Camara Date: Wed, 27 Apr 2022 15:51:57 -0500 Subject: [PATCH 01/11] fix: make visible the path being extracted --- dist/index.js | 1 + lib/setup-terraform.js | 1 + 2 files changed, 2 insertions(+) diff --git a/dist/index.js b/dist/index.js index fe8a57fd..d24d4a3a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -37,6 +37,7 @@ function mapOS (os) { async function downloadCLI (url) { core.debug(`Downloading Terraform CLI from ${url}`); const pathToCLIZip = await tc.downloadTool(url); + core.info(`Terraform CLI Download Path is ${pathToCLIZip}`) core.debug('Extracting Terraform CLI zip file'); const pathToCLI = await tc.extractZip(pathToCLIZip); diff --git a/lib/setup-terraform.js b/lib/setup-terraform.js index 2f0b8bf6..fcb769c2 100644 --- a/lib/setup-terraform.js +++ b/lib/setup-terraform.js @@ -31,6 +31,7 @@ function mapOS (os) { async function downloadCLI (url) { core.debug(`Downloading Terraform CLI from ${url}`); const pathToCLIZip = await tc.downloadTool(url); + core.info(`Terraform CLI Download Path is ${pathToCLIZip}`) core.debug('Extracting Terraform CLI zip file'); const pathToCLI = await tc.extractZip(pathToCLIZip); From 135469c3f3111bacce5850aad56d6dc9eeb3b6b4 Mon Sep 17 00:00:00 2001 From: Jonathan Camara Date: Wed, 27 Apr 2022 16:03:29 -0500 Subject: [PATCH 02/11] fix: output files in download path --- dist/index.js | 11 +++++++++++ lib/setup-terraform.js | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/dist/index.js b/dist/index.js index d24d4a3a..a434a084 100644 --- a/dist/index.js +++ b/dist/index.js @@ -37,7 +37,18 @@ function mapOS (os) { async function downloadCLI (url) { core.debug(`Downloading Terraform CLI from ${url}`); const pathToCLIZip = await tc.downloadTool(url); + core.info(`Terraform CLI Download Path is ${pathToCLIZip}`) + const files = await readdir(path); + try { + const files = await fs.readdir(pathToCLIZip); + for (const file of files) + core.info(file); + + } catch (error) { + core.error(err); + throw err; + } core.debug('Extracting Terraform CLI zip file'); const pathToCLI = await tc.extractZip(pathToCLIZip); diff --git a/lib/setup-terraform.js b/lib/setup-terraform.js index fcb769c2..acdd6b48 100644 --- a/lib/setup-terraform.js +++ b/lib/setup-terraform.js @@ -31,7 +31,18 @@ function mapOS (os) { async function downloadCLI (url) { core.debug(`Downloading Terraform CLI from ${url}`); const pathToCLIZip = await tc.downloadTool(url); + core.info(`Terraform CLI Download Path is ${pathToCLIZip}`) + const files = await readdir(path); + try { + const files = await fs.readdir(pathToCLIZip); + for (const file of files) + core.info(file); + + } catch (error) { + core.error(err); + throw err; + } core.debug('Extracting Terraform CLI zip file'); const pathToCLI = await tc.extractZip(pathToCLIZip); From eb0d7e6261895649db824f7985baa40497ffca5a Mon Sep 17 00:00:00 2001 From: Jonathan Camara Date: Wed, 27 Apr 2022 16:05:16 -0500 Subject: [PATCH 03/11] fix: output files in download path --- dist/index.js | 1 - lib/setup-terraform.js | 1 - 2 files changed, 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index a434a084..8c5167c3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -39,7 +39,6 @@ async function downloadCLI (url) { const pathToCLIZip = await tc.downloadTool(url); core.info(`Terraform CLI Download Path is ${pathToCLIZip}`) - const files = await readdir(path); try { const files = await fs.readdir(pathToCLIZip); for (const file of files) diff --git a/lib/setup-terraform.js b/lib/setup-terraform.js index acdd6b48..5bfd2811 100644 --- a/lib/setup-terraform.js +++ b/lib/setup-terraform.js @@ -33,7 +33,6 @@ async function downloadCLI (url) { const pathToCLIZip = await tc.downloadTool(url); core.info(`Terraform CLI Download Path is ${pathToCLIZip}`) - const files = await readdir(path); try { const files = await fs.readdir(pathToCLIZip); for (const file of files) From 3ea2f56085d112c40100a7f86ee0358729c5c93e Mon Sep 17 00:00:00 2001 From: Jonathan Camara Date: Wed, 27 Apr 2022 16:07:48 -0500 Subject: [PATCH 04/11] fix: ensure using defined variable --- dist/index.js | 4 ++-- lib/setup-terraform.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8c5167c3..5058629c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -45,8 +45,8 @@ async function downloadCLI (url) { core.info(file); } catch (error) { - core.error(err); - throw err; + core.error(error); + throw error; } core.debug('Extracting Terraform CLI zip file'); diff --git a/lib/setup-terraform.js b/lib/setup-terraform.js index 5bfd2811..aecf9ecc 100644 --- a/lib/setup-terraform.js +++ b/lib/setup-terraform.js @@ -39,8 +39,8 @@ async function downloadCLI (url) { core.info(file); } catch (error) { - core.error(err); - throw err; + core.error(error); + throw error; } core.debug('Extracting Terraform CLI zip file'); From e5e4b2086fca0e97906a95ad511fd8cb3fb0545a Mon Sep 17 00:00:00 2001 From: Jonathan Camara Date: Wed, 27 Apr 2022 16:20:22 -0500 Subject: [PATCH 05/11] fix: see if adding the extension fixes the problem --- dist/index.js | 13 +++---------- lib/setup-terraform.js | 13 +++---------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/dist/index.js b/dist/index.js index 5058629c..3116cdb2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -39,18 +39,11 @@ async function downloadCLI (url) { const pathToCLIZip = await tc.downloadTool(url); core.info(`Terraform CLI Download Path is ${pathToCLIZip}`) - try { - const files = await fs.readdir(pathToCLIZip); - for (const file of files) - core.info(file); - - } catch (error) { - core.error(error); - throw error; - } + fixedPathToCLIZip=`${pathToCLIZip}.zip` + io.mv(pathToCLIZip,fixedPathToCLIZip) core.debug('Extracting Terraform CLI zip file'); - const pathToCLI = await tc.extractZip(pathToCLIZip); + const pathToCLI = await tc.extractZip(fixedPathToCLIZip); core.debug(`Terraform CLI path is ${pathToCLI}.`); if (!pathToCLIZip || !pathToCLI) { diff --git a/lib/setup-terraform.js b/lib/setup-terraform.js index aecf9ecc..5e5288ae 100644 --- a/lib/setup-terraform.js +++ b/lib/setup-terraform.js @@ -33,18 +33,11 @@ async function downloadCLI (url) { const pathToCLIZip = await tc.downloadTool(url); core.info(`Terraform CLI Download Path is ${pathToCLIZip}`) - try { - const files = await fs.readdir(pathToCLIZip); - for (const file of files) - core.info(file); - - } catch (error) { - core.error(error); - throw error; - } + fixedPathToCLIZip=`${pathToCLIZip}.zip` + io.mv(pathToCLIZip,fixedPathToCLIZip) core.debug('Extracting Terraform CLI zip file'); - const pathToCLI = await tc.extractZip(pathToCLIZip); + const pathToCLI = await tc.extractZip(fixedPathToCLIZip); core.debug(`Terraform CLI path is ${pathToCLI}.`); if (!pathToCLIZip || !pathToCLI) { From 62f144899ac380ba3ef932769ea0f7da8ab73fbe Mon Sep 17 00:00:00 2001 From: Jonathan Camara Date: Wed, 27 Apr 2022 16:26:36 -0500 Subject: [PATCH 06/11] fix: switch to check messages to debug --- dist/index.js | 3 ++- lib/setup-terraform.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3116cdb2..ab6708aa 100644 --- a/dist/index.js +++ b/dist/index.js @@ -38,9 +38,10 @@ async function downloadCLI (url) { core.debug(`Downloading Terraform CLI from ${url}`); const pathToCLIZip = await tc.downloadTool(url); - core.info(`Terraform CLI Download Path is ${pathToCLIZip}`) + core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`) fixedPathToCLIZip=`${pathToCLIZip}.zip` io.mv(pathToCLIZip,fixedPathToCLIZip) + core.debug(`Moved download to ${fixedPathToCLIZip}`) core.debug('Extracting Terraform CLI zip file'); const pathToCLI = await tc.extractZip(fixedPathToCLIZip); diff --git a/lib/setup-terraform.js b/lib/setup-terraform.js index 5e5288ae..c4a080f9 100644 --- a/lib/setup-terraform.js +++ b/lib/setup-terraform.js @@ -32,9 +32,10 @@ async function downloadCLI (url) { core.debug(`Downloading Terraform CLI from ${url}`); const pathToCLIZip = await tc.downloadTool(url); - core.info(`Terraform CLI Download Path is ${pathToCLIZip}`) + core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`) fixedPathToCLIZip=`${pathToCLIZip}.zip` io.mv(pathToCLIZip,fixedPathToCLIZip) + core.debug(`Moved download to ${fixedPathToCLIZip}`) core.debug('Extracting Terraform CLI zip file'); const pathToCLI = await tc.extractZip(fixedPathToCLIZip); From 07c30f59da93270ba280c6f309fae69d53271ab2 Mon Sep 17 00:00:00 2001 From: Jonathan Camara Date: Wed, 27 Apr 2022 16:32:54 -0500 Subject: [PATCH 07/11] fix: only change file extension of we are on Windows --- dist/index.js | 16 +++++++++++----- lib/setup-terraform.js | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index ab6708aa..f0fa4deb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -38,13 +38,19 @@ async function downloadCLI (url) { core.debug(`Downloading Terraform CLI from ${url}`); const pathToCLIZip = await tc.downloadTool(url); - core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`) - fixedPathToCLIZip=`${pathToCLIZip}.zip` - io.mv(pathToCLIZip,fixedPathToCLIZip) - core.debug(`Moved download to ${fixedPathToCLIZip}`) + const pathToCLI = ""; + + if (os.platform().startsWith('win')) { + core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`) + fixedPathToCLIZip = `${pathToCLIZip}.zip` + io.mv(pathToCLIZip, fixedPathToCLIZip) + core.debug(`Moved download to ${fixedPathToCLIZip}`) + pathToCLI = await tc.extractZip(fixedPathToCLIZip); + } else { + pathToCLI = await tc.extractZip(pathToCLIZip); + } core.debug('Extracting Terraform CLI zip file'); - const pathToCLI = await tc.extractZip(fixedPathToCLIZip); core.debug(`Terraform CLI path is ${pathToCLI}.`); if (!pathToCLIZip || !pathToCLI) { diff --git a/lib/setup-terraform.js b/lib/setup-terraform.js index c4a080f9..e743f3f5 100644 --- a/lib/setup-terraform.js +++ b/lib/setup-terraform.js @@ -32,13 +32,19 @@ async function downloadCLI (url) { core.debug(`Downloading Terraform CLI from ${url}`); const pathToCLIZip = await tc.downloadTool(url); - core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`) - fixedPathToCLIZip=`${pathToCLIZip}.zip` - io.mv(pathToCLIZip,fixedPathToCLIZip) - core.debug(`Moved download to ${fixedPathToCLIZip}`) + const pathToCLI = ""; + + if (os.platform().startsWith('win')) { + core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`) + fixedPathToCLIZip = `${pathToCLIZip}.zip` + io.mv(pathToCLIZip, fixedPathToCLIZip) + core.debug(`Moved download to ${fixedPathToCLIZip}`) + pathToCLI = await tc.extractZip(fixedPathToCLIZip); + } else { + pathToCLI = await tc.extractZip(pathToCLIZip); + } core.debug('Extracting Terraform CLI zip file'); - const pathToCLI = await tc.extractZip(fixedPathToCLIZip); core.debug(`Terraform CLI path is ${pathToCLI}.`); if (!pathToCLIZip || !pathToCLI) { From 155af1502d57703fa530a39cab30c796c7607a69 Mon Sep 17 00:00:00 2001 From: Jonathan Camara Date: Thu, 28 Apr 2022 08:01:34 -0500 Subject: [PATCH 08/11] fix: use a mutable variable for setting the CLI path --- dist/index.js | 2 +- lib/setup-terraform.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index f0fa4deb..cdf630c3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -38,7 +38,7 @@ async function downloadCLI (url) { core.debug(`Downloading Terraform CLI from ${url}`); const pathToCLIZip = await tc.downloadTool(url); - const pathToCLI = ""; + let pathToCLI = ""; if (os.platform().startsWith('win')) { core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`) diff --git a/lib/setup-terraform.js b/lib/setup-terraform.js index e743f3f5..8676f61e 100644 --- a/lib/setup-terraform.js +++ b/lib/setup-terraform.js @@ -32,7 +32,7 @@ async function downloadCLI (url) { core.debug(`Downloading Terraform CLI from ${url}`); const pathToCLIZip = await tc.downloadTool(url); - const pathToCLI = ""; + let pathToCLI = ""; if (os.platform().startsWith('win')) { core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`) From 50cae4776622f9cb2f6024783577bef792c2ddbb Mon Sep 17 00:00:00 2001 From: Jonathan Camara Date: Thu, 28 Apr 2022 14:18:08 -0500 Subject: [PATCH 09/11] style: fix semistandard lint errors --- dist/index.js | 10 +++++----- lib/setup-terraform.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index cdf630c3..e5017542 100644 --- a/dist/index.js +++ b/dist/index.js @@ -38,13 +38,13 @@ async function downloadCLI (url) { core.debug(`Downloading Terraform CLI from ${url}`); const pathToCLIZip = await tc.downloadTool(url); - let pathToCLI = ""; + let pathToCLI = ''; if (os.platform().startsWith('win')) { - core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`) - fixedPathToCLIZip = `${pathToCLIZip}.zip` - io.mv(pathToCLIZip, fixedPathToCLIZip) - core.debug(`Moved download to ${fixedPathToCLIZip}`) + core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`); + const fixedPathToCLIZip = `${pathToCLIZip}.zip`; + io.mv(pathToCLIZip, fixedPathToCLIZip); + core.debug(`Moved download to ${fixedPathToCLIZip}`); pathToCLI = await tc.extractZip(fixedPathToCLIZip); } else { pathToCLI = await tc.extractZip(pathToCLIZip); diff --git a/lib/setup-terraform.js b/lib/setup-terraform.js index 8676f61e..ef0a8fbb 100644 --- a/lib/setup-terraform.js +++ b/lib/setup-terraform.js @@ -32,13 +32,13 @@ async function downloadCLI (url) { core.debug(`Downloading Terraform CLI from ${url}`); const pathToCLIZip = await tc.downloadTool(url); - let pathToCLI = ""; + let pathToCLI = ''; if (os.platform().startsWith('win')) { - core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`) - fixedPathToCLIZip = `${pathToCLIZip}.zip` - io.mv(pathToCLIZip, fixedPathToCLIZip) - core.debug(`Moved download to ${fixedPathToCLIZip}`) + core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`); + const fixedPathToCLIZip = `${pathToCLIZip}.zip`; + io.mv(pathToCLIZip, fixedPathToCLIZip); + core.debug(`Moved download to ${fixedPathToCLIZip}`); pathToCLI = await tc.extractZip(fixedPathToCLIZip); } else { pathToCLI = await tc.extractZip(pathToCLIZip); From 1a3ca02724c999903bad6e0569f411fa4241c67a Mon Sep 17 00:00:00 2001 From: Jonathan Camara Date: Fri, 29 Apr 2022 12:07:49 -0500 Subject: [PATCH 10/11] fix: move extraction debug statement to more sensible location --- dist/index.js | 2 +- lib/setup-terraform.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index e5017542..283f8139 100644 --- a/dist/index.js +++ b/dist/index.js @@ -40,6 +40,7 @@ async function downloadCLI (url) { let pathToCLI = ''; + core.debug('Extracting Terraform CLI zip file'); if (os.platform().startsWith('win')) { core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`); const fixedPathToCLIZip = `${pathToCLIZip}.zip`; @@ -50,7 +51,6 @@ async function downloadCLI (url) { pathToCLI = await tc.extractZip(pathToCLIZip); } - core.debug('Extracting Terraform CLI zip file'); core.debug(`Terraform CLI path is ${pathToCLI}.`); if (!pathToCLIZip || !pathToCLI) { diff --git a/lib/setup-terraform.js b/lib/setup-terraform.js index ef0a8fbb..1e61d2c5 100644 --- a/lib/setup-terraform.js +++ b/lib/setup-terraform.js @@ -34,6 +34,7 @@ async function downloadCLI (url) { let pathToCLI = ''; + core.debug('Extracting Terraform CLI zip file'); if (os.platform().startsWith('win')) { core.debug(`Terraform CLI Download Path is ${pathToCLIZip}`); const fixedPathToCLIZip = `${pathToCLIZip}.zip`; @@ -44,7 +45,6 @@ async function downloadCLI (url) { pathToCLI = await tc.extractZip(pathToCLIZip); } - core.debug('Extracting Terraform CLI zip file'); core.debug(`Terraform CLI path is ${pathToCLI}.`); if (!pathToCLIZip || !pathToCLI) { From aff1a4ef8f4bb4e21ca59cfde878052176178305 Mon Sep 17 00:00:00 2001 From: Jonathan Camara Date: Fri, 29 Apr 2022 12:28:53 -0500 Subject: [PATCH 11/11] test: mock function changing the filesystem --- test/setup-terraform.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/setup-terraform.test.js b/test/setup-terraform.test.js index fa2fd337..367de90b 100644 --- a/test/setup-terraform.test.js +++ b/test/setup-terraform.test.js @@ -94,6 +94,8 @@ describe('Setup Terraform', () => { .fn() .mockReturnValueOnce('file.zip'); + io.mv = jest.fn(); + tc.extractZip = jest .fn() .mockReturnValueOnce('file');