Initial Commit
Some checks failed
Lint Codebase / Lint Codebase (push) Has been cancelled
Continuous Integration / GitHub Actions Test (push) Failing after 20s
Check Transpiled JavaScript / Check dist/ (push) Successful in 1m9s
Continuous Integration / TypeScript Tests (push) Successful in 1m17s

This commit is contained in:
2024-11-17 11:50:58 +13:00
commit 06249bf357
34 changed files with 37991 additions and 0 deletions

76
src/download.ts Normal file
View 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
}