Skip to content

Commit

Permalink
Tool cache install from a manifest file (actions#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanmacfarlane authored May 19, 2020
1 parent dcf5c88 commit 4e9375d
Show file tree
Hide file tree
Showing 8 changed files with 633 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-ignore": "error",
"camelcase": "off",
"@typescript-eslint/camelcase": "error",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
"@typescript-eslint/func-call-spacing": ["error", "never"],
Expand Down
1 change: 0 additions & 1 deletion packages/github/__tests__/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ describe('@actions/context', () => {
it('works with pull_request payloads', () => {
delete process.env.GITHUB_REPOSITORY
context.payload = {
// eslint-disable-next-line @typescript-eslint/camelcase
pull_request: {number: 2},
repository: {owner: {login: 'user'}, name: 'test'}
}
Expand Down
86 changes: 86 additions & 0 deletions packages/tool-cache/__tests__/data/versions-manifest.json
Original file line number Diff line number Diff line change
@@ -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 changes: 272 additions & 0 deletions packages/tool-cache/__tests__/manifest.test.ts
Original file line number Diff line number Diff line change
@@ -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')
})
})
2 changes: 1 addition & 1 deletion packages/tool-cache/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/tool-cache/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@actions/tool-cache",
"version": "1.3.5",
"version": "1.5.4",
"description": "Actions tool-cache lib",
"keywords": [
"github",
Expand Down
Loading

0 comments on commit 4e9375d

Please sign in to comment.