Files
setup-clang/src/download.ts
Lucas Petrino 24ecf016df
Some checks failed
Check Transpiled JavaScript / Check dist/ (push) Successful in 1m2s
Continuous Integration / TypeScript Tests (push) Successful in 1m5s
Continuous Integration / GitHub Actions Test (push) Failing after 1m20s
fix: archive extraction
2024-11-17 12:01:17 +13:00

77 lines
2.1 KiB
TypeScript

import * as tc from '@actions/tool-cache'
import * as core from '@actions/core'
import * as httpm from '@actions/http-client'
import { GitHubRelease } from './github-release'
/**
* Download a specific version of the Clang.
* @param version The version to download
* @returns {Promise<string>} Returns the path of the downloaded clang binary
*/
export async function download(version: string): Promise<string> {
const findCachedPath = tc.find('clang', version)
if (findCachedPath !== '') {
core.info(
`Using cached Clang ${version} (${process.platform}, ${process.arch})`
)
return findCachedPath
}
let path
switch (process.platform) {
case 'win32':
path = `clang+llvm-${version}-x86_64-pc-windows-msvc.tar.xz`
break
default:
path = `clang+llvm-${version}-x86_64-linux-gnu-ubuntu-18.04.tar.xz`
break
}
const url = `https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/${path}`
core.info(
`Downloading Clang ${version} (${process.platform}, ${process.arch}) from ${url} ...`
)
const archivePath = await tc.downloadTool(url)
core.info(`Extracting Clang archive...`)
const extractedPath = await tc.extractTar(archivePath, undefined, 'xf')
const cachedPath = await tc.cacheDir(extractedPath, 'clang', version)
return cachedPath
}
export async function getLatestVersion(): Promise<string> {
const http = new httpm.HttpClient('siteorg/setup-clang')
const url = 'https://api.github.com/repos/llvm/llvm-project/releases'
const response = await http.getJson<GitHubRelease[]>(url)
if (!(response.statusCode == 200)) {
throw new Error(
`GitHub API request failed with status ${response.statusCode}`
)
}
const releaseData = response.result
if (releaseData == null) {
throw new Error('No releases found.')
}
const stableReleases = releaseData.filter(release => !release.prerelease)
if (stableReleases.length === 0) {
throw new Error('No stable releases found.')
}
const latestStableRelease = stableReleases[0]
const latestReleaseTag = latestStableRelease.tag_name
return latestReleaseTag.replace('llvmorg-', '')
}