Skip to content

Commit 57fba30

Browse files
committed
feat(tool): leave version empty for latest
1 parent 88eb5f0 commit 57fba30

File tree

6 files changed

+317
-37
lines changed

6 files changed

+317
-37
lines changed

PackerTool/package-lock.json

+250
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PackerTool/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
"author": "Manuel Riezebosch",
1818
"license": "ISC",
1919
"dependencies": {
20+
"axios": "^0.19.1",
21+
"node-fetch": "^2.6.0",
2022
"vsts-task-tool-lib": "^0.9.0"
2123
},
2224
"devDependencies": {
2325
"@types/mocha": "^5.2.4",
26+
"@types/node-fetch": "^2.5.4",
2427
"chai": "^4.1.2",
2528
"mocha": "^5.2.0",
2629
"typescript": "^2.9.2"

PackerTool/src/packertool.ts

+30-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as taskLib from 'vsts-task-lib/task';
22
import * as toolLib from 'vsts-task-tool-lib/tool';
33
import * as os from 'os';
4+
import * as fetch from 'node-fetch';
45

56
async function run() {
67
try {
7-
let version = taskLib.getInput('version', true);
8+
let version = taskLib.getInput('version', false) || await getVersion();
89
await getNode(version);
910
}
1011
catch (error) {
@@ -25,24 +26,42 @@ async function acquireNode(version: string): Promise<string> {
2526
version = toolLib.cleanVersion(version);
2627
let downloadUrl = downloadLink(version, os.platform(), os.arch())
2728

28-
let downloadPath = await toolLib.downloadTool(downloadUrl);
29+
let downloadPath = await toolLib.downloadTool(await downloadUrl);
2930
let extPath: string = await toolLib.extractZip(downloadPath);
3031

3132
return await toolLib.cacheDir(extPath, 'packer', version);
3233
}
3334

3435
run();
3536

36-
export default function downloadLink(version: string, os: string, arch: string): string {
37-
if (os == 'win32') {
38-
os = 'windows';
39-
}
37+
export async function downloadLink(version: string, os: string, arch: string): Promise<string> {
38+
os = getOs(os);
39+
arch = getArch(arch);
40+
41+
return `https://releases.hashicorp.com/packer/${version}/packer_${version}_${os}_${arch}.zip`;
42+
}
4043

44+
function getArch(arch: string) {
4145
if (arch == 'x32' || arch == 'ia32') {
42-
arch = '386';
43-
} else if (arch == 'x64') {
44-
arch = 'amd64';
46+
return '386';
47+
}
48+
49+
if (arch == 'x64') {
50+
return 'amd64';
4551
}
4652

47-
return `https://releases.hashicorp.com/packer/${version}/packer_${version}_${os}_${arch}.zip`;
48-
}
53+
return arch;
54+
}
55+
56+
function getOs(os: string) {
57+
if (os == 'win32') {
58+
return 'windows';
59+
}
60+
61+
return os;
62+
}
63+
64+
export async function getVersion(): Promise<string> {
65+
const res = await fetch.default('https://checkpoint-api.hashicorp.com/v1/check/packer');
66+
return (await res.json()).current_version;
67+
}

0 commit comments

Comments
 (0)