-
Notifications
You must be signed in to change notification settings - Fork 2
/
install-k6.js
75 lines (63 loc) · 2.18 KB
/
install-k6.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const { execSync } = require('child_process')
const { existsSync } = require('fs')
const K6_VERSION = 'v0.55.0'
const K6_PATH_MAC_AMD = `k6-${K6_VERSION}-macos-amd64`
const K6_PATH_MAC_ARM = `k6-${K6_VERSION}-macos-arm64`
const K6_PATH_WIN_AMD = `k6-${K6_VERSION}-windows-amd64`
const getMacOSK6Binary = () => {
const command = `
# download binaries
curl -LO https://github.com/grafana/k6/releases/download/${K6_VERSION}/${K6_PATH_MAC_AMD}.zip
curl -LO https://github.com/grafana/k6/releases/download/${K6_VERSION}/${K6_PATH_MAC_ARM}.zip
# unzip & smoke test
unzip ${K6_PATH_MAC_AMD}.zip
unzip ${K6_PATH_MAC_ARM}.zip
${K6_PATH_MAC_AMD}/k6 version
${K6_PATH_MAC_ARM}/k6 version
# move to resource folder
mv ${K6_PATH_MAC_AMD}/k6 resources/mac/x86_64
mv ${K6_PATH_MAC_ARM}/k6 resources/mac/arm64
# cleanup
rm ${K6_PATH_MAC_AMD}.zip
rm ${K6_PATH_MAC_ARM}.zip
rmdir ${K6_PATH_MAC_AMD}
rmdir ${K6_PATH_MAC_ARM}
`
execSync(command)
}
const getWindowsK6Binary = () => {
const command = `
# download binaries
Invoke-WebRequest -Uri "https://github.com/grafana/k6/releases/download/${K6_VERSION}/${K6_PATH_WIN_AMD}.zip" -OutFile "k6-windows-amd64.zip"
# unzip & smoke test
Expand-Archive -Path "k6-windows-amd64.zip" -DestinationPath "."
${K6_PATH_WIN_AMD}\\k6.exe version
# move to resource folder
Move-Item -Path "${K6_PATH_WIN_AMD}\\k6.exe" -Destination resources\\win\\x86_64
# clean up
del k6-windows-amd64.zip
Remove-Item -Path "${K6_PATH_WIN_AMD}" -Recurse
`
execSync(command, { shell: 'powershell.exe' })
}
switch (process.platform) {
case 'darwin':
// we check only for one arch since we include both binaries
if (!existsSync('resources/mac/arm64/k6')) {
console.log('k6 binary not found')
console.log('downloading k6... this might take some time...')
getMacOSK6Binary()
console.log('k6 binary download completed')
}
break
case 'win32':
if (!existsSync('resources/win/x86_64/k6.exe')) {
console.log('k6 binary not found')
console.log('downloading k6... this might take some time...')
getWindowsK6Binary()
console.log('k6 binary download completed')
}
break
default:
console.log(`unsupported platform found: ${process.platform}`)
}