use ts
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
import { exec } from '@actions/exec'
|
||||
import * as io from '@actions/io'
|
||||
import * as os from 'os'
|
||||
import * as path from 'path'
|
||||
|
||||
export const folder = path.join(os.tmpdir(), `xmake${Date.now()}`)
|
||||
const opt = { cwd: folder }
|
||||
const a = 12_12_12
|
||||
|
||||
export async function create(ref: string) {
|
||||
await io.rmRF(folder)
|
||||
await io.mkdirP(folder)
|
||||
await exec('git', ['init'], opt)
|
||||
await exec('git', ['remote', 'add', 'origin', 'https://github.com/xmake-io/xmake.git'], opt)
|
||||
await exec('git', ['fetch'], opt)
|
||||
await exec('git', ['checkout', ref], opt)
|
||||
await exec('git', ['submodule', 'update', '--init', '--recursive'], opt)
|
||||
return folder
|
||||
}
|
||||
|
||||
export async function cleanup() {
|
||||
await io.rmRF(folder)
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import * as core from '@actions/core'
|
||||
import { exec } from '@actions/exec'
|
||||
import * as _fs from 'fs'
|
||||
const fs = _fs.promises
|
||||
import * as io from '@actions/io'
|
||||
import * as toolCache from '@actions/tool-cache'
|
||||
import * as os from 'os'
|
||||
import * as path from 'path'
|
||||
import * as semver from 'semver'
|
||||
import * as git from './git'
|
||||
import { selectVersion } from './versions'
|
||||
|
||||
async function winInstall(version: string) {
|
||||
let toolDir = toolCache.find('xmake', version)
|
||||
if (!toolDir) {
|
||||
const installer = await core.group("download xmake", async () => {
|
||||
const arch = os.arch() === 'x64' ? 'x64' : 'x86'
|
||||
const url = semver.gt(version, '2.2.6')
|
||||
? `https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?tag=v${version}&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+${arch}`
|
||||
: `https://github.com/xmake-io/xmake/releases/download/v$v/xmake-v${version}.exe`
|
||||
core.info(`downloading from ${url}`)
|
||||
const file = await toolCache.downloadTool(url)
|
||||
const exe = path.format({ ...path.parse(file), ext: '.exe', base: undefined })
|
||||
await fs.rename(file, exe)
|
||||
core.info(`downloaded to ${exe}`)
|
||||
return exe
|
||||
})
|
||||
toolDir = await core.group("install xmake", async () => {
|
||||
const binDir = path.join(os.tmpdir(), `xmake-${version}`)
|
||||
core.info(`installing to ${binDir}`)
|
||||
await exec(`"${installer}" /NOADMIN /S /D=${binDir}`)
|
||||
core.info(`installed to ${binDir}`)
|
||||
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', version)
|
||||
await io.rmRF(binDir)
|
||||
await io.rmRF(installer)
|
||||
return cacheDir
|
||||
})
|
||||
}
|
||||
core.addPath(toolDir)
|
||||
}
|
||||
|
||||
async function unixInstall(version: string, sha: string) {
|
||||
let toolDir = toolCache.find('xmake', version)
|
||||
if (!toolDir) {
|
||||
const sourceDir = await core.group("download xmake", () => git.create(sha))
|
||||
toolDir = await core.group("install xmake", async () => {
|
||||
await exec('make', ['build'], { cwd: sourceDir })
|
||||
const binDir = path.join(os.tmpdir(), `xmake-${version}-${sha}`)
|
||||
await exec('make', ['install', `prefix=${binDir}`], { cwd: sourceDir })
|
||||
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', version)
|
||||
await io.rmRF(binDir)
|
||||
await git.cleanup()
|
||||
return cacheDir
|
||||
})
|
||||
}
|
||||
core.addPath(path.join(toolDir, 'share', 'xmake'))
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const { version, sha } = selectVersion()
|
||||
if (os.platform() === 'win32' || os.platform() === 'cygwin')
|
||||
await winInstall(version)
|
||||
else
|
||||
await unixInstall(version, sha)
|
||||
await exec('xmake --version')
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
||||
@@ -0,0 +1,44 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as semver from 'semver'
|
||||
|
||||
export const versions: { [v: string]: string } = {
|
||||
"1.0.1": "723ec3e970e17f48a601fe2a919b9802b5e516fa",
|
||||
"1.0.2": "84fa20ca3ded99b9667609c5cb2e56b2308c8e4b",
|
||||
"1.0.3": "e56812a09d3677957c41bccc8988599208e3b49a",
|
||||
"1.0.4": "825dda9d93448ba783e18f7947eef0b4eb07942e",
|
||||
"2.0.1": "432fd6a40018f4c29e08f1d4cadf1ccc387a0cff",
|
||||
"2.0.2": "d24fcddbc2f1093f3943a917d99c5a8989ef2644",
|
||||
"2.0.3": "b5f21a05b1cdaf46314238b4cc665976294df1da",
|
||||
"2.0.4": "2b15a1b5b149e5156e22358f3d29b4de63473376",
|
||||
"2.0.5": "b168ce05d763957ed05844141d77d155bf842e7a",
|
||||
"2.1.1": "5ba22ca230c3f3f9477491df6d39f11d53132fb1",
|
||||
"2.1.2": "bf69a2413117cf21c53bde1edbda713e77d4fd9b",
|
||||
"2.1.3": "248b2cc8a96d41445a2e46d259d14fea8e4203ec",
|
||||
"2.1.4": "1d94a23a7db35631f4b33b8b0b3968d0e62ffe2a",
|
||||
"2.1.5": "72f68f941f9b6d07f71811fe403a2dc178270af0",
|
||||
"2.1.6": "7ea60d24da152469258a4cb35b3ce591ea2fd961",
|
||||
"2.1.7": "a04725662933fbbe3ad4a319d03267fc32907242",
|
||||
"2.1.8": "6c3f42dad5840210ee7294ca295f6c7b18c32291",
|
||||
"2.1.9": "0f1e8530e89a9432678ed6fe4fef25d0485d1293",
|
||||
"2.2.1": "f15ff1ca73b02ff5f522c9fe59004331b1b410fb",
|
||||
"2.2.2": "18a42e0e8980e3edc39198b18c5c4b9a464ea381",
|
||||
"2.2.3": "c4d0e69abf2b9caa88b997ca1f2935b6e0b00c9f",
|
||||
"2.2.5": "d71a01615883fffa53fbd28e578db14353628a52",
|
||||
"2.2.6": "eb60a76b7454975d151f2d8b5d9e19b26d561c2d",
|
||||
"2.2.7": "72bd93de8dd64cc5de8986860819a5873ce08fe5",
|
||||
"2.2.8": "6a2e390a79c4f0444a03b566d4bf24849a6ee3a3",
|
||||
}
|
||||
|
||||
export function selectVersion(version?: string) {
|
||||
version = version || core.getInput('xmake-version') || 'latest'
|
||||
if (version.toLowerCase() === 'latest') version = ''
|
||||
version = semver.validRange(version)
|
||||
if (!version) throw new Error(`Invalid input xmake-version: ${core.getInput('xmake-version')}`)
|
||||
|
||||
const ver = semver.maxSatisfying(Object.keys(versions), version)
|
||||
if (!ver) throw new Error(`No matched releases of xmake-version: ${version}`)
|
||||
|
||||
const sha = versions[ver]
|
||||
core.info(`selected xmake v${ver} (commit: ${sha.substr(0, 8)})`)
|
||||
return { version: ver, sha }
|
||||
}
|
||||
Reference in New Issue
Block a user