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} Returns the path of the downloaded clang binary */ export async function download(version: string): Promise { 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 { const http = new httpm.HttpClient('siteorg/setup-clang') const url = 'https://api.github.com/repos/llvm/llvm-project/releases' const response = await http.getJson(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-', '') }