Initial Commit
Some checks failed
Continuous Integration / GitHub Actions Test (push) Successful in 23s
CodeQL / Analyze (TypeScript) (push) Failing after 5m27s
Check Transpiled JavaScript / Check dist/ (push) Has been cancelled
Continuous Integration / TypeScript Tests (push) Has been cancelled
Lint Codebase / Lint Codebase (push) Has been cancelled

This commit is contained in:
2024-11-05 23:08:13 +13:00
commit 42fb744b4f
38 changed files with 38124 additions and 0 deletions

75
src/download.ts Normal file
View File

@@ -0,0 +1,75 @@
import * as tc from '@actions/tool-cache'
import * as core from '@actions/core'
import * as util from './util'
import * as httpm from '@actions/http-client'
import { GitHubRelease } from './github-release'
/**
* Download a specific version of the Conan.
* @param version The version to download
* @returns {Promise<string>} Returns the path of the downloaded conan binary
*/
export async function download(version: string): Promise<string> {
const platform = util.getConanPlatform()
const architecture = util.getConanArchitecture()
const extension = util.getPlatformExtension()
const findCachedPath = tc.find('conan', version)
if (findCachedPath !== '') {
core.info(`Using cached Conan ${version} (${platform}, ${architecture})`)
return findCachedPath
}
const url = `https://github.com/conan-io/conan/releases/download/${version}/conan-${version}-${platform}-${architecture}.${extension}`
core.info(
`Downloading Conan ${version} (${platform}, ${architecture}) from ${url} ...`
)
const archivePath = await tc.downloadTool(url)
core.info(`Extracting Conan archive...`)
let extractedPath
if (platform == 'windows') {
extractedPath = await tc.extractZip(archivePath)
} else {
extractedPath = await tc.extractTar(archivePath)
}
const cachedPath = await tc.cacheDir(extractedPath, 'conan', version)
return cachedPath
}
export async function getLatestVersion(): Promise<string> {
const http = new httpm.HttpClient('siteorg/setup-conan')
const url = 'https://api.github.com/repos/conan-io/conan/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
}

94
src/github-release.ts Normal file
View File

@@ -0,0 +1,94 @@
export interface GitHubRelease {
url: string
assets_url: string
upload_url: string
html_url: string
id: number
author: Author
node_id: string
tag_name: string
target_commitish: string
name: string
draft: boolean
prerelease: boolean
created_at: string
published_at: string
assets: Asset[]
tarball_url: string
zipball_url: string
body: string
reactions: Reactions
}
export interface Author {
login: string
id: number
node_id: string
avatar_url: string
gravatar_id: string
url: string
html_url: string
followers_url: string
following_url: string
gists_url: string
starred_url: string
subscriptions_url: string
organizations_url: string
repos_url: string
events_url: string
received_events_url: string
type: string
user_view_type: string
site_admin: boolean
}
export interface Asset {
url: string
id: number
node_id: string
name: string
label: string
uploader: Uploader
content_type: string
state: string
size: number
download_count: number
created_at: string
updated_at: string
browser_download_url: string
}
export interface Uploader {
login: string
id: number
node_id: string
avatar_url: string
gravatar_id: string
url: string
html_url: string
followers_url: string
following_url: string
gists_url: string
starred_url: string
subscriptions_url: string
organizations_url: string
repos_url: string
events_url: string
received_events_url: string
type: string
user_view_type: string
site_admin: boolean
}
export interface Reactions {
url: string
total_count: number
'+1': number
'-1': number
laugh: number
hooray: number
confused: number
heart: number
rocket: number
eyes: number
}

7
src/index.ts Normal file
View File

@@ -0,0 +1,7 @@
/**
* The entrypoint for the action.
*/
import { run } from './main'
// eslint-disable-next-line @typescript-eslint/no-floating-promises
run()

21
src/main.ts Normal file
View File

@@ -0,0 +1,21 @@
import * as core from '@actions/core'
import { download, getLatestVersion } from './download'
/**
* The main function for the action.
* @returns {Promise<void>} Resolves when the action is complete.
*/
export async function run(): Promise<void> {
try {
let conanVersion: string = core.getInput('conan-version')
if (conanVersion === '') {
conanVersion = await getLatestVersion()
}
const path = await download(conanVersion)
core.addPath(path)
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
}
}

30
src/util.ts Normal file
View File

@@ -0,0 +1,30 @@
export function getPlatformExtension(): string {
switch (process.platform) {
case 'win32':
return 'zip'
default:
return 'tgz'
}
}
export function getConanArchitecture(): string {
switch (process.arch) {
case 'x64':
return 'x86_64'
case 'ia32':
return 'i686'
default:
return process.arch
}
}
export function getConanPlatform(): string {
switch (process.platform) {
case 'win32':
return 'windows'
case 'darwin':
return 'macos'
default:
return 'linux'
}
}