Skip to content

Commit

Permalink
unify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Llandy3d committed Nov 21, 2024
1 parent 8178f88 commit 897325e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 58 deletions.
37 changes: 0 additions & 37 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,6 @@ jobs:
steps:
- uses: actions/checkout@v4

# get k6 binaries macos
- name: get latest k6 binary macos
if: startsWith(matrix.platform, 'macos-')
run: |
K6_PATH_AMD=k6-${{ vars.K6_VERSION }}-macos-amd64
K6_PATH_ARM=k6-${{ vars.K6_VERSION }}-macos-arm64
# download binaries
curl -LO https://github.com/grafana/k6/releases/download/${{ vars.K6_VERSION }}/$K6_PATH_AMD.zip
curl -LO https://github.com/grafana/k6/releases/download/${{ vars.K6_VERSION }}/$K6_PATH_ARM.zip
# unzip & smoke test
unzip $K6_PATH_AMD.zip
unzip $K6_PATH_ARM.zip
$K6_PATH_AMD/k6 version
$K6_PATH_ARM/k6 version
# move to resource folder
mv $K6_PATH_AMD/k6 resources/mac/x86_64
mv $K6_PATH_ARM/k6 resources/mac/arm64
# get k6 binaries windows
- name: get latest k6 binary windows
if: startsWith(matrix.platform, 'windows-')
run: |
$K6_PATH_AMD="k6-${{ vars.K6_VERSION }}-windows-amd64"
# download binaries
Invoke-WebRequest -Uri "https://github.com/grafana/k6/releases/download/${{ vars.K6_VERSION }}/$K6_PATH_AMD.zip" -OutFile "k6-windows-amd64.zip"
# unzip & smoke test
Expand-Archive -Path "k6-windows-amd64.zip" -DestinationPath "."
& $K6_PATH_AMD\k6.exe version
# move to resource folder
Move-Item -Path "$K6_PATH_AMD\k6.exe" -Destination resources\win\x86_64
- name: setup node
uses: actions/setup-node@v4
with:
Expand Down
30 changes: 9 additions & 21 deletions install-k6.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { exec } = require('child_process')
const { execSync } = require('child_process')
const { existsSync } = require('fs')

const K6_VERSION = 'v0.55.0'
Expand Down Expand Up @@ -33,7 +33,7 @@ rmdir ${K6_PATH_MAC_AMD}
rmdir ${K6_PATH_MAC_ARM}
`

executeCommand(command, {})
execSync(command)
}

const getWindowsK6Binary = () => {
Expand All @@ -47,39 +47,27 @@ ${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
`

executeCommand(command, { shell: 'powershell.exe' })
}
const executeCommand = (command, options) => {
exec(command, options, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`)
return
}

if (stderr) {
console.error(`stderr: ${stderr}`)
return
}
# clean up
del k6-windows-amd64.zip
Remove-Item -Path "${K6_PATH_WIN_AMD}" -Recurse
`

console.log(`stdout: ${stdout}`)
})
execSync(command, { shell: 'powershell.exe' })
}

switch (process.platform) {
case 'darwin':
// we check only for one arch since we include both binaries
if (!existsK6('mac', 'arm64')) {
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 (!existsK6('win', 'x86_64')) {
if (!existsSync('resources/win/x86_64/k6.exe')) {
console.log('k6 binary not found')
console.log('downloading k6... this might take some time...')
getWindowsK6Binary()
Expand Down

0 comments on commit 897325e

Please sign in to comment.