Skip to content

Commit 4e9375d

Browse files
Tool cache install from a manifest file (actions#382)
1 parent dcf5c88 commit 4e9375d

File tree

8 files changed

+633
-10
lines changed

8 files changed

+633
-10
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@typescript-eslint/await-thenable": "error",
1919
"@typescript-eslint/ban-ts-ignore": "error",
2020
"camelcase": "off",
21-
"@typescript-eslint/camelcase": "error",
21+
"@typescript-eslint/camelcase": "off",
2222
"@typescript-eslint/class-name-casing": "error",
2323
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
2424
"@typescript-eslint/func-call-spacing": ["error", "never"],

packages/github/__tests__/lib.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ describe('@actions/context', () => {
5555
it('works with pull_request payloads', () => {
5656
delete process.env.GITHUB_REPOSITORY
5757
context.payload = {
58-
// eslint-disable-next-line @typescript-eslint/camelcase
5958
pull_request: {number: 2},
6059
repository: {owner: {login: 'user'}, name: 'test'}
6160
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
[
2+
{
3+
"version": "3.0.1",
4+
"stable": false,
5+
"release_url": "https://github.com/actions/sometool/releases/tag/3.0.1-20200402.6",
6+
"files": [
7+
{
8+
"filename": "sometool-3.0.1-linux-x64.tar.gz",
9+
"arch": "x64",
10+
"platform": "linux",
11+
"download_url": "https://github.com/actions/sometool/releases/tag/3.0.1-20200402.6/sometool-1.2.3-linux-x64.tar.gz"
12+
}
13+
]
14+
},
15+
{
16+
"version": "2.0.2",
17+
"stable": true,
18+
"release_url": "https://github.com/actions/sometool/releases/tag/2.0.2-20200402.6",
19+
"files": [
20+
{
21+
"filename": "sometool-2.0.2-linux-x64.tar.gz",
22+
"arch": "x64",
23+
"platform": "linux",
24+
"download_url": "https://github.com/actions/sometool/releases/tag/2.0.2-20200402.6/sometool-2.0.2-linux-x64.tar.gz"
25+
},
26+
{
27+
"filename": "sometool-2.0.2-linux-x32.tar.gz",
28+
"arch": "x32",
29+
"platform": "linux",
30+
"download_url": "https://github.com/actions/sometool/releases/tag/2.0.2-20200402.6/sometool-2.0.2-linux-x32.tar.gz"
31+
},
32+
{
33+
"filename": "sometool-2.0.2-linux-x32.tar.gz",
34+
"arch": "x64",
35+
"platform": "windows",
36+
"download_url": "https://github.com/actions/sometool/releases/tag/2.0.2-20200402.6/sometool-2.0.2-linux-x32.tar.gz"
37+
}
38+
]
39+
},
40+
{
41+
"version": "1.2.4",
42+
"stable": true,
43+
"release_url": "https://github.com/actions/sometool/releases/tag/1.2.4-20200402.6",
44+
"files": [
45+
{
46+
"filename": "sometool-1.2.4-ubuntu1804-x64.tar.gz",
47+
"arch": "x64",
48+
"platform": "linux",
49+
"platform_version": "18.04",
50+
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.4-20200402.6/sometool-1.2.4-ubuntu1804-x64.tar.gz"
51+
},
52+
{
53+
"filename": "sometool-1.2.4-darwin1015-x64.tar.gz",
54+
"arch": "x64",
55+
"platform": "darwin",
56+
"platform_version": "10.15",
57+
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.4-20200402.6/sometool-1.2.4-darwin1015-x64.tar.gz"
58+
}
59+
]
60+
},
61+
{
62+
"version": "1.2.3",
63+
"stable": true,
64+
"release_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6",
65+
"files": [
66+
{
67+
"filename": "sometool-1.2.3-linux-x64.tar.gz",
68+
"arch": "x64",
69+
"platform": "linux",
70+
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-linux-x64.tar.gz"
71+
},
72+
{
73+
"filename": "sometool-1.2.3-linux-x32.tar.gz",
74+
"arch": "x32",
75+
"platform": "linux",
76+
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-linux-x32.tar.gz"
77+
},
78+
{
79+
"filename": "sometool-1.2.3-linux-x32.zip",
80+
"arch": "x64",
81+
"platform": "windows",
82+
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-linux-x32.zip"
83+
}
84+
]
85+
}
86+
]
Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
import * as tc from '../src/tool-cache'
2+
import * as mm from '../src/manifest' // --> OFF
3+
4+
// needs to be require for core node modules to be mocked
5+
// eslint-disable-next-line @typescript-eslint/no-require-imports
6+
import osm = require('os')
7+
// eslint-disable-next-line @typescript-eslint/no-require-imports
8+
import cp = require('child_process')
9+
//import {coerce} from 'semver'
10+
11+
// we fetch the manifest file from master of a repo
12+
const owner = 'actions'
13+
const repo = 'some-tool'
14+
const fakeToken = 'notrealtoken'
15+
16+
// just loading data and require handles BOMs etc.
17+
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
18+
const manifestData = require('./data/versions-manifest.json')
19+
20+
describe('@actions/tool-cache-manifest', () => {
21+
let os: {platform: string; arch: string}
22+
23+
let getSpy: jest.SpyInstance
24+
let platSpy: jest.SpyInstance
25+
let archSpy: jest.SpyInstance
26+
let execSpy: jest.SpyInstance
27+
let readLsbSpy: jest.SpyInstance
28+
29+
beforeEach(() => {
30+
// node
31+
os = {platform: '', arch: ''}
32+
platSpy = jest.spyOn(osm, 'platform')
33+
34+
platSpy.mockImplementation(() => os.platform)
35+
archSpy = jest.spyOn(osm, 'arch')
36+
archSpy.mockImplementation(() => os.arch)
37+
38+
execSpy = jest.spyOn(cp, 'execSync')
39+
readLsbSpy = jest.spyOn(mm, '_readLinuxVersionFile')
40+
41+
getSpy = jest.spyOn(tc, 'getManifestFromRepo')
42+
getSpy.mockImplementation(() => <mm.IToolRelease[]>manifestData)
43+
})
44+
45+
afterEach(() => {
46+
jest.resetAllMocks()
47+
jest.clearAllMocks()
48+
//jest.restoreAllMocks();
49+
})
50+
51+
afterAll(async () => {}, 100000)
52+
53+
it('can query versions', async () => {
54+
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
55+
owner,
56+
repo,
57+
fakeToken
58+
)
59+
60+
expect(manifest).toBeDefined()
61+
const l: number = manifest ? manifest.length : 0
62+
expect(l).toBe(4)
63+
})
64+
65+
it('can match stable major version for linux x64', async () => {
66+
os.platform = 'linux'
67+
os.arch = 'x64'
68+
69+
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
70+
owner,
71+
repo,
72+
fakeToken
73+
)
74+
const release: tc.IToolRelease | undefined = await tc.findFromManifest(
75+
'2.x',
76+
true,
77+
manifest
78+
)
79+
expect(release).toBeDefined()
80+
expect(release?.version).toBe('2.0.2')
81+
expect(release?.files.length).toBe(1)
82+
const file = release?.files[0]
83+
expect(file).toBeDefined()
84+
expect(file?.arch).toBe('x64')
85+
expect(file?.platform).toBe('linux')
86+
expect(file?.download_url).toBe(
87+
'https://github.com/actions/sometool/releases/tag/2.0.2-20200402.6/sometool-2.0.2-linux-x64.tar.gz'
88+
)
89+
expect(file?.filename).toBe('sometool-2.0.2-linux-x64.tar.gz')
90+
})
91+
92+
it('can match stable exact version for linux x64', async () => {
93+
os.platform = 'linux'
94+
os.arch = 'x64'
95+
96+
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
97+
owner,
98+
repo,
99+
fakeToken
100+
)
101+
const release: tc.IToolRelease | undefined = await tc.findFromManifest(
102+
'1.2.3',
103+
true,
104+
manifest
105+
)
106+
expect(release).toBeDefined()
107+
expect(release?.version).toBe('1.2.3')
108+
expect(release?.files.length).toBe(1)
109+
const file = release?.files[0]
110+
expect(file).toBeDefined()
111+
expect(file?.arch).toBe('x64')
112+
expect(file?.platform).toBe('linux')
113+
expect(file?.download_url).toBe(
114+
'https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-linux-x64.tar.gz'
115+
)
116+
expect(file?.filename).toBe('sometool-1.2.3-linux-x64.tar.gz')
117+
})
118+
119+
it('can match with linux platform version spec', async () => {
120+
os.platform = 'linux'
121+
os.arch = 'x64'
122+
123+
readLsbSpy.mockImplementation(() => {
124+
return `DISTRIB_ID=Ubuntu
125+
DISTRIB_RELEASE=18.04
126+
DISTRIB_CODENAME=bionic
127+
DISTRIB_DESCRIPTION=Ubuntu 18.04.4 LTS`
128+
})
129+
130+
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
131+
owner,
132+
repo,
133+
fakeToken
134+
)
135+
const release: tc.IToolRelease | undefined = await tc.findFromManifest(
136+
'1.2.4',
137+
true,
138+
manifest
139+
)
140+
expect(release).toBeDefined()
141+
expect(release?.version).toBe('1.2.4')
142+
expect(release?.files.length).toBe(1)
143+
const file = release?.files[0]
144+
expect(file).toBeDefined()
145+
expect(file?.arch).toBe('x64')
146+
expect(file?.platform).toBe('linux')
147+
expect(file?.download_url).toBe(
148+
'https://github.com/actions/sometool/releases/tag/1.2.4-20200402.6/sometool-1.2.4-ubuntu1804-x64.tar.gz'
149+
)
150+
expect(file?.filename).toBe('sometool-1.2.4-ubuntu1804-x64.tar.gz')
151+
})
152+
153+
it('can match with darwin platform version spec', async () => {
154+
os.platform = 'darwin'
155+
os.arch = 'x64'
156+
157+
execSpy.mockImplementation(() => '10.15.1')
158+
159+
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
160+
owner,
161+
repo,
162+
fakeToken
163+
)
164+
const release: tc.IToolRelease | undefined = await tc.findFromManifest(
165+
'1.2.4',
166+
true,
167+
manifest
168+
)
169+
expect(release).toBeDefined()
170+
expect(release?.version).toBe('1.2.4')
171+
expect(release?.files.length).toBe(1)
172+
const file = release?.files[0]
173+
expect(file).toBeDefined()
174+
expect(file?.arch).toBe('x64')
175+
expect(file?.platform).toBe('darwin')
176+
expect(file?.download_url).toBe(
177+
'https://github.com/actions/sometool/releases/tag/1.2.4-20200402.6/sometool-1.2.4-darwin1015-x64.tar.gz'
178+
)
179+
expect(file?.filename).toBe('sometool-1.2.4-darwin1015-x64.tar.gz')
180+
})
181+
182+
it('does not match with unmatched linux platform version spec', async () => {
183+
os.platform = 'linux'
184+
os.arch = 'x64'
185+
186+
readLsbSpy.mockImplementation(() => {
187+
return `DISTRIB_ID=Ubuntu
188+
DISTRIB_RELEASE=16.04
189+
DISTRIB_CODENAME=xenial
190+
DISTRIB_DESCRIPTION=Ubuntu 16.04.4 LTS`
191+
})
192+
193+
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
194+
owner,
195+
repo,
196+
fakeToken
197+
)
198+
const release: tc.IToolRelease | undefined = await tc.findFromManifest(
199+
'1.2.4',
200+
true,
201+
manifest
202+
)
203+
expect(release).toBeUndefined()
204+
})
205+
206+
it('does not match with unmatched darwin platform version spec', async () => {
207+
os.platform = 'darwin'
208+
os.arch = 'x64'
209+
210+
execSpy.mockImplementation(() => '10.14.6')
211+
212+
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
213+
owner,
214+
repo,
215+
fakeToken
216+
)
217+
const release: tc.IToolRelease | undefined = await tc.findFromManifest(
218+
'1.2.4',
219+
true,
220+
manifest
221+
)
222+
expect(release).toBeUndefined()
223+
})
224+
225+
it('can get version from lsb on ubuntu-18.04', async () => {
226+
os.platform = 'linux'
227+
os.arch = 'x64'
228+
229+
//existsSpy.mockImplementation(() => true)
230+
readLsbSpy.mockImplementation(() => {
231+
return `DISTRIB_ID=Ubuntu
232+
DISTRIB_RELEASE=18.04
233+
DISTRIB_CODENAME=bionic
234+
DISTRIB_DESCRIPTION=Ubuntu 18.04.4 LTS`
235+
})
236+
237+
const version = mm._getOsVersion()
238+
239+
expect(osm.platform()).toBe('linux')
240+
expect(version).toBe('18.04')
241+
})
242+
243+
it('can get version from lsb on ubuntu-16.04', async () => {
244+
os.platform = 'linux'
245+
os.arch = 'x64'
246+
247+
readLsbSpy.mockImplementation(() => {
248+
return `DISTRIB_ID=Ubuntu
249+
DISTRIB_RELEASE=16.04
250+
DISTRIB_CODENAME=xenial
251+
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"`
252+
})
253+
254+
const version = mm._getOsVersion()
255+
256+
expect(osm.platform()).toBe('linux')
257+
expect(version).toBe('16.04')
258+
})
259+
260+
// sw_vers -productVersion
261+
it('can get version on macOS', async () => {
262+
os.platform = 'darwin'
263+
os.arch = 'x64'
264+
265+
execSpy.mockImplementation(() => '10.14.6')
266+
267+
const version = mm._getOsVersion()
268+
269+
expect(osm.platform()).toBe('darwin')
270+
expect(version).toBe('10.14.6')
271+
})
272+
})

packages/tool-cache/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/tool-cache/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@actions/tool-cache",
3-
"version": "1.3.5",
3+
"version": "1.5.4",
44
"description": "Actions tool-cache lib",
55
"keywords": [
66
"github",

0 commit comments

Comments
 (0)