This commit is contained in:
OpportunityLiu
2020-03-31 19:03:08 +08:00
Unverified
parent 11d52ba768
commit 2836246660
151 changed files with 0 additions and 12284 deletions
Vendored
-56
View File
@@ -1,56 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const exec_1 = require("@actions/exec");
const io = require("@actions/io");
const os = require("os");
const path = require("path");
function makeOpt(ref) {
return { cwd: path.join(os.tmpdir(), `xmake-git-${ref}`) };
}
async function lsRemote() {
let out = '';
await exec_1.exec('git', ['ls-remote', 'https://github.com/xmake-io/xmake.git'], {
silent: true,
listeners: {
stdout: d => (out += d.toString()),
},
});
const data = { heads: {}, tags: {}, pull: {} };
out.split('\n').forEach(line => {
const [ref, tag] = line.trim().split('\t');
if (ref && tag && tag.startsWith('refs/')) {
const tagPath = tag.split('/').splice(1);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let ldata = data;
for (let i = 0; i < tagPath.length - 1; i++) {
const seg = tagPath[i];
if (typeof ldata[seg] === 'object') {
ldata = ldata[seg];
}
else {
ldata = ldata[seg] = {};
}
}
ldata[tagPath[tagPath.length - 1]] = ref;
}
});
return data;
}
exports.lsRemote = lsRemote;
async function create(ref) {
const opt = makeOpt(ref);
await io.rmRF(opt.cwd);
await io.mkdirP(opt.cwd);
await exec_1.exec('git', ['init'], opt);
await exec_1.exec('git', ['remote', 'add', 'origin', 'https://github.com/xmake-io/xmake.git'], opt);
await exec_1.exec('git', ['fetch'], opt);
await exec_1.exec('git', ['checkout', ref], opt);
await exec_1.exec('git', ['submodule', 'update', '--init', '--recursive'], opt);
return opt.cwd;
}
exports.create = create;
async function cleanup(ref) {
const opt = makeOpt(ref);
await io.rmRF(opt.cwd);
}
exports.cleanup = cleanup;
-22
View File
@@ -1,22 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core = require("@actions/core");
const exec_1 = require("@actions/exec");
const os = require("os");
const versions_1 = require("./versions");
const win_install_1 = require("./win-install");
const unix_install_1 = require("./unix-install");
async function run() {
try {
const version = await versions_1.selectVersion();
if (os.platform() === 'win32' || os.platform() === 'cygwin')
await win_install_1.winInstall(version);
else
await unix_install_1.unixInstall(version);
await exec_1.exec('xmake --version');
}
catch (error) {
core.setFailed(error.message);
}
}
run().catch(e => core.error(e));
-33
View File
@@ -1,33 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core = require("@actions/core");
const exec_1 = require("@actions/exec");
const io = require("@actions/io");
const toolCache = require("@actions/tool-cache");
const os = require("os");
const path = require("path");
const semver = require("semver");
const git = require("./git");
async function unixInstall(version) {
let toolDir = toolCache.find('xmake', version.version);
if (!toolDir) {
const sourceDir = await core.group(`download xmake ${version}`, () => git.create(version.sha));
toolDir = await core.group(`install xmake ${version}`, async () => {
await exec_1.exec('make', ['build'], { cwd: sourceDir });
const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`);
await exec_1.exec('make', ['install', `prefix=${binDir}`], { cwd: sourceDir });
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', version.version);
await io.rmRF(binDir);
await git.cleanup(version.sha);
return cacheDir;
});
}
// for versions 2.3.2 and above, xmake will be installed directly into the bin directory, and no script will be used to wrap it.
if (version.type !== 'tags' || semver.gt(version.version, '2.3.1')) {
core.addPath(path.join(toolDir, 'bin'));
}
else {
core.addPath(path.join(toolDir, 'share', 'xmake')); // only for <= 2.3.1
}
}
exports.unixInstall = unixInstall;
-95
View File
@@ -1,95 +0,0 @@
"use strict";
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
};
var _string;
Object.defineProperty(exports, "__esModule", { value: true });
const core = require("@actions/core");
const semver = require("semver");
const git_1 = require("./git");
class VersionImpl {
constructor(version, sha, type, toString) {
this.version = version;
this.sha = sha;
this.type = type;
_string.set(this, void 0);
__classPrivateFieldSet(this, _string, toString);
}
toString() {
return __classPrivateFieldGet(this, _string);
}
}
_string = new WeakMap();
async function selectBranch(branch) {
const versions = await git_1.lsRemote();
if (branch in versions.heads) {
return new VersionImpl(branch, versions.heads[branch], 'heads', `branch ${branch}`);
}
throw new Error(`Branch ${branch} not found`);
}
async function selectPr(pr) {
var _a;
const versions = await git_1.lsRemote();
if (pr in versions.pull) {
const prheads = versions.pull[pr];
const sha = (_a = prheads.merge) !== null && _a !== void 0 ? _a : prheads.head;
if (sha) {
return new VersionImpl(`#${pr}`, sha, 'pull', `pull request #${pr}`);
}
}
throw new Error(`Pull requrest #${pr} not found`);
}
async function selectSemver(version) {
// check version valid
const v = new semver.Range(version);
if (!v) {
throw new Error(`Invalid semver`);
}
const versions = await git_1.lsRemote();
const ver = semver.maxSatisfying(Object.keys(versions.tags), v);
if (!ver) {
throw new Error(`No matched releases of xmake-version ${v.format()}`);
}
const sha = versions.tags[ver];
return new VersionImpl(ver, sha, 'tags', ver);
}
async function selectVersion(version) {
// get version string
version = (version !== null && version !== void 0 ? version : core.getInput('xmake-version')) || 'latest';
if (version.toLowerCase() === 'latest')
version = '';
let ret;
// select branch
if (version.startsWith('branch@')) {
const branch = version.substr('branch@'.length);
ret = await selectBranch(branch);
}
// select pr
if (version.startsWith('pr@')) {
const pr = Number.parseInt(version.substr('pr@'.length));
if (Number.isNaN(pr) || pr <= 0) {
throw new Error(`Invalid pull requrest ${version.substr('pr@'.length)}, should be a positive integer`);
}
ret = await selectPr(pr);
}
// select version
if (semver.validRange(version)) {
ret = await selectSemver(version);
}
if (!ret) {
throw new Error(`Invalid input xmake-version ${core.getInput('xmake-version')}`);
}
core.info(`Selected xmake ${ret} (commit: ${ret.sha.substr(0, 8)})`);
return ret;
}
exports.selectVersion = selectVersion;
-50
View File
@@ -1,50 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core = require("@actions/core");
const exec_1 = require("@actions/exec");
const io = require("@actions/io");
const toolCache = require("@actions/tool-cache");
const os = require("os");
const path = require("path");
const semver = require("semver");
async function winInstall(version) {
let toolDir = toolCache.find('xmake', version.version);
if (!toolDir) {
const installer = await core.group(`download xmake ${version}`, async () => {
let url = '';
if (version.type === 'heads') {
// we only use appveyor ci artifacts for branch version
const arch = os.arch() === 'x64' ? 'x64' : 'x86';
url = `https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?branch=${version.version}&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+${arch}`;
}
else if (version.type === 'pull') {
throw new Error('PR builds for windows is not supported');
}
else {
// we cannot use appveyor ci artifacts, the old version links may be broken.
const arch = os.arch() === 'x64' ? 'win64' : 'win32';
url = semver.gt(version.version, '2.2.6')
? `https://github.com/xmake-io/xmake/releases/download/v${version}/xmake-v${version}.${arch}.exe`
: `https://github.com/xmake-io/xmake/releases/download/v${version}/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 io.mv(file, exe);
core.info(`downloaded to ${exe}`);
return exe;
});
toolDir = await core.group(`install xmake ${version}`, async () => {
const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`);
core.info(`installing to ${binDir}`);
await exec_1.exec(`"${installer}" /NOADMIN /S /D=${binDir}`);
core.info(`installed to ${binDir}`);
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', version.version);
await io.rmRF(binDir);
await io.rmRF(installer);
return cacheDir;
});
}
core.addPath(toolDir);
}
exports.winInstall = winInstall;