1
0
Fork 0

feat: get linux version from os-release file if available (#594)

pull/823/head
Sergey Ukustov 2021-05-28 22:40:45 +03:00 committed by GitHub
parent c507914181
commit e1a7863be6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 6 deletions

View File

@ -116,7 +116,7 @@ describe('@actions/tool-cache-manifest', () => {
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.arch = 'x64'
@ -150,6 +150,48 @@ describe('@actions/tool-cache-manifest', () => {
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 () => {
os.platform = 'darwin'
os.arch = 'x64'

View File

@ -135,8 +135,15 @@ export function _getOsVersion(): string {
const lines = lsbContents.split('\n')
for (const line of lines) {
const parts = line.split('=')
if (parts.length === 2 && parts[0].trim() === 'DISTRIB_RELEASE') {
version = parts[1].trim()
if (
parts.length === 2 &&
(parts[0].trim() === 'VERSION_ID' ||
parts[0].trim() === 'DISTRIB_RELEASE')
) {
version = parts[1]
.trim()
.replace(/^"/, '')
.replace(/"$/, '')
break
}
}
@ -147,11 +154,14 @@ export function _getOsVersion(): string {
}
export function _readLinuxVersionFile(): string {
const lsbFile = '/etc/lsb-release'
const lsbReleaseFile = '/etc/lsb-release'
const osReleaseFile = '/etc/os-release'
let contents = ''
if (fs.existsSync(lsbFile)) {
contents = fs.readFileSync(lsbFile).toString()
if (fs.existsSync(lsbReleaseFile)) {
contents = fs.readFileSync(lsbReleaseFile).toString()
} else if (fs.existsSync(osReleaseFile)) {
contents = fs.readFileSync(osReleaseFile).toString()
}
return contents