Skip to content

Commit

Permalink
Fix terraform extract (#187)
Browse files Browse the repository at this point in the history
On Windows runners, extracting the downloaded CLI zip file was failing because the file didn't have a .zip extension. This commit attempts to solve the problem by adding the extension to the downloaded file before extraction.
  • Loading branch information
cpc-camarj committed May 9, 2022
1 parent 8b4c280 commit 8aaee7f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
13 changes: 12 additions & 1 deletion dist/index.js
Expand Up @@ -38,8 +38,19 @@ async function downloadCLI (url) {
core.debug(`Downloading Terraform CLI from ${url}`);
const pathToCLIZip = await tc.downloadTool(url);

let pathToCLI = '';

core.debug('Extracting Terraform CLI zip file');
const pathToCLI = await tc.extractZip(pathToCLIZip);
if (os.platform().startsWith('win')) {
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);
}

core.debug(`Terraform CLI path is ${pathToCLI}.`);

if (!pathToCLIZip || !pathToCLI) {
Expand Down
13 changes: 12 additions & 1 deletion lib/setup-terraform.js
Expand Up @@ -32,8 +32,19 @@ async function downloadCLI (url) {
core.debug(`Downloading Terraform CLI from ${url}`);
const pathToCLIZip = await tc.downloadTool(url);

let pathToCLI = '';

core.debug('Extracting Terraform CLI zip file');
const pathToCLI = await tc.extractZip(pathToCLIZip);
if (os.platform().startsWith('win')) {
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);
}

core.debug(`Terraform CLI path is ${pathToCLI}.`);

if (!pathToCLIZip || !pathToCLI) {
Expand Down
2 changes: 2 additions & 0 deletions test/setup-terraform.test.js
Expand Up @@ -94,6 +94,8 @@ describe('Setup Terraform', () => {
.fn()
.mockReturnValueOnce('file.zip');

io.mv = jest.fn();

tc.extractZip = jest
.fn()
.mockReturnValueOnce('file');
Expand Down

0 comments on commit 8aaee7f

Please sign in to comment.