diff --git a/__tests__/download.test.ts b/__tests__/download.test.ts index c4e7ddc..aaf4517 100644 --- a/__tests__/download.test.ts +++ b/__tests__/download.test.ts @@ -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) + } }) diff --git a/dist/index.js b/dist/index.js index 4d5d148..8d447d6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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); diff --git a/src/download.ts b/src/download.ts index f9ee7fe..c1db1eb 100644 --- a/src/download.ts +++ b/src/download.ts @@ -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.` + ) } }