mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-05 18:13:19 +08:00
Tool cache install from a manifest file (#382)
This commit is contained in:
86
packages/tool-cache/__tests__/data/versions-manifest.json
Normal file
86
packages/tool-cache/__tests__/data/versions-manifest.json
Normal file
@@ -0,0 +1,86 @@
|
||||
[
|
||||
{
|
||||
"version": "3.0.1",
|
||||
"stable": false,
|
||||
"release_url": "https://github.com/actions/sometool/releases/tag/3.0.1-20200402.6",
|
||||
"files": [
|
||||
{
|
||||
"filename": "sometool-3.0.1-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://github.com/actions/sometool/releases/tag/3.0.1-20200402.6/sometool-1.2.3-linux-x64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "2.0.2",
|
||||
"stable": true,
|
||||
"release_url": "https://github.com/actions/sometool/releases/tag/2.0.2-20200402.6",
|
||||
"files": [
|
||||
{
|
||||
"filename": "sometool-2.0.2-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://github.com/actions/sometool/releases/tag/2.0.2-20200402.6/sometool-2.0.2-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "sometool-2.0.2-linux-x32.tar.gz",
|
||||
"arch": "x32",
|
||||
"platform": "linux",
|
||||
"download_url": "https://github.com/actions/sometool/releases/tag/2.0.2-20200402.6/sometool-2.0.2-linux-x32.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "sometool-2.0.2-linux-x32.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "windows",
|
||||
"download_url": "https://github.com/actions/sometool/releases/tag/2.0.2-20200402.6/sometool-2.0.2-linux-x32.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.2.4",
|
||||
"stable": true,
|
||||
"release_url": "https://github.com/actions/sometool/releases/tag/1.2.4-20200402.6",
|
||||
"files": [
|
||||
{
|
||||
"filename": "sometool-1.2.4-ubuntu1804-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"platform_version": "18.04",
|
||||
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.4-20200402.6/sometool-1.2.4-ubuntu1804-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "sometool-1.2.4-darwin1015-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"platform_version": "10.15",
|
||||
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.4-20200402.6/sometool-1.2.4-darwin1015-x64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.2.3",
|
||||
"stable": true,
|
||||
"release_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6",
|
||||
"files": [
|
||||
{
|
||||
"filename": "sometool-1.2.3-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "sometool-1.2.3-linux-x32.tar.gz",
|
||||
"arch": "x32",
|
||||
"platform": "linux",
|
||||
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-linux-x32.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "sometool-1.2.3-linux-x32.zip",
|
||||
"arch": "x64",
|
||||
"platform": "windows",
|
||||
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-linux-x32.zip"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
272
packages/tool-cache/__tests__/manifest.test.ts
Normal file
272
packages/tool-cache/__tests__/manifest.test.ts
Normal file
@@ -0,0 +1,272 @@
|
||||
import * as tc from '../src/tool-cache'
|
||||
import * as mm from '../src/manifest' // --> OFF
|
||||
|
||||
// needs to be require for core node modules to be mocked
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
import osm = require('os')
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
import cp = require('child_process')
|
||||
//import {coerce} from 'semver'
|
||||
|
||||
// we fetch the manifest file from master of a repo
|
||||
const owner = 'actions'
|
||||
const repo = 'some-tool'
|
||||
const fakeToken = 'notrealtoken'
|
||||
|
||||
// just loading data and require handles BOMs etc.
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
||||
const manifestData = require('./data/versions-manifest.json')
|
||||
|
||||
describe('@actions/tool-cache-manifest', () => {
|
||||
let os: {platform: string; arch: string}
|
||||
|
||||
let getSpy: jest.SpyInstance
|
||||
let platSpy: jest.SpyInstance
|
||||
let archSpy: jest.SpyInstance
|
||||
let execSpy: jest.SpyInstance
|
||||
let readLsbSpy: jest.SpyInstance
|
||||
|
||||
beforeEach(() => {
|
||||
// node
|
||||
os = {platform: '', arch: ''}
|
||||
platSpy = jest.spyOn(osm, 'platform')
|
||||
|
||||
platSpy.mockImplementation(() => os.platform)
|
||||
archSpy = jest.spyOn(osm, 'arch')
|
||||
archSpy.mockImplementation(() => os.arch)
|
||||
|
||||
execSpy = jest.spyOn(cp, 'execSync')
|
||||
readLsbSpy = jest.spyOn(mm, '_readLinuxVersionFile')
|
||||
|
||||
getSpy = jest.spyOn(tc, 'getManifestFromRepo')
|
||||
getSpy.mockImplementation(() => <mm.IToolRelease[]>manifestData)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks()
|
||||
jest.clearAllMocks()
|
||||
//jest.restoreAllMocks();
|
||||
})
|
||||
|
||||
afterAll(async () => {}, 100000)
|
||||
|
||||
it('can query versions', async () => {
|
||||
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
|
||||
owner,
|
||||
repo,
|
||||
fakeToken
|
||||
)
|
||||
|
||||
expect(manifest).toBeDefined()
|
||||
const l: number = manifest ? manifest.length : 0
|
||||
expect(l).toBe(4)
|
||||
})
|
||||
|
||||
it('can match stable major version for linux x64', async () => {
|
||||
os.platform = 'linux'
|
||||
os.arch = 'x64'
|
||||
|
||||
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
|
||||
owner,
|
||||
repo,
|
||||
fakeToken
|
||||
)
|
||||
const release: tc.IToolRelease | undefined = await tc.findFromManifest(
|
||||
'2.x',
|
||||
true,
|
||||
manifest
|
||||
)
|
||||
expect(release).toBeDefined()
|
||||
expect(release?.version).toBe('2.0.2')
|
||||
expect(release?.files.length).toBe(1)
|
||||
const file = release?.files[0]
|
||||
expect(file).toBeDefined()
|
||||
expect(file?.arch).toBe('x64')
|
||||
expect(file?.platform).toBe('linux')
|
||||
expect(file?.download_url).toBe(
|
||||
'https://github.com/actions/sometool/releases/tag/2.0.2-20200402.6/sometool-2.0.2-linux-x64.tar.gz'
|
||||
)
|
||||
expect(file?.filename).toBe('sometool-2.0.2-linux-x64.tar.gz')
|
||||
})
|
||||
|
||||
it('can match stable exact version for linux x64', async () => {
|
||||
os.platform = 'linux'
|
||||
os.arch = 'x64'
|
||||
|
||||
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
|
||||
owner,
|
||||
repo,
|
||||
fakeToken
|
||||
)
|
||||
const release: tc.IToolRelease | undefined = await tc.findFromManifest(
|
||||
'1.2.3',
|
||||
true,
|
||||
manifest
|
||||
)
|
||||
expect(release).toBeDefined()
|
||||
expect(release?.version).toBe('1.2.3')
|
||||
expect(release?.files.length).toBe(1)
|
||||
const file = release?.files[0]
|
||||
expect(file).toBeDefined()
|
||||
expect(file?.arch).toBe('x64')
|
||||
expect(file?.platform).toBe('linux')
|
||||
expect(file?.download_url).toBe(
|
||||
'https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-linux-x64.tar.gz'
|
||||
)
|
||||
expect(file?.filename).toBe('sometool-1.2.3-linux-x64.tar.gz')
|
||||
})
|
||||
|
||||
it('can match with linux platform version spec', async () => {
|
||||
os.platform = 'linux'
|
||||
os.arch = 'x64'
|
||||
|
||||
readLsbSpy.mockImplementation(() => {
|
||||
return `DISTRIB_ID=Ubuntu
|
||||
DISTRIB_RELEASE=18.04
|
||||
DISTRIB_CODENAME=bionic
|
||||
DISTRIB_DESCRIPTION=Ubuntu 18.04.4 LTS`
|
||||
})
|
||||
|
||||
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
|
||||
owner,
|
||||
repo,
|
||||
fakeToken
|
||||
)
|
||||
const release: tc.IToolRelease | undefined = await tc.findFromManifest(
|
||||
'1.2.4',
|
||||
true,
|
||||
manifest
|
||||
)
|
||||
expect(release).toBeDefined()
|
||||
expect(release?.version).toBe('1.2.4')
|
||||
expect(release?.files.length).toBe(1)
|
||||
const file = release?.files[0]
|
||||
expect(file).toBeDefined()
|
||||
expect(file?.arch).toBe('x64')
|
||||
expect(file?.platform).toBe('linux')
|
||||
expect(file?.download_url).toBe(
|
||||
'https://github.com/actions/sometool/releases/tag/1.2.4-20200402.6/sometool-1.2.4-ubuntu1804-x64.tar.gz'
|
||||
)
|
||||
expect(file?.filename).toBe('sometool-1.2.4-ubuntu1804-x64.tar.gz')
|
||||
})
|
||||
|
||||
it('can match with darwin platform version spec', async () => {
|
||||
os.platform = 'darwin'
|
||||
os.arch = 'x64'
|
||||
|
||||
execSpy.mockImplementation(() => '10.15.1')
|
||||
|
||||
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
|
||||
owner,
|
||||
repo,
|
||||
fakeToken
|
||||
)
|
||||
const release: tc.IToolRelease | undefined = await tc.findFromManifest(
|
||||
'1.2.4',
|
||||
true,
|
||||
manifest
|
||||
)
|
||||
expect(release).toBeDefined()
|
||||
expect(release?.version).toBe('1.2.4')
|
||||
expect(release?.files.length).toBe(1)
|
||||
const file = release?.files[0]
|
||||
expect(file).toBeDefined()
|
||||
expect(file?.arch).toBe('x64')
|
||||
expect(file?.platform).toBe('darwin')
|
||||
expect(file?.download_url).toBe(
|
||||
'https://github.com/actions/sometool/releases/tag/1.2.4-20200402.6/sometool-1.2.4-darwin1015-x64.tar.gz'
|
||||
)
|
||||
expect(file?.filename).toBe('sometool-1.2.4-darwin1015-x64.tar.gz')
|
||||
})
|
||||
|
||||
it('does not match with unmatched linux platform version spec', async () => {
|
||||
os.platform = 'linux'
|
||||
os.arch = 'x64'
|
||||
|
||||
readLsbSpy.mockImplementation(() => {
|
||||
return `DISTRIB_ID=Ubuntu
|
||||
DISTRIB_RELEASE=16.04
|
||||
DISTRIB_CODENAME=xenial
|
||||
DISTRIB_DESCRIPTION=Ubuntu 16.04.4 LTS`
|
||||
})
|
||||
|
||||
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
|
||||
owner,
|
||||
repo,
|
||||
fakeToken
|
||||
)
|
||||
const release: tc.IToolRelease | undefined = await tc.findFromManifest(
|
||||
'1.2.4',
|
||||
true,
|
||||
manifest
|
||||
)
|
||||
expect(release).toBeUndefined()
|
||||
})
|
||||
|
||||
it('does not match with unmatched darwin platform version spec', async () => {
|
||||
os.platform = 'darwin'
|
||||
os.arch = 'x64'
|
||||
|
||||
execSpy.mockImplementation(() => '10.14.6')
|
||||
|
||||
const manifest: mm.IToolRelease[] | null = await tc.getManifestFromRepo(
|
||||
owner,
|
||||
repo,
|
||||
fakeToken
|
||||
)
|
||||
const release: tc.IToolRelease | undefined = await tc.findFromManifest(
|
||||
'1.2.4',
|
||||
true,
|
||||
manifest
|
||||
)
|
||||
expect(release).toBeUndefined()
|
||||
})
|
||||
|
||||
it('can get version from lsb on ubuntu-18.04', async () => {
|
||||
os.platform = 'linux'
|
||||
os.arch = 'x64'
|
||||
|
||||
//existsSpy.mockImplementation(() => true)
|
||||
readLsbSpy.mockImplementation(() => {
|
||||
return `DISTRIB_ID=Ubuntu
|
||||
DISTRIB_RELEASE=18.04
|
||||
DISTRIB_CODENAME=bionic
|
||||
DISTRIB_DESCRIPTION=Ubuntu 18.04.4 LTS`
|
||||
})
|
||||
|
||||
const version = mm._getOsVersion()
|
||||
|
||||
expect(osm.platform()).toBe('linux')
|
||||
expect(version).toBe('18.04')
|
||||
})
|
||||
|
||||
it('can get version from lsb on ubuntu-16.04', async () => {
|
||||
os.platform = 'linux'
|
||||
os.arch = 'x64'
|
||||
|
||||
readLsbSpy.mockImplementation(() => {
|
||||
return `DISTRIB_ID=Ubuntu
|
||||
DISTRIB_RELEASE=16.04
|
||||
DISTRIB_CODENAME=xenial
|
||||
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"`
|
||||
})
|
||||
|
||||
const version = mm._getOsVersion()
|
||||
|
||||
expect(osm.platform()).toBe('linux')
|
||||
expect(version).toBe('16.04')
|
||||
})
|
||||
|
||||
// sw_vers -productVersion
|
||||
it('can get version on macOS', async () => {
|
||||
os.platform = 'darwin'
|
||||
os.arch = 'x64'
|
||||
|
||||
execSpy.mockImplementation(() => '10.14.6')
|
||||
|
||||
const version = mm._getOsVersion()
|
||||
|
||||
expect(osm.platform()).toBe('darwin')
|
||||
expect(version).toBe('10.14.6')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user