mirror of https://github.com/actions/toolkit
feat: get linux version from os-release file if available (#594)
parent
c507914181
commit
e1a7863be6
|
@ -116,7 +116,7 @@ describe('@actions/tool-cache-manifest', () => {
|
||||||
expect(file?.filename).toBe('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 () => {
|
it('can match with linux platform version spec from lsb-release', async () => {
|
||||||
os.platform = 'linux'
|
os.platform = 'linux'
|
||||||
os.arch = 'x64'
|
os.arch = 'x64'
|
||||||
|
|
||||||
|
@ -150,6 +150,48 @@ describe('@actions/tool-cache-manifest', () => {
|
||||||
expect(file?.filename).toBe('sometool-1.2.4-ubuntu1804-x64.tar.gz')
|
expect(file?.filename).toBe('sometool-1.2.4-ubuntu1804-x64.tar.gz')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('can match with linux platform version spec from os-release', async () => {
|
||||||
|
os.platform = 'linux'
|
||||||
|
os.arch = 'x64'
|
||||||
|
|
||||||
|
readLsbSpy.mockImplementation(() => {
|
||||||
|
return `NAME="Ubuntu"
|
||||||
|
VERSION="18.04.5 LTS (Bionic Beaver)"
|
||||||
|
ID=ubuntu
|
||||||
|
ID_LIKE=debian
|
||||||
|
PRETTY_NAME="Ubuntu 18.04.5 LTS"
|
||||||
|
VERSION_ID="18.04"
|
||||||
|
HOME_URL="https://www.ubuntu.com/"
|
||||||
|
SUPPORT_URL="https://help.ubuntu.com/"
|
||||||
|
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
|
||||||
|
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
|
||||||
|
VERSION_CODENAME=bionic
|
||||||
|
UBUNTU_CODENAME=bionic`
|
||||||
|
})
|
||||||
|
|
||||||
|
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 () => {
|
it('can match with darwin platform version spec', async () => {
|
||||||
os.platform = 'darwin'
|
os.platform = 'darwin'
|
||||||
os.arch = 'x64'
|
os.arch = 'x64'
|
||||||
|
|
|
@ -135,8 +135,15 @@ export function _getOsVersion(): string {
|
||||||
const lines = lsbContents.split('\n')
|
const lines = lsbContents.split('\n')
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
const parts = line.split('=')
|
const parts = line.split('=')
|
||||||
if (parts.length === 2 && parts[0].trim() === 'DISTRIB_RELEASE') {
|
if (
|
||||||
version = parts[1].trim()
|
parts.length === 2 &&
|
||||||
|
(parts[0].trim() === 'VERSION_ID' ||
|
||||||
|
parts[0].trim() === 'DISTRIB_RELEASE')
|
||||||
|
) {
|
||||||
|
version = parts[1]
|
||||||
|
.trim()
|
||||||
|
.replace(/^"/, '')
|
||||||
|
.replace(/"$/, '')
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,11 +154,14 @@ export function _getOsVersion(): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function _readLinuxVersionFile(): string {
|
export function _readLinuxVersionFile(): string {
|
||||||
const lsbFile = '/etc/lsb-release'
|
const lsbReleaseFile = '/etc/lsb-release'
|
||||||
|
const osReleaseFile = '/etc/os-release'
|
||||||
let contents = ''
|
let contents = ''
|
||||||
|
|
||||||
if (fs.existsSync(lsbFile)) {
|
if (fs.existsSync(lsbReleaseFile)) {
|
||||||
contents = fs.readFileSync(lsbFile).toString()
|
contents = fs.readFileSync(lsbReleaseFile).toString()
|
||||||
|
} else if (fs.existsSync(osReleaseFile)) {
|
||||||
|
contents = fs.readFileSync(osReleaseFile).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
return contents
|
return contents
|
||||||
|
|
Loading…
Reference in New Issue