Initial Commit
Some checks failed
Some checks failed
This commit is contained in:
76
src/download.ts
Normal file
76
src/download.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
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}-aarch64-linux-gnu.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)
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user