Skip to content

Commit

Permalink
Merge pull request #469 from spowelljr/useProperArch
Browse files Browse the repository at this point in the history
Download binary based on machine arch
  • Loading branch information
medyagh authored Jun 13, 2024
2 parents 6cb1078 + 9e2bb81 commit 9ed194e
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 61 deletions.
234 changes: 180 additions & 54 deletions __tests__/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,188 @@ import {getDownloadURL} from '../src/download'
jest.mock('os')
const mockedOS = jest.mocked(os)

test('getDownloadURL Unix latest', () => {
mockedOS.platform.mockReturnValue('linux')

const url = getDownloadURL('latest')

expect(url).toBe(
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64'
)
})

test('getDownloadURL Windows latest', () => {
mockedOS.platform.mockReturnValue('win32')

const url = getDownloadURL('latest')

expect(url).toBe(
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-windows-amd64.exe'
)
})

test('getDownloadURL Unix head', () => {
mockedOS.platform.mockReturnValue('linux')

const url = getDownloadURL('head')

expect(url).toBe(
'https://storage.googleapis.com/minikube-builds/master/minikube-linux-amd64'
)
test('getDownloadURL Linux', () => {
const tests = [
{
arch: 'x64',
version: 'latest',
expected:
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64',
},
{
arch: 'arm64',
version: 'latest',
expected:
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-arm64',
},
{
arch: 'arm',
version: 'latest',
expected:
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-arm',
},
{
arch: 's390x',
version: 'latest',
expected:
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-s390x',
},
{
arch: 'ppc64',
version: 'latest',
expected:
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-ppc64le',
},
{
arch: 'x64',
version: 'head',
expected:
'https://storage.googleapis.com/minikube-builds/master/minikube-linux-amd64',
},
{
arch: 'arm64',
version: 'head',
expected:
'https://storage.googleapis.com/minikube-builds/master/minikube-linux-arm64',
},
{
arch: 'arm',
version: 'head',
expected:
'https://storage.googleapis.com/minikube-builds/master/minikube-linux-arm',
},
{
arch: 's390x',
version: 'head',
expected:
'https://storage.googleapis.com/minikube-builds/master/minikube-linux-s390x',
},
{
arch: 'ppc64',
version: 'head',
expected:
'https://storage.googleapis.com/minikube-builds/master/minikube-linux-ppc64le',
},
{
arch: 'x64',
version: '1.28.0',
expected:
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-linux-amd64',
},
{
arch: 'arm64',
version: '1.28.0',
expected:
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-linux-arm64',
},
{
arch: 'arm',
version: '1.28.0',
expected:
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-linux-arm',
},
{
arch: 's390x',
version: '1.28.0',
expected:
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-linux-s390x',
},
{
arch: 'ppc64',
version: '1.28.0',
expected:
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-linux-ppc64le',
},
]

for (const tc of tests) {
mockedOS.arch.mockReturnValue(tc.arch)
mockedOS.platform.mockReturnValue('linux')

const url = getDownloadURL(tc.version)

expect(url).toBe(tc.expected)
}
})

test('getDownloadURL Windows head', () => {
mockedOS.platform.mockReturnValue('win32')

const url = getDownloadURL('head')

expect(url).toBe(
'https://storage.googleapis.com/minikube-builds/master/minikube-windows-amd64.exe'
)
test('getDownloadURL macOS', () => {
const tests = [
{
arch: 'x64',
version: 'latest',
expected:
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-darwin-amd64',
},
{
arch: 'arm64',
version: 'latest',
expected:
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-darwin-arm64',
},
{
arch: 'x64',
version: 'head',
expected:
'https://storage.googleapis.com/minikube-builds/master/minikube-darwin-amd64',
},
{
arch: 'arm64',
version: 'head',
expected:
'https://storage.googleapis.com/minikube-builds/master/minikube-darwin-arm64',
},
{
arch: 'x64',
version: '1.28.0',
expected:
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-darwin-amd64',
},
{
arch: 'arm64',
version: '1.28.0',
expected:
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-darwin-arm64',
},
]

for (const tc of tests) {
mockedOS.arch.mockReturnValue(tc.arch)
mockedOS.platform.mockReturnValue('darwin')

const url = getDownloadURL(tc.version)

expect(url).toBe(tc.expected)
}
})

test('getDownloadURL Unix version', () => {
mockedOS.platform.mockReturnValue('linux')

const url = getDownloadURL('1.28.0')

expect(url).toBe(
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-linux-amd64'
)
})

test('getDownloadURL Windows version', () => {
mockedOS.platform.mockReturnValue('win32')

const url = getDownloadURL('1.28.0')

expect(url).toBe(
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-windows-amd64.exe'
)
test('getDownloadURL Windows', () => {
const tests = [
{
arch: 'x64',
version: 'latest',
expected:
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-windows-amd64.exe',
},
{
arch: 'x64',
version: 'head',
expected:
'https://storage.googleapis.com/minikube-builds/master/minikube-windows-amd64.exe',
},
{
arch: 'x64',
version: '1.28.0',
expected:
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-windows-amd64.exe',
},
]

for (const tc of tests) {
mockedOS.arch.mockReturnValue(tc.arch)
mockedOS.platform.mockReturnValue('win32')

const url = getDownloadURL(tc.version)

expect(url).toBe(tc.expected)
}
})
28 changes: 25 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,40 @@ const os_1 = __nccwpck_require__(2037);
const path_1 = __nccwpck_require__(1017);
const getDownloadURL = (version) => {
const osPlat = (0, os_1.platform)();
const osArch = getMinikubeArch();
const platform = osPlat === 'win32' ? 'windows' : osPlat;
const suffix = osPlat === 'win32' ? '.exe' : '';
switch (version) {
case 'latest':
return `https://github.com/kubernetes/minikube/releases/latest/download/minikube-${platform}-amd64${suffix}`;
return `https://github.com/kubernetes/minikube/releases/latest/download/minikube-${platform}-${osArch}${suffix}`;
case 'head':
return `https://storage.googleapis.com/minikube-builds/master/minikube-${platform}-amd64${suffix}`;
return `https://storage.googleapis.com/minikube-builds/master/minikube-${platform}-${osArch}${suffix}`;
default:
return `https://github.com/kubernetes/minikube/releases/download/v${version}/minikube-${platform}-amd64${suffix}`;
return `https://github.com/kubernetes/minikube/releases/download/v${version}/minikube-${platform}-${osArch}${suffix}`;
}
};
exports.getDownloadURL = getDownloadURL;
const getMinikubeArch = () => {
switch ((0, os_1.arch)()) {
case 'x64':
return 'amd64';
break;
case 'arm64':
return 'arm64';
break;
case 'arm':
return 'arm';
break;
case 's390x':
return 's390x';
break;
case 'ppc64':
return 'ppc64le';
break;
default:
throw new Error(`Machine is of arch ${(0, os_1.arch)()}, which isn't supported by minikube.`);
}
};
const downloadMinikube = (version, installPath) => __awaiter(void 0, void 0, void 0, function* () {
const url = (0, exports.getDownloadURL)(version);
const downloadPath = yield (0, tool_cache_1.downloadTool)(url);
Expand Down
33 changes: 29 additions & 4 deletions src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,45 @@ import {addPath} from '@actions/core'
import {exec} from '@actions/exec'
import {mkdirP, cp, rmRF} from '@actions/io'
import {downloadTool} from '@actions/tool-cache'
import {platform as getPlatform} from 'os'
import {arch, platform as getPlatform} from 'os'
import {join} from 'path'

export const getDownloadURL = (version: string): string => {
const osPlat = getPlatform()
const osArch = getMinikubeArch()
const platform = osPlat === 'win32' ? 'windows' : osPlat
const suffix = osPlat === 'win32' ? '.exe' : ''
switch (version) {
case 'latest':
return `https://github.com/kubernetes/minikube/releases/latest/download/minikube-${platform}-amd64${suffix}`
return `https://github.com/kubernetes/minikube/releases/latest/download/minikube-${platform}-${osArch}${suffix}`
case 'head':
return `https://storage.googleapis.com/minikube-builds/master/minikube-${platform}-amd64${suffix}`
return `https://storage.googleapis.com/minikube-builds/master/minikube-${platform}-${osArch}${suffix}`
default:
return `https://github.com/kubernetes/minikube/releases/download/v${version}/minikube-${platform}-amd64${suffix}`
return `https://github.com/kubernetes/minikube/releases/download/v${version}/minikube-${platform}-${osArch}${suffix}`
}
}

const getMinikubeArch = (): string => {
switch (arch()) {
case 'x64':
return 'amd64'
break
case 'arm64':
return 'arm64'
break
case 'arm':
return 'arm'
break
case 's390x':
return 's390x'
break
case 'ppc64':
return 'ppc64le'
break
default:
throw new Error(
`Machine is of arch ${arch()}, which isn't supported by minikube.`
)
}
}

Expand Down

0 comments on commit 9ed194e

Please sign in to comment.