support sha
This commit is contained in:
Vendored
+34
-5
@@ -17,6 +17,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = require("@actions/core");
|
||||
const semver = require("semver");
|
||||
const git_1 = require("./git");
|
||||
let VERSIONS;
|
||||
async function getVersions() {
|
||||
if (VERSIONS)
|
||||
return VERSIONS;
|
||||
return (VERSIONS = await git_1.lsRemote());
|
||||
}
|
||||
class VersionImpl {
|
||||
constructor(version, sha, type, toString) {
|
||||
this.version = version;
|
||||
@@ -31,19 +37,20 @@ class VersionImpl {
|
||||
}
|
||||
_string = new WeakMap();
|
||||
async function selectBranch(branch) {
|
||||
const versions = await git_1.lsRemote();
|
||||
const versions = await getVersions();
|
||||
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) {
|
||||
const versions = await git_1.lsRemote();
|
||||
var _a;
|
||||
const versions = await getVersions();
|
||||
if (pr in versions.pull) {
|
||||
const prheads = versions.pull[pr];
|
||||
const sha = prheads.head;
|
||||
const sha = (_a = prheads.merge) !== null && _a !== void 0 ? _a : prheads.head;
|
||||
if (sha) {
|
||||
return new VersionImpl(`#${pr}`, sha, 'pull', `pull request #${pr}`);
|
||||
return new VersionImpl(`pr#${pr}`, sha, 'pull', `pull request #${pr}`);
|
||||
}
|
||||
}
|
||||
throw new Error(`Pull requrest #${pr} not found`);
|
||||
@@ -54,7 +61,7 @@ async function selectSemver(version) {
|
||||
if (!v) {
|
||||
throw new Error(`Invalid semver`);
|
||||
}
|
||||
const versions = await git_1.lsRemote();
|
||||
const versions = await getVersions();
|
||||
const ver = semver.maxSatisfying(Object.keys(versions.tags), v);
|
||||
if (!ver) {
|
||||
throw new Error(`No matched releases of xmake-version ${v.format()}`);
|
||||
@@ -62,6 +69,23 @@ async function selectSemver(version) {
|
||||
const sha = versions.tags[ver];
|
||||
return new VersionImpl(ver, sha, 'tags', ver);
|
||||
}
|
||||
async function selectSha(sha) {
|
||||
sha = sha.toLowerCase();
|
||||
if (!/^[a-f0-9]{40}$/gi.test(sha))
|
||||
throw new Error(`Invalid sha value ${sha}`);
|
||||
const versions = await getVersions();
|
||||
for (const branch in versions.heads) {
|
||||
if (versions.heads[branch] === sha) {
|
||||
return selectBranch(branch);
|
||||
}
|
||||
}
|
||||
for (const tag in versions.tags) {
|
||||
if (versions.tags[tag] === sha) {
|
||||
return selectSemver(tag);
|
||||
}
|
||||
}
|
||||
return Promise.resolve(new VersionImpl(`sha#${sha}`, sha, 'sha', `commit ${sha.substr(0, 8)}`));
|
||||
}
|
||||
async function selectVersion(version) {
|
||||
// get version string
|
||||
version = (version !== null && version !== void 0 ? version : core.getInput('xmake-version')) || 'latest';
|
||||
@@ -81,6 +105,11 @@ async function selectVersion(version) {
|
||||
}
|
||||
ret = await selectPr(pr);
|
||||
}
|
||||
// select sha
|
||||
if (version.startsWith('sha@')) {
|
||||
const sha = version.substr('sha@'.length);
|
||||
ret = await selectSha(sha);
|
||||
}
|
||||
// select version
|
||||
if (semver.validRange(version)) {
|
||||
ret = await selectSemver(version);
|
||||
|
||||
Reference in New Issue
Block a user