use ls-remote
This commit is contained in:
Vendored
+17
@@ -6,6 +6,23 @@ const os = require("os");
|
||||
const path = require("path");
|
||||
exports.folder = path.join(os.tmpdir(), `xmake${Date.now()}`);
|
||||
const opt = { cwd: exports.folder };
|
||||
async function lsRemote() {
|
||||
let out = '';
|
||||
await exec_1.exec('git', ['ls-remote', '--tags', 'https://github.com/xmake-io/xmake.git'], {
|
||||
listeners: {
|
||||
stdout: d => (out += d.toString()),
|
||||
},
|
||||
});
|
||||
const data = {};
|
||||
out.split('\n').forEach(line => {
|
||||
const [ref, tag] = line.trim().split('\t');
|
||||
if (ref && tag && tag.startsWith('refs/tags/v')) {
|
||||
data[tag.substring('refs/tags/v'.length)] = ref;
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}
|
||||
exports.lsRemote = lsRemote;
|
||||
async function create(ref) {
|
||||
await io.rmRF(exports.folder);
|
||||
await io.mkdirP(exports.folder);
|
||||
|
||||
Vendored
+5
-5
@@ -14,7 +14,7 @@ const versions_1 = require("./versions");
|
||||
async function winInstall(version) {
|
||||
let toolDir = toolCache.find('xmake', version);
|
||||
if (!toolDir) {
|
||||
const installer = await core.group("download xmake", async () => {
|
||||
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}`
|
||||
@@ -26,7 +26,7 @@ async function winInstall(version) {
|
||||
core.info(`downloaded to ${exe}`);
|
||||
return exe;
|
||||
});
|
||||
toolDir = await core.group("install xmake", async () => {
|
||||
toolDir = await core.group('install xmake', async () => {
|
||||
const binDir = path.join(os.tmpdir(), `xmake-${version}`);
|
||||
core.info(`installing to ${binDir}`);
|
||||
await exec_1.exec(`"${installer}" /NOADMIN /S /D=${binDir}`);
|
||||
@@ -42,8 +42,8 @@ async function winInstall(version) {
|
||||
async function unixInstall(version, sha) {
|
||||
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 () => {
|
||||
const sourceDir = await core.group('download xmake', () => git.create(sha));
|
||||
toolDir = await core.group('install xmake', 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 });
|
||||
@@ -68,4 +68,4 @@ async function run() {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
run();
|
||||
run().catch(e => core.error(e));
|
||||
|
||||
Vendored
+6
-17
@@ -2,27 +2,16 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = require("@actions/core");
|
||||
const semver = require("semver");
|
||||
const tool_cache_1 = require("@actions/tool-cache");
|
||||
const _fs = require("fs");
|
||||
const fs = _fs.promises;
|
||||
async function fetchVersions() {
|
||||
const file = await tool_cache_1.downloadTool("https://api.github.com/repos/xmake-io/xmake/git/refs/tags");
|
||||
const tags = JSON.parse(await fs.readFile(file, { encoding: "utf-8" }));
|
||||
return tags.map(({ ref, object: { sha } }) => [ref.slice(11), sha]).reduce((o, [k, v]) => {
|
||||
o[k] = v;
|
||||
return o;
|
||||
}, {});
|
||||
}
|
||||
exports.fetchVersions = fetchVersions;
|
||||
const git_1 = require("./git");
|
||||
async function selectVersion(version) {
|
||||
version = version || core.getInput("xmake-version") || "latest";
|
||||
if (version.toLowerCase() === "latest")
|
||||
version = "";
|
||||
version = (version !== null && version !== void 0 ? 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")}`);
|
||||
throw new Error(`Invalid input xmake-version: ${core.getInput('xmake-version')}`);
|
||||
}
|
||||
const versions = await fetchVersions();
|
||||
const versions = await git_1.lsRemote();
|
||||
const ver = semver.maxSatisfying(Object.keys(versions), version);
|
||||
if (!ver) {
|
||||
throw new Error(`No matched releases of xmake-version: ${version}`);
|
||||
|
||||
Reference in New Issue
Block a user