Compare commits

..

8 Commits

12 changed files with 247 additions and 112 deletions
+1 -1
View File
@@ -142,6 +142,6 @@ git branch test
git checkout test
pnpm build
pnpm release
git-commit -a -m "..."
git commit -a -m "..."
git push origin test
```
+127 -56
View File
@@ -70512,9 +70512,9 @@ const core = __nccwpck_require__(7484);
const exec_1 = __nccwpck_require__(5236);
const io = __nccwpck_require__(4994);
const cache = __nccwpck_require__(5116);
const os = __nccwpck_require__(857);
const path = __nccwpck_require__(6928);
const fsutils = __nccwpck_require__(7999);
const system_1 = __nccwpck_require__(7666);
function getBuildTime(hours) {
let key = 'BuildTime';
if (hours && hours !== '') {
@@ -70545,8 +70545,7 @@ function getProjectRootPath() {
}
return projectRootPath;
}
function getBuildCacheKey(buildCacheTime) {
var _a;
async function getBuildCacheKey(buildCacheTime) {
let buildCacheKey = core.getInput('build-cache-key');
if (!buildCacheKey) {
buildCacheKey = '';
@@ -70554,7 +70553,8 @@ function getBuildCacheKey(buildCacheTime) {
if (!buildCacheTime || buildCacheTime === '') {
buildCacheTime = getBuildTime();
}
return `xmake-build-cache-${buildCacheKey}-${buildCacheTime}-${os.arch()}-${os.platform()}-${(_a = process.env.RUNNER_OS) !== null && _a !== void 0 ? _a : 'unknown'}`;
const platformIdentifier = await (0, system_1.getPlatformIdentifier)();
return `xmake-build-cache-${buildCacheKey}-${buildCacheTime}-${platformIdentifier}`;
}
async function getBuildCachePath() {
let buildCachePath = core.getInput('build-cache-path');
@@ -70611,7 +70611,7 @@ async function loadBuildCache() {
if (hours < 0) {
break;
}
const buildCacheKey = getBuildCacheKey(getBuildTime(String(hours).padStart(2, '0')));
const buildCacheKey = await getBuildCacheKey(getBuildTime(String(hours).padStart(2, '0')));
if (!fsutils.isFile(filepath)) {
core.info(`Restore build cache path: ${fullCachePath} to ${buildCachePath}, key: ${buildCacheKey}`);
await cache.restoreCache([buildCacheFolder], buildCacheKey);
@@ -70644,7 +70644,7 @@ async function saveBuildCache() {
return;
}
const buildCacheFolder = getBuildCacheFolder();
const buildCacheKey = getBuildCacheKey();
const buildCacheKey = await getBuildCacheKey();
const buildCachePath = await getBuildCachePath();
const hitBuildCache = !!core.getState('hitBuildCache');
if (!hitBuildCache && buildCacheFolder && process.env.GITHUB_WORKSPACE && fsutils.isDir(buildCachePath)) {
@@ -70713,6 +70713,7 @@ const exec_1 = __nccwpck_require__(5236);
const io = __nccwpck_require__(4994);
const os = __nccwpck_require__(857);
const path = __nccwpck_require__(6928);
const semver_1 = __nccwpck_require__(2088);
function makeOpt(ref) {
return { cwd: path.join(os.tmpdir(), `xmake-git-${ref}`) };
}
@@ -70727,25 +70728,38 @@ async function lsRemote(repo) {
});
const data = { heads: {}, tags: {}, pull: {} };
out.split('\n').forEach((line) => {
const [ref, tag] = line.trim().split('\t');
if (ref && (tag === null || tag === void 0 ? void 0 : tag.startsWith('refs/'))) {
const tagPath = tag.split('/').splice(1);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let ldata = data; // eslint-disable-line @typescript-eslint/no-unsafe-assignment
for (let i = 0; i < tagPath.length - 1; i++) {
const seg = tagPath[i];
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (typeof ldata[seg] === 'object') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
ldata = ldata[seg]; // eslint-disable-line @typescript-eslint/no-unsafe-assignment
const [ref, path] = line.trim().split('\t');
if (ref && (path === null || path === void 0 ? void 0 : path.startsWith('refs/'))) {
const tagPath = path.split('/').splice(1);
switch (tagPath[0]) {
case 'heads': {
// refs/heads/copilot/fix-6807
const head = tagPath.slice(1).join('/');
data.heads[head] = ref;
break;
}
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] = {};
}
data.pull[pr][tagPath[2]] = ref;
break;
}
case 'tags': {
// refs/tags/preview
// refs/tags/v3.0.3
const tag = tagPath.slice(1).join('/');
if ((0, semver_1.valid)(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;
@@ -70784,8 +70798,7 @@ const unix_install_1 = __nccwpck_require__(9095);
async function installXmake() {
const version = await (0, versions_1.selectVersion)();
if (os.platform() === 'win32' || os.platform() === 'cygwin') {
const latest = await (0, versions_1.selectVersion)('latest');
await (0, win_install_1.winInstall)(version, latest);
await (0, win_install_1.winInstall)(version);
}
else {
await (0, unix_install_1.unixInstall)(version);
@@ -70832,9 +70845,9 @@ const core = __nccwpck_require__(7484);
const exec_1 = __nccwpck_require__(5236);
const io = __nccwpck_require__(4994);
const cache = __nccwpck_require__(5116);
const os = __nccwpck_require__(857);
const path = __nccwpck_require__(6928);
const fsutils = __nccwpck_require__(7999);
const system_1 = __nccwpck_require__(7666);
function getProjectRootPath() {
let projectRootPath = core.getInput('project-path');
if (!projectRootPath) {
@@ -70847,7 +70860,6 @@ function getProjectRootPath() {
return projectRootPath;
}
async function getPackageCacheKey() {
var _a;
let packageCacheKey = core.getInput('package-cache-key');
if (!packageCacheKey) {
packageCacheKey = '';
@@ -70870,7 +70882,8 @@ async function getPackageCacheKey() {
await (0, exec_1.exec)('xmake', ['l', 'utils.ci.packageskey'], options);
packageCacheHash = packageCacheHash.trim();
}
return `xmake-package-cache-${packageCacheKey}-${packageCacheHash}-${os.arch()}-${os.platform()}-${(_a = process.env.RUNNER_OS) !== null && _a !== void 0 ? _a : 'unknown'}`;
const platformIdentifier = await (0, system_1.getPlatformIdentifier)();
return `xmake-package-cache-${packageCacheKey}-${packageCacheHash}-${platformIdentifier}`;
}
async function getPackageCachePath() {
let packageCachePath = '';
@@ -70974,6 +70987,44 @@ if (!exports.IsPost) {
}
/***/ }),
/***/ 7666:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getPlatformIdentifier = getPlatformIdentifier;
const core = __nccwpck_require__(7484);
const exec_1 = __nccwpck_require__(5236);
const os = __nccwpck_require__(857);
async function getPlatformIdentifier() {
var _a;
let identifier = `${os.platform()}-${os.arch()}-${(_a = process.env.RUNNER_OS) !== null && _a !== void 0 ? _a : 'unknown'}`;
if (os.platform() === 'darwin') {
let productVersion = '';
try {
await (0, exec_1.exec)('sw_vers', ['-productVersion'], {
silent: true,
listeners: {
stdout: (data) => {
productVersion = data.toString().trim();
},
},
});
if (productVersion) {
identifier += `-${productVersion}`;
}
}
catch (error) {
core.warning(`Failed to get macOS product version: ${error instanceof Error ? error.message : String(error)}`);
}
}
return identifier;
}
/***/ }),
/***/ 9095:
@@ -70993,6 +71044,7 @@ const fs = __nccwpck_require__(9896);
const path = __nccwpck_require__(6928);
const semver = __nccwpck_require__(2088);
const git = __nccwpck_require__(1243);
const system_1 = __nccwpck_require__(7666);
async function install(sourceDir, binDir) {
if (fs.existsSync(path.join(sourceDir, 'configure'))) {
await (0, exec_1.exec)('sh', ['./configure'], { cwd: sourceDir });
@@ -71005,7 +71057,6 @@ async function install(sourceDir, binDir) {
}
}
async function unixInstall(version) {
var _a;
let toolDir = '';
const actionsCacheFolder = core.getInput('actions-cache-folder');
let actionsCacheKey = core.getInput('actions-cache-key');
@@ -71015,22 +71066,23 @@ async function unixInstall(version) {
if (version.type !== 'local') {
const ver = version.version;
const sha = version.sha;
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${os.arch()}-${os.platform()}-${(_a = process.env.RUNNER_OS) !== null && _a !== void 0 ? _a : 'unknown'}`;
const platformIdentifier = await (0, system_1.getPlatformIdentifier)();
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${platformIdentifier}`;
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
try {
try {
fs.accessSync(path.join(fullCachePath, 'bin', 'xmake'), fs.constants.X_OK);
}
catch (_b) {
catch (_a) {
await cache.restoreCache([actionsCacheFolder], cacheKey);
}
fs.accessSync(path.join(fullCachePath, 'bin', 'xmake'), fs.constants.X_OK);
toolDir = fullCachePath;
core.info(`cache path: ${toolDir}, key: ${cacheKey}`);
}
catch (_c) {
core.warning(`No cached files found at path "${fullCachePath}".`);
catch (_b) {
core.warning(`No cached files found at path "${fullCachePath}, key: ${cacheKey}".`);
await io.rmRF(fullCachePath);
}
}
@@ -71187,9 +71239,9 @@ async function selectSha(repo, sha) {
return selectPr(repo, Number.parseInt(pr));
}
}
return Promise.resolve(new GitVersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substr(0, 8)}`));
return Promise.resolve(new GitVersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substring(0, 8)}`));
}
async function selectVersion(version) {
async function selectVersion(version, _fallback = false) {
// get version string
version = (version !== null && version !== void 0 ? version : core.getInput('xmake-version')) || 'latest';
if (version.toLowerCase() === 'latest')
@@ -71210,20 +71262,20 @@ async function selectVersion(version) {
}
// select branch
if (version.startsWith('branch@')) {
const branch = version.substr('branch@'.length);
const branch = version.substring('branch@'.length);
ret = await selectBranch(repo, branch);
}
// select 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) {
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);
}
// select sha
if (version.startsWith('sha@')) {
const sha = version.substr('sha@'.length);
const sha = version.substring('sha@'.length);
ret = await selectSha(repo, sha);
}
// select version
@@ -71236,8 +71288,8 @@ async function selectVersion(version) {
if (ret.type === 'local') {
core.info(`Use local xmake at '${ret.path}'`);
}
else {
core.info(`Selected xmake ${String(ret)} (commit: ${ret.sha.substr(0, 8)})` +
else if (!_fallback) {
core.info(`Selected xmake ${String(ret)} (commit: ${ret.sha.substring(0, 8)})` +
(repo !== DEFAULT_REPO ? ` of ${repo}` : ''));
}
return ret;
@@ -71263,16 +71315,21 @@ const fs = __nccwpck_require__(9896);
const path = __nccwpck_require__(6928);
const semver = __nccwpck_require__(2088);
const git = __nccwpck_require__(1243);
function getInstallerUrl(version, latest) {
let ver = version.version;
const versions_1 = __nccwpck_require__(7902);
const system_1 = __nccwpck_require__(7666);
async function getInstallerUrl(version, _fallback = false) {
const latest = (await (0, versions_1.selectVersion)('latest', _fallback));
const latestVers = latest.version;
let vers = version.version;
let finalUrl;
switch (version.type) {
case 'heads': {
const arch = os.arch() === 'arm64' ? 'arm64' : os.arch() === 'x64' ? 'win64' : 'win32';
const latestver = latest.version;
if (ver !== 'dev' && ver !== 'master') {
ver = latestver;
if (vers !== 'dev' && vers !== 'master') {
vers = latestVers;
}
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': {
throw new Error('PR builds for windows is not supported');
@@ -71282,9 +71339,10 @@ function getInstallerUrl(version, latest) {
}
case 'tags': {
const arch = os.arch() === 'arm64' ? 'arm64' : os.arch() === 'x64' ? 'win64' : 'win32';
return semver.gt(ver, '2.2.6')
? `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.${arch}.exe`
: `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.exe`;
finalUrl = semver.gt(vers, '2.2.6')
? `https://github.com/xmake-io/xmake/releases/download/${vers}/xmake-${vers}.${arch}.exe`
: `https://github.com/xmake-io/xmake/releases/download/${vers}/xmake-${vers}.exe`;
break;
}
default: {
// check that we have tested all types
@@ -71292,14 +71350,26 @@ function getInstallerUrl(version, latest) {
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 (0, versions_1.selectVersion)('<' + currentVers));
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, sourceDir, binDir) {
await (0, exec_1.exec)(xmakeBin, ['-y'], { cwd: sourceDir });
await (0, exec_1.exec)(xmakeBin, ['install', '-o', binDir, 'cli'], { cwd: sourceDir });
}
async function winInstall(version, latest) {
var _a;
if (version.type === 'local' || latest.type === 'local') {
async function winInstall(version) {
if (version.type === 'local') {
throw new Error('Local builds for windows is not supported');
}
const actionsCacheFolder = core.getInput('actions-cache-folder');
@@ -71309,7 +71379,8 @@ async function winInstall(version, latest) {
}
const ver = version.version;
const sha = version.sha;
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${os.arch()}-${os.platform()}-${(_a = process.env.RUNNER_OS) !== null && _a !== void 0 ? _a : 'unknown'}`;
const platformIdentifier = await (0, system_1.getPlatformIdentifier)();
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${platformIdentifier}`;
let toolDir = '';
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
@@ -71317,14 +71388,14 @@ async function winInstall(version, latest) {
try {
fs.accessSync(path.join(fullCachePath, 'xmake.exe'), fs.constants.X_OK);
}
catch (_b) {
catch (_a) {
await cache.restoreCache([actionsCacheFolder], cacheKey);
}
fs.accessSync(path.join(fullCachePath, 'xmake.exe'), fs.constants.X_OK);
toolDir = fullCachePath;
core.info(`cache path: ${toolDir}, key: ${cacheKey}`);
}
catch (_c) {
catch (_b) {
core.warning(`No cached files found at path "${fullCachePath}".`);
await io.rmRF(fullCachePath);
}
@@ -71334,7 +71405,7 @@ async function winInstall(version, latest) {
}
if (!toolDir) {
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}`);
const file = await toolCache.downloadTool(url);
const exe = path.format({
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "github-action-setup-xmake",
"version": "1.2.1",
"version": "1.2.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "github-action-setup-xmake",
"version": "1.2.1",
"version": "1.2.3",
"license": "GPL-3.0-or-later",
"dependencies": {
"@actions/cache": "^4.0.3",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "github-action-setup-xmake",
"version": "1.2.1",
"version": "1.2.3",
"description": "Set up your GitHub Actions workflow with a specific version of xmake",
"main": "dist/index.js",
"author": "OpportunityLiu",
+6 -5
View File
@@ -2,9 +2,9 @@ import * as core from '@actions/core';
import { exec, ExecOptions } from '@actions/exec';
import * as io from '@actions/io';
import * as cache from '@actions/cache';
import * as os from 'os';
import * as path from 'path';
import * as fsutils from './fsutils';
import { getPlatformIdentifier } from './system';
function getBuildTime(hours?: string): string {
let key = 'BuildTime';
@@ -38,7 +38,7 @@ function getProjectRootPath(): string {
return projectRootPath;
}
function getBuildCacheKey(buildCacheTime?: string): string {
async function getBuildCacheKey(buildCacheTime?: string): Promise<string> {
let buildCacheKey = core.getInput('build-cache-key');
if (!buildCacheKey) {
buildCacheKey = '';
@@ -46,7 +46,8 @@ function getBuildCacheKey(buildCacheTime?: string): string {
if (!buildCacheTime || buildCacheTime === '') {
buildCacheTime = getBuildTime();
}
return `xmake-build-cache-${buildCacheKey}-${buildCacheTime}-${os.arch()}-${os.platform()}-${process.env.RUNNER_OS ?? 'unknown'}`;
const platformIdentifier = await getPlatformIdentifier();
return `xmake-build-cache-${buildCacheKey}-${buildCacheTime}-${platformIdentifier}`;
}
async function getBuildCachePath(): Promise<string> {
@@ -112,7 +113,7 @@ export async function loadBuildCache(): Promise<void> {
if (hours < 0) {
break;
}
const buildCacheKey = getBuildCacheKey(getBuildTime(String(hours).padStart(2, '0')));
const buildCacheKey = await getBuildCacheKey(getBuildTime(String(hours).padStart(2, '0')));
if (!fsutils.isFile(filepath)) {
core.info(`Restore build cache path: ${fullCachePath} to ${buildCachePath}, key: ${buildCacheKey}`);
await cache.restoreCache([buildCacheFolder], buildCacheKey);
@@ -147,7 +148,7 @@ export async function saveBuildCache(): Promise<void> {
}
const buildCacheFolder = getBuildCacheFolder();
const buildCacheKey = getBuildCacheKey();
const buildCacheKey = await getBuildCacheKey();
const buildCachePath = await getBuildCachePath();
const hitBuildCache = !!core.getState('hitBuildCache');
+31 -16
View File
@@ -3,6 +3,7 @@ import * as io from '@actions/io';
import * as os from 'os';
import * as path from 'path';
import { Sha, RefDic, Repo } from './interfaces';
import { valid as isValidSemver } from 'semver';
function makeOpt(ref: Sha): { cwd: string } {
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: {} };
out.split('\n').forEach((line) => {
const [ref, tag] = line.trim().split('\t');
if (ref && tag?.startsWith('refs/')) {
const tagPath = tag.split('/').splice(1);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let ldata = data as any; // eslint-disable-line @typescript-eslint/no-unsafe-assignment
for (let i = 0; i < tagPath.length - 1; i++) {
const seg = tagPath[i];
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (typeof ldata[seg] === 'object') {
// 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] = {};
const [ref, path] = line.trim().split('\t') as [Sha, string];
if (ref && path?.startsWith('refs/')) {
const tagPath = path.split('/').splice(1);
switch (tagPath[0]) {
case 'heads': {
// refs/heads/copilot/fix-6807
const head = tagPath.slice(1).join('/');
data.heads[head] = ref;
break;
}
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;
+1 -2
View File
@@ -7,8 +7,7 @@ import { unixInstall } from './unix-install';
export async function installXmake(): Promise<void> {
const version = await selectVersion();
if (os.platform() === 'win32' || os.platform() === 'cygwin') {
const latest = await selectVersion('latest');
await winInstall(version, latest);
await winInstall(version);
} else {
await unixInstall(version);
}
+3 -2
View File
@@ -2,9 +2,9 @@ import * as core from '@actions/core';
import { exec, ExecOptions } from '@actions/exec';
import * as io from '@actions/io';
import * as cache from '@actions/cache';
import * as os from 'os';
import * as path from 'path';
import * as fsutils from './fsutils';
import { getPlatformIdentifier } from './system';
function getProjectRootPath(): string {
let projectRootPath = core.getInput('project-path');
@@ -41,7 +41,8 @@ async function getPackageCacheKey(): Promise<string> {
await exec('xmake', ['l', 'utils.ci.packageskey'], options);
packageCacheHash = packageCacheHash.trim();
}
return `xmake-package-cache-${packageCacheKey}-${packageCacheHash}-${os.arch()}-${os.platform()}-${process.env.RUNNER_OS ?? 'unknown'}`;
const platformIdentifier = await getPlatformIdentifier();
return `xmake-package-cache-${packageCacheKey}-${packageCacheHash}-${platformIdentifier}`;
}
async function getPackageCachePath(): Promise<string> {
+28
View File
@@ -0,0 +1,28 @@
import * as core from '@actions/core';
import { exec } from '@actions/exec';
import * as os from 'os';
export async function getPlatformIdentifier(): Promise<string> {
let identifier = `${os.platform()}-${os.arch()}-${process.env.RUNNER_OS ?? 'unknown'}`;
if (os.platform() === 'darwin') {
let productVersion = '';
try {
await exec('sw_vers', ['-productVersion'], {
silent: true,
listeners: {
stdout: (data: Buffer) => {
productVersion = data.toString().trim();
},
},
});
if (productVersion) {
identifier += `-${productVersion}`;
}
} catch (error: unknown) {
core.warning(
`Failed to get macOS product version: ${error instanceof Error ? error.message : String(error)}`,
);
}
}
return identifier;
}
+4 -4
View File
@@ -9,6 +9,7 @@ import * as path from 'path';
import * as semver from 'semver';
import * as git from './git';
import { Version } from './interfaces';
import { getPlatformIdentifier } from './system';
async function install(sourceDir: string, binDir: string): Promise<void> {
if (fs.existsSync(path.join(sourceDir, 'configure'))) {
@@ -32,9 +33,8 @@ export async function unixInstall(version: Version): Promise<void> {
if (version.type !== 'local') {
const ver = version.version;
const sha = version.sha;
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${os.arch()}-${os.platform()}-${
process.env.RUNNER_OS ?? 'unknown'
}`;
const platformIdentifier = await getPlatformIdentifier();
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${platformIdentifier}`;
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
@@ -48,7 +48,7 @@ export async function unixInstall(version: Version): Promise<void> {
toolDir = fullCachePath;
core.info(`cache path: ${toolDir}, key: ${cacheKey}`);
} catch {
core.warning(`No cached files found at path "${fullCachePath}".`);
core.warning(`No cached files found at path "${fullCachePath}, key: ${cacheKey}".`);
await io.rmRF(fullCachePath);
}
} else {
+8 -8
View File
@@ -96,11 +96,11 @@ async function selectSha(repo: Repo, sha: string): Promise<Version> {
}
}
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
version = (version ?? core.getInput('xmake-version')) || 'latest';
if (version.toLowerCase() === 'latest') version = '';
@@ -123,20 +123,20 @@ export async function selectVersion(version?: string): Promise<Version> {
// select branch
if (version.startsWith('branch@')) {
const branch = version.substr('branch@'.length);
const branch = version.substring('branch@'.length);
ret = await selectBranch(repo, branch);
}
// select 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) {
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);
}
// select sha
if (version.startsWith('sha@')) {
const sha = version.substr('sha@'.length);
const sha = version.substring('sha@'.length);
ret = await selectSha(repo, sha);
}
// select version
@@ -148,9 +148,9 @@ export async function selectVersion(version?: string): Promise<Version> {
}
if (ret.type === 'local') {
core.info(`Use local xmake at '${ret.path}'`);
} else {
} else if (!_fallback) {
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}` : ''),
);
}
+35 -15
View File
@@ -9,17 +9,22 @@ import * as path from 'path';
import * as semver from 'semver';
import * as git from './git';
import { Version, GitVersion } from './interfaces';
import { selectVersion } from './versions';
import { getPlatformIdentifier } from './system';
function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
let ver = version.version;
async function getInstallerUrl(version: GitVersion, _fallback: boolean = false): Promise<string> {
const latest = (await selectVersion('latest', _fallback)) as GitVersion;
const latestVers = latest.version;
let vers = version.version;
let finalUrl: string;
switch (version.type) {
case 'heads': {
const arch = os.arch() === 'arm64' ? 'arm64' : os.arch() === 'x64' ? 'win64' : 'win32';
const latestver = latest.version;
if (ver !== 'dev' && ver !== 'master') {
ver = latestver;
if (vers !== 'dev' && vers !== 'master') {
vers = latestVers;
}
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': {
throw new Error('PR builds for windows is not supported');
@@ -29,9 +34,10 @@ function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
}
case 'tags': {
const arch = os.arch() === 'arm64' ? 'arm64' : os.arch() === 'x64' ? 'win64' : 'win32';
return semver.gt(ver, '2.2.6')
? `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.${arch}.exe`
: `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.exe`;
finalUrl = semver.gt(vers, '2.2.6')
? `https://github.com/xmake-io/xmake/releases/download/${vers}/xmake-${vers}.${arch}.exe`
: `https://github.com/xmake-io/xmake/releases/download/${vers}/xmake-${vers}.exe`;
break;
}
default: {
// check that we have tested all types
@@ -39,6 +45,21 @@ function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
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> {
@@ -46,8 +67,8 @@ async function installFromSource(xmakeBin: string, sourceDir: string, binDir: st
await exec(xmakeBin, ['install', '-o', binDir, 'cli'], { cwd: sourceDir });
}
export async function winInstall(version: Version, latest: Version): Promise<void> {
if (version.type === 'local' || latest.type === 'local') {
export async function winInstall(version: Version): Promise<void> {
if (version.type === 'local') {
throw new Error('Local builds for windows is not supported');
}
@@ -59,9 +80,8 @@ export async function winInstall(version: Version, latest: Version): Promise<voi
const ver = version.version;
const sha = version.sha;
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${os.arch()}-${os.platform()}-${
process.env.RUNNER_OS ?? 'unknown'
}`;
const platformIdentifier = await getPlatformIdentifier();
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${platformIdentifier}`;
let toolDir = '';
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
@@ -85,7 +105,7 @@ export async function winInstall(version: Version, latest: Version): Promise<voi
if (!toolDir) {
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}`);
const file = await toolCache.downloadTool(url);
const exe = path.format({