Merge pull request #43 from Redbeanw44602/master
Add fallback to winInstall.
This commit is contained in:
@@ -142,6 +142,6 @@ git branch test
|
|||||||
git checkout test
|
git checkout test
|
||||||
pnpm build
|
pnpm build
|
||||||
pnpm release
|
pnpm release
|
||||||
git-commit -a -m "..."
|
git commit -a -m "..."
|
||||||
git push origin test
|
git push origin test
|
||||||
```
|
```
|
||||||
|
|||||||
Vendored
+5406
-5513
File diff suppressed because one or more lines are too long
+31
-16
@@ -3,6 +3,7 @@ import * as io from '@actions/io';
|
|||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { Sha, RefDic, Repo } from './interfaces';
|
import { Sha, RefDic, Repo } from './interfaces';
|
||||||
|
import { valid as isValidSemver } from 'semver';
|
||||||
|
|
||||||
function makeOpt(ref: Sha): { cwd: string } {
|
function makeOpt(ref: Sha): { cwd: string } {
|
||||||
return { cwd: path.join(os.tmpdir(), `xmake-git-${ref}`) };
|
return { cwd: path.join(os.tmpdir(), `xmake-git-${ref}`) };
|
||||||
@@ -20,24 +21,38 @@ export async function lsRemote(repo: Repo): Promise<RefDic> {
|
|||||||
});
|
});
|
||||||
const data: RefDic = { heads: {}, tags: {}, pull: {} };
|
const data: RefDic = { heads: {}, tags: {}, pull: {} };
|
||||||
out.split('\n').forEach((line) => {
|
out.split('\n').forEach((line) => {
|
||||||
const [ref, tag] = line.trim().split('\t');
|
const [ref, path] = line.trim().split('\t') as [Sha, string];
|
||||||
if (ref && tag?.startsWith('refs/')) {
|
if (ref && path?.startsWith('refs/')) {
|
||||||
const tagPath = tag.split('/').splice(1);
|
const tagPath = path.split('/').splice(1);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
switch (tagPath[0]) {
|
||||||
let ldata = data as any; // eslint-disable-line @typescript-eslint/no-unsafe-assignment
|
case 'heads': {
|
||||||
for (let i = 0; i < tagPath.length - 1; i++) {
|
// refs/heads/copilot/fix-6807
|
||||||
const seg = tagPath[i];
|
const head = tagPath.slice(1).join('/');
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
data.heads[head] = ref;
|
||||||
if (typeof ldata[seg] === 'object') {
|
break;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
||||||
ldata = ldata[seg]; // eslint-disable-line @typescript-eslint/no-unsafe-assignment
|
|
||||||
} else {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
||||||
ldata = ldata[seg] = {};
|
|
||||||
}
|
}
|
||||||
|
case 'pull': {
|
||||||
|
// refs/pull/11/head
|
||||||
|
// refs/pull/11/merge
|
||||||
|
const pr = Number(tagPath[1]);
|
||||||
|
if (!data.pull[pr]) {
|
||||||
|
data.pull[pr] = {} as RefDic['pull'][number];
|
||||||
|
}
|
||||||
|
data.pull[pr][tagPath[2] as 'head' | 'merge'] = ref;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'tags': {
|
||||||
|
// refs/tags/preview
|
||||||
|
// refs/tags/v3.0.3
|
||||||
|
const tag = tagPath.slice(1).join('/');
|
||||||
|
if (isValidSemver(tag)) {
|
||||||
|
data.tags[tag] = ref;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
||||||
ldata[tagPath[tagPath.length - 1]] = ref;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
+1
-2
@@ -7,8 +7,7 @@ import { unixInstall } from './unix-install';
|
|||||||
export async function installXmake(): Promise<void> {
|
export async function installXmake(): Promise<void> {
|
||||||
const version = await selectVersion();
|
const version = await selectVersion();
|
||||||
if (os.platform() === 'win32' || os.platform() === 'cygwin') {
|
if (os.platform() === 'win32' || os.platform() === 'cygwin') {
|
||||||
const latest = await selectVersion('latest');
|
await winInstall(version);
|
||||||
await winInstall(version, latest);
|
|
||||||
} else {
|
} else {
|
||||||
await unixInstall(version);
|
await unixInstall(version);
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-8
@@ -96,11 +96,11 @@ async function selectSha(repo: Repo, sha: string): Promise<Version> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Promise.resolve(
|
return Promise.resolve(
|
||||||
new GitVersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substr(0, 8)}`),
|
new GitVersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substring(0, 8)}`),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function selectVersion(version?: string): Promise<Version> {
|
export async function selectVersion(version?: string, _fallback: boolean = false): Promise<Version> {
|
||||||
// get version string
|
// get version string
|
||||||
version = (version ?? core.getInput('xmake-version')) || 'latest';
|
version = (version ?? core.getInput('xmake-version')) || 'latest';
|
||||||
if (version.toLowerCase() === 'latest') version = '';
|
if (version.toLowerCase() === 'latest') version = '';
|
||||||
@@ -123,20 +123,20 @@ export async function selectVersion(version?: string): Promise<Version> {
|
|||||||
|
|
||||||
// select branch
|
// select branch
|
||||||
if (version.startsWith('branch@')) {
|
if (version.startsWith('branch@')) {
|
||||||
const branch = version.substr('branch@'.length);
|
const branch = version.substring('branch@'.length);
|
||||||
ret = await selectBranch(repo, branch);
|
ret = await selectBranch(repo, branch);
|
||||||
}
|
}
|
||||||
// select pr
|
// select pr
|
||||||
if (version.startsWith('pr@')) {
|
if (version.startsWith('pr@')) {
|
||||||
const pr = Number.parseInt(version.substr('pr@'.length));
|
const pr = Number.parseInt(version.substring('pr@'.length));
|
||||||
if (Number.isNaN(pr) || pr <= 0) {
|
if (Number.isNaN(pr) || pr <= 0) {
|
||||||
throw new Error(`Invalid pull requrest ${version.substr('pr@'.length)}, should be a positive integer`);
|
throw new Error(`Invalid pull requrest ${version.substring('pr@'.length)}, should be a positive integer`);
|
||||||
}
|
}
|
||||||
ret = await selectPr(repo, pr);
|
ret = await selectPr(repo, pr);
|
||||||
}
|
}
|
||||||
// select sha
|
// select sha
|
||||||
if (version.startsWith('sha@')) {
|
if (version.startsWith('sha@')) {
|
||||||
const sha = version.substr('sha@'.length);
|
const sha = version.substring('sha@'.length);
|
||||||
ret = await selectSha(repo, sha);
|
ret = await selectSha(repo, sha);
|
||||||
}
|
}
|
||||||
// select version
|
// select version
|
||||||
@@ -148,9 +148,9 @@ export async function selectVersion(version?: string): Promise<Version> {
|
|||||||
}
|
}
|
||||||
if (ret.type === 'local') {
|
if (ret.type === 'local') {
|
||||||
core.info(`Use local xmake at '${ret.path}'`);
|
core.info(`Use local xmake at '${ret.path}'`);
|
||||||
} else {
|
} else if (!_fallback) {
|
||||||
core.info(
|
core.info(
|
||||||
`Selected xmake ${String(ret)} (commit: ${ret.sha.substr(0, 8)})` +
|
`Selected xmake ${String(ret)} (commit: ${ret.sha.substring(0, 8)})` +
|
||||||
(repo !== DEFAULT_REPO ? ` of ${repo}` : ''),
|
(repo !== DEFAULT_REPO ? ` of ${repo}` : ''),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-12
@@ -9,18 +9,22 @@ import * as path from 'path';
|
|||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import * as git from './git';
|
import * as git from './git';
|
||||||
import { Version, GitVersion } from './interfaces';
|
import { Version, GitVersion } from './interfaces';
|
||||||
|
import { selectVersion } from './versions';
|
||||||
import { getPlatformIdentifier } from './system';
|
import { getPlatformIdentifier } from './system';
|
||||||
|
|
||||||
function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
|
async function getInstallerUrl(version: GitVersion, _fallback: boolean = false): Promise<string> {
|
||||||
let ver = version.version;
|
const latest = (await selectVersion('latest', _fallback)) as GitVersion;
|
||||||
|
const latestVers = latest.version;
|
||||||
|
let vers = version.version;
|
||||||
|
let finalUrl: string;
|
||||||
switch (version.type) {
|
switch (version.type) {
|
||||||
case 'heads': {
|
case 'heads': {
|
||||||
const arch = os.arch() === 'arm64' ? 'arm64' : os.arch() === 'x64' ? 'win64' : 'win32';
|
const arch = os.arch() === 'arm64' ? 'arm64' : os.arch() === 'x64' ? 'win64' : 'win32';
|
||||||
const latestver = latest.version;
|
if (vers !== 'dev' && vers !== 'master') {
|
||||||
if (ver !== 'dev' && ver !== 'master') {
|
vers = latestVers;
|
||||||
ver = latestver;
|
|
||||||
}
|
}
|
||||||
return `https://github.com/xmake-io/xmake/releases/download/${latestver}/xmake-${ver}.${arch}.exe`;
|
finalUrl = `https://github.com/xmake-io/xmake/releases/download/${latestVers}/xmake-${vers}.${arch}.exe`;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case 'pull': {
|
case 'pull': {
|
||||||
throw new Error('PR builds for windows is not supported');
|
throw new Error('PR builds for windows is not supported');
|
||||||
@@ -30,9 +34,10 @@ function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
|
|||||||
}
|
}
|
||||||
case 'tags': {
|
case 'tags': {
|
||||||
const arch = os.arch() === 'arm64' ? 'arm64' : os.arch() === 'x64' ? 'win64' : 'win32';
|
const arch = os.arch() === 'arm64' ? 'arm64' : os.arch() === 'x64' ? 'win64' : 'win32';
|
||||||
return semver.gt(ver, '2.2.6')
|
finalUrl = semver.gt(vers, '2.2.6')
|
||||||
? `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.${arch}.exe`
|
? `https://github.com/xmake-io/xmake/releases/download/${vers}/xmake-${vers}.${arch}.exe`
|
||||||
: `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.exe`;
|
: `https://github.com/xmake-io/xmake/releases/download/${vers}/xmake-${vers}.exe`;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
// check that we have tested all types
|
// check that we have tested all types
|
||||||
@@ -40,6 +45,21 @@ function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
|
|||||||
throw new Error('Unknown version type');
|
throw new Error('Unknown version type');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// check if the URL returns 404. If so, xmake may have just released a
|
||||||
|
// new version, causing some binaries to be temporarily unavailable, so
|
||||||
|
// we need to fallback to the previous version.
|
||||||
|
if (!_fallback) {
|
||||||
|
const head = await fetch(finalUrl, { method: 'HEAD' });
|
||||||
|
if (head.status === 404) {
|
||||||
|
const currentVers = latestVers || vers;
|
||||||
|
const previousVersion = (await selectVersion('<' + currentVers)) as GitVersion;
|
||||||
|
core.warning(
|
||||||
|
`The requested version ${currentVers} (${finalUrl}) resource is temporarily unavailable, trying to fallback to the previous version...`,
|
||||||
|
);
|
||||||
|
return await getInstallerUrl(previousVersion, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return finalUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function installFromSource(xmakeBin: string, sourceDir: string, binDir: string): Promise<void> {
|
async function installFromSource(xmakeBin: string, sourceDir: string, binDir: string): Promise<void> {
|
||||||
@@ -47,8 +67,8 @@ async function installFromSource(xmakeBin: string, sourceDir: string, binDir: st
|
|||||||
await exec(xmakeBin, ['install', '-o', binDir, 'cli'], { cwd: sourceDir });
|
await exec(xmakeBin, ['install', '-o', binDir, 'cli'], { cwd: sourceDir });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function winInstall(version: Version, latest: Version): Promise<void> {
|
export async function winInstall(version: Version): Promise<void> {
|
||||||
if (version.type === 'local' || latest.type === 'local') {
|
if (version.type === 'local') {
|
||||||
throw new Error('Local builds for windows is not supported');
|
throw new Error('Local builds for windows is not supported');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +105,7 @@ export async function winInstall(version: Version, latest: Version): Promise<voi
|
|||||||
|
|
||||||
if (!toolDir) {
|
if (!toolDir) {
|
||||||
const installer = await core.group(`download xmake ${String(version)}`, async () => {
|
const installer = await core.group(`download xmake ${String(version)}`, async () => {
|
||||||
const url = getInstallerUrl(version, latest);
|
const url = await getInstallerUrl(version);
|
||||||
core.info(`downloading from ${url}`);
|
core.info(`downloading from ${url}`);
|
||||||
const file = await toolCache.downloadTool(url);
|
const file = await toolCache.downloadTool(url);
|
||||||
const exe = path.format({
|
const exe = path.format({
|
||||||
|
|||||||
Reference in New Issue
Block a user