Skip to content

Commit 9ed194e

Browse files
authored
Merge pull request #469 from spowelljr/useProperArch
Download binary based on machine arch
2 parents 6cb1078 + 9e2bb81 commit 9ed194e

File tree

3 files changed

+234
-61
lines changed

3 files changed

+234
-61
lines changed

__tests__/download.test.ts

Lines changed: 180 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,188 @@ import {getDownloadURL} from '../src/download'
55
jest.mock('os')
66
const mockedOS = jest.mocked(os)
77

8-
test('getDownloadURL Unix latest', () => {
9-
mockedOS.platform.mockReturnValue('linux')
10-
11-
const url = getDownloadURL('latest')
12-
13-
expect(url).toBe(
14-
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64'
15-
)
16-
})
17-
18-
test('getDownloadURL Windows latest', () => {
19-
mockedOS.platform.mockReturnValue('win32')
20-
21-
const url = getDownloadURL('latest')
22-
23-
expect(url).toBe(
24-
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-windows-amd64.exe'
25-
)
26-
})
27-
28-
test('getDownloadURL Unix head', () => {
29-
mockedOS.platform.mockReturnValue('linux')
30-
31-
const url = getDownloadURL('head')
32-
33-
expect(url).toBe(
34-
'https://storage.googleapis.com/minikube-builds/master/minikube-linux-amd64'
35-
)
8+
test('getDownloadURL Linux', () => {
9+
const tests = [
10+
{
11+
arch: 'x64',
12+
version: 'latest',
13+
expected:
14+
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64',
15+
},
16+
{
17+
arch: 'arm64',
18+
version: 'latest',
19+
expected:
20+
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-arm64',
21+
},
22+
{
23+
arch: 'arm',
24+
version: 'latest',
25+
expected:
26+
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-arm',
27+
},
28+
{
29+
arch: 's390x',
30+
version: 'latest',
31+
expected:
32+
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-s390x',
33+
},
34+
{
35+
arch: 'ppc64',
36+
version: 'latest',
37+
expected:
38+
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-ppc64le',
39+
},
40+
{
41+
arch: 'x64',
42+
version: 'head',
43+
expected:
44+
'https://storage.googleapis.com/minikube-builds/master/minikube-linux-amd64',
45+
},
46+
{
47+
arch: 'arm64',
48+
version: 'head',
49+
expected:
50+
'https://storage.googleapis.com/minikube-builds/master/minikube-linux-arm64',
51+
},
52+
{
53+
arch: 'arm',
54+
version: 'head',
55+
expected:
56+
'https://storage.googleapis.com/minikube-builds/master/minikube-linux-arm',
57+
},
58+
{
59+
arch: 's390x',
60+
version: 'head',
61+
expected:
62+
'https://storage.googleapis.com/minikube-builds/master/minikube-linux-s390x',
63+
},
64+
{
65+
arch: 'ppc64',
66+
version: 'head',
67+
expected:
68+
'https://storage.googleapis.com/minikube-builds/master/minikube-linux-ppc64le',
69+
},
70+
{
71+
arch: 'x64',
72+
version: '1.28.0',
73+
expected:
74+
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-linux-amd64',
75+
},
76+
{
77+
arch: 'arm64',
78+
version: '1.28.0',
79+
expected:
80+
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-linux-arm64',
81+
},
82+
{
83+
arch: 'arm',
84+
version: '1.28.0',
85+
expected:
86+
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-linux-arm',
87+
},
88+
{
89+
arch: 's390x',
90+
version: '1.28.0',
91+
expected:
92+
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-linux-s390x',
93+
},
94+
{
95+
arch: 'ppc64',
96+
version: '1.28.0',
97+
expected:
98+
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-linux-ppc64le',
99+
},
100+
]
101+
102+
for (const tc of tests) {
103+
mockedOS.arch.mockReturnValue(tc.arch)
104+
mockedOS.platform.mockReturnValue('linux')
105+
106+
const url = getDownloadURL(tc.version)
107+
108+
expect(url).toBe(tc.expected)
109+
}
36110
})
37111

38-
test('getDownloadURL Windows head', () => {
39-
mockedOS.platform.mockReturnValue('win32')
40-
41-
const url = getDownloadURL('head')
42-
43-
expect(url).toBe(
44-
'https://storage.googleapis.com/minikube-builds/master/minikube-windows-amd64.exe'
45-
)
112+
test('getDownloadURL macOS', () => {
113+
const tests = [
114+
{
115+
arch: 'x64',
116+
version: 'latest',
117+
expected:
118+
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-darwin-amd64',
119+
},
120+
{
121+
arch: 'arm64',
122+
version: 'latest',
123+
expected:
124+
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-darwin-arm64',
125+
},
126+
{
127+
arch: 'x64',
128+
version: 'head',
129+
expected:
130+
'https://storage.googleapis.com/minikube-builds/master/minikube-darwin-amd64',
131+
},
132+
{
133+
arch: 'arm64',
134+
version: 'head',
135+
expected:
136+
'https://storage.googleapis.com/minikube-builds/master/minikube-darwin-arm64',
137+
},
138+
{
139+
arch: 'x64',
140+
version: '1.28.0',
141+
expected:
142+
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-darwin-amd64',
143+
},
144+
{
145+
arch: 'arm64',
146+
version: '1.28.0',
147+
expected:
148+
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-darwin-arm64',
149+
},
150+
]
151+
152+
for (const tc of tests) {
153+
mockedOS.arch.mockReturnValue(tc.arch)
154+
mockedOS.platform.mockReturnValue('darwin')
155+
156+
const url = getDownloadURL(tc.version)
157+
158+
expect(url).toBe(tc.expected)
159+
}
46160
})
47161

48-
test('getDownloadURL Unix version', () => {
49-
mockedOS.platform.mockReturnValue('linux')
50-
51-
const url = getDownloadURL('1.28.0')
52-
53-
expect(url).toBe(
54-
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-linux-amd64'
55-
)
56-
})
57-
58-
test('getDownloadURL Windows version', () => {
59-
mockedOS.platform.mockReturnValue('win32')
60-
61-
const url = getDownloadURL('1.28.0')
62-
63-
expect(url).toBe(
64-
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-windows-amd64.exe'
65-
)
162+
test('getDownloadURL Windows', () => {
163+
const tests = [
164+
{
165+
arch: 'x64',
166+
version: 'latest',
167+
expected:
168+
'https://github.com/kubernetes/minikube/releases/latest/download/minikube-windows-amd64.exe',
169+
},
170+
{
171+
arch: 'x64',
172+
version: 'head',
173+
expected:
174+
'https://storage.googleapis.com/minikube-builds/master/minikube-windows-amd64.exe',
175+
},
176+
{
177+
arch: 'x64',
178+
version: '1.28.0',
179+
expected:
180+
'https://github.com/kubernetes/minikube/releases/download/v1.28.0/minikube-windows-amd64.exe',
181+
},
182+
]
183+
184+
for (const tc of tests) {
185+
mockedOS.arch.mockReturnValue(tc.arch)
186+
mockedOS.platform.mockReturnValue('win32')
187+
188+
const url = getDownloadURL(tc.version)
189+
190+
expect(url).toBe(tc.expected)
191+
}
66192
})

dist/index.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,40 @@ const os_1 = __nccwpck_require__(2037);
127127
const path_1 = __nccwpck_require__(1017);
128128
const getDownloadURL = (version) => {
129129
const osPlat = (0, os_1.platform)();
130+
const osArch = getMinikubeArch();
130131
const platform = osPlat === 'win32' ? 'windows' : osPlat;
131132
const suffix = osPlat === 'win32' ? '.exe' : '';
132133
switch (version) {
133134
case 'latest':
134-
return `https://github.com/kubernetes/minikube/releases/latest/download/minikube-${platform}-amd64${suffix}`;
135+
return `https://github.com/kubernetes/minikube/releases/latest/download/minikube-${platform}-${osArch}${suffix}`;
135136
case 'head':
136-
return `https://storage.googleapis.com/minikube-builds/master/minikube-${platform}-amd64${suffix}`;
137+
return `https://storage.googleapis.com/minikube-builds/master/minikube-${platform}-${osArch}${suffix}`;
137138
default:
138-
return `https://github.com/kubernetes/minikube/releases/download/v${version}/minikube-${platform}-amd64${suffix}`;
139+
return `https://github.com/kubernetes/minikube/releases/download/v${version}/minikube-${platform}-${osArch}${suffix}`;
139140
}
140141
};
141142
exports.getDownloadURL = getDownloadURL;
143+
const getMinikubeArch = () => {
144+
switch ((0, os_1.arch)()) {
145+
case 'x64':
146+
return 'amd64';
147+
break;
148+
case 'arm64':
149+
return 'arm64';
150+
break;
151+
case 'arm':
152+
return 'arm';
153+
break;
154+
case 's390x':
155+
return 's390x';
156+
break;
157+
case 'ppc64':
158+
return 'ppc64le';
159+
break;
160+
default:
161+
throw new Error(`Machine is of arch ${(0, os_1.arch)()}, which isn't supported by minikube.`);
162+
}
163+
};
142164
const downloadMinikube = (version, installPath) => __awaiter(void 0, void 0, void 0, function* () {
143165
const url = (0, exports.getDownloadURL)(version);
144166
const downloadPath = yield (0, tool_cache_1.downloadTool)(url);

src/download.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,45 @@ import {addPath} from '@actions/core'
22
import {exec} from '@actions/exec'
33
import {mkdirP, cp, rmRF} from '@actions/io'
44
import {downloadTool} from '@actions/tool-cache'
5-
import {platform as getPlatform} from 'os'
5+
import {arch, platform as getPlatform} from 'os'
66
import {join} from 'path'
77

88
export const getDownloadURL = (version: string): string => {
99
const osPlat = getPlatform()
10+
const osArch = getMinikubeArch()
1011
const platform = osPlat === 'win32' ? 'windows' : osPlat
1112
const suffix = osPlat === 'win32' ? '.exe' : ''
1213
switch (version) {
1314
case 'latest':
14-
return `https://github.com/kubernetes/minikube/releases/latest/download/minikube-${platform}-amd64${suffix}`
15+
return `https://github.com/kubernetes/minikube/releases/latest/download/minikube-${platform}-${osArch}${suffix}`
1516
case 'head':
16-
return `https://storage.googleapis.com/minikube-builds/master/minikube-${platform}-amd64${suffix}`
17+
return `https://storage.googleapis.com/minikube-builds/master/minikube-${platform}-${osArch}${suffix}`
1718
default:
18-
return `https://github.com/kubernetes/minikube/releases/download/v${version}/minikube-${platform}-amd64${suffix}`
19+
return `https://github.com/kubernetes/minikube/releases/download/v${version}/minikube-${platform}-${osArch}${suffix}`
20+
}
21+
}
22+
23+
const getMinikubeArch = (): string => {
24+
switch (arch()) {
25+
case 'x64':
26+
return 'amd64'
27+
break
28+
case 'arm64':
29+
return 'arm64'
30+
break
31+
case 'arm':
32+
return 'arm'
33+
break
34+
case 's390x':
35+
return 's390x'
36+
break
37+
case 'ppc64':
38+
return 'ppc64le'
39+
break
40+
default:
41+
throw new Error(
42+
`Machine is of arch ${arch()}, which isn't supported by minikube.`
43+
)
1944
}
2045
}
2146

0 commit comments

Comments
 (0)