mirror of
https://github.com/hashicorp/setup-terraform.git
synced 2025-12-17 08:52:37 +00:00
utilize .tool-versions file to resolve terraform version
This commit is contained in:
parent
1fdd4cd311
commit
5de63cedb5
4 changed files with 158 additions and 5 deletions
|
|
@ -176,6 +176,46 @@
|
|||
"url": "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_windows_386.zip"
|
||||
}
|
||||
]
|
||||
},
|
||||
"1.3.7": {
|
||||
"name": "terraform",
|
||||
"version": "1.3.7",
|
||||
"shasums": "terraform_1.3.7_SHA256SUMS",
|
||||
"shasums_signature": "terraform_1.3.7_SHA256SUMS.sig",
|
||||
"builds": [
|
||||
{
|
||||
"name": "terraform",
|
||||
"version": "1.3.7",
|
||||
"os": "darwin",
|
||||
"arch": "amd64",
|
||||
"filename": "terraform_1.3.7_darwin_amd64.zip",
|
||||
"url": "https://releases.hashicorp.com/terraform/1.3.7/terraform_1.3.7_darwin_amd64.zip"
|
||||
},
|
||||
{
|
||||
"name": "terraform",
|
||||
"version": "1.3.7",
|
||||
"os": "linux",
|
||||
"arch": "386",
|
||||
"filename": "terraform_1.3.7_linux_386.zip",
|
||||
"url": "https://releases.hashicorp.com/terraform/1.3.7/terraform_1.3.7_linux_386.zip"
|
||||
},
|
||||
{
|
||||
"name": "terraform",
|
||||
"version": "1.3.7",
|
||||
"os": "linux",
|
||||
"arch": "amd64",
|
||||
"filename": "terraform_1.3.7_linux_amd64.zip",
|
||||
"url": "https://releases.hashicorp.com/terraform/1.3.7/terraform_1.3.7_linux_amd64.zip"
|
||||
},
|
||||
{
|
||||
"name": "terraform",
|
||||
"version": "1.3.7",
|
||||
"os": "windows",
|
||||
"arch": "386",
|
||||
"filename": "terraform_1.3.7_windows_386.zip",
|
||||
"url": "https://releases.hashicorp.com/terraform/1.3.7/terraform_1.3.7_windows_386.zip"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ describe('Setup Terraform', () => {
|
|||
.reply(200, json);
|
||||
|
||||
const versionObj = await setup();
|
||||
expect(versionObj.version).toEqual('0.10.0');
|
||||
expect(versionObj.version).toEqual('1.3.7');
|
||||
|
||||
// downloaded CLI has been added to path
|
||||
expect(core.addPath).toHaveBeenCalled();
|
||||
|
|
@ -420,6 +420,59 @@ describe('Setup Terraform', () => {
|
|||
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||
});
|
||||
|
||||
test('gets version from .tool-versions when version not provided', async () => {
|
||||
const credentialsHostname = 'app.terraform.io';
|
||||
const credentialsToken = 'asdfjkl';
|
||||
|
||||
fs.existsSync = jest
|
||||
.fn()
|
||||
.mockReturnValueOnce(true);
|
||||
|
||||
fs.readFileSync = jest
|
||||
.fn()
|
||||
.mockReturnValueOnce(`terraform 1.3.7
|
||||
golang 1.16.3
|
||||
python 3.10.11
|
||||
ruby 3.2.1
|
||||
`);
|
||||
|
||||
core.getInput = jest
|
||||
.fn()
|
||||
.mockReturnValueOnce(null)
|
||||
.mockReturnValueOnce(credentialsHostname)
|
||||
.mockReturnValueOnce(credentialsToken);
|
||||
|
||||
tc.downloadTool = jest
|
||||
.fn()
|
||||
.mockReturnValueOnce('file.zip');
|
||||
|
||||
tc.extractZip = jest
|
||||
.fn()
|
||||
.mockReturnValueOnce('file');
|
||||
|
||||
os.platform = jest
|
||||
.fn()
|
||||
.mockReturnValue('linux');
|
||||
|
||||
os.arch = jest
|
||||
.fn()
|
||||
.mockReturnValue('amd64');
|
||||
|
||||
nock('https://releases.hashicorp.com')
|
||||
.get('/terraform/index.json')
|
||||
.reply(200, json);
|
||||
|
||||
const versionObj = await setup();
|
||||
expect(versionObj.version).toEqual('1.3.7');
|
||||
|
||||
// downloaded CLI has been added to path
|
||||
expect(core.addPath).toHaveBeenCalled();
|
||||
// expect credentials are in ${HOME}.terraformrc
|
||||
const creds = await fs.readFile(`${process.env.HOME}/.terraformrc`, { encoding: 'utf8' });
|
||||
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
||||
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||
});
|
||||
|
||||
test('fails when metadata cannot be downloaded', async () => {
|
||||
const version = 'latest';
|
||||
const credentialsHostname = 'app.terraform.io';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue