cache window bin and support dev
This commit is contained in:
+67
-1
@@ -2,9 +2,12 @@ import * as core from '@actions/core';
|
||||
import { exec } from '@actions/exec';
|
||||
import * as io from '@actions/io';
|
||||
import * as toolCache from '@actions/tool-cache';
|
||||
import * as cache from '@actions/cache';
|
||||
import * as os from 'os';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import * as git from './git';
|
||||
import { Version, GitVersion } from './interfaces';
|
||||
|
||||
function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
|
||||
@@ -35,12 +38,48 @@ function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
|
||||
}
|
||||
}
|
||||
|
||||
async function installFromSource(xmakeBin: string, sourceDir: string, binDir: string): Promise<void> {
|
||||
await exec(xmakeBin, ['-y'], { cwd: sourceDir });
|
||||
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') {
|
||||
throw new Error('Local builds for windows is not supported');
|
||||
}
|
||||
|
||||
const actionsCacheFolder = core.getInput('actions-cache-folder');
|
||||
let actionsCacheKey = core.getInput('actions-cache-key');
|
||||
if (!actionsCacheKey) {
|
||||
actionsCacheKey = '';
|
||||
}
|
||||
|
||||
const ver = version.version;
|
||||
let toolDir = toolCache.find('xmake', ver);
|
||||
const sha = version.sha;
|
||||
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${os.arch()}-${os.platform()}-${
|
||||
process.env.RUNNER_OS ?? 'unknown'
|
||||
}`;
|
||||
|
||||
let toolDir = '';
|
||||
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
|
||||
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
|
||||
try {
|
||||
try {
|
||||
fs.accessSync(path.join(fullCachePath, 'xmake.exe'), fs.constants.X_OK);
|
||||
} catch {
|
||||
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 {
|
||||
core.warning(`No cached files found at path "${fullCachePath}".`);
|
||||
await io.rmRF(fullCachePath);
|
||||
}
|
||||
} else {
|
||||
toolDir = toolCache.find('xmake', ver);
|
||||
}
|
||||
|
||||
if (!toolDir) {
|
||||
const installer = await core.group(`download xmake ${String(version)}`, async () => {
|
||||
const url = getInstallerUrl(version, latest);
|
||||
@@ -65,6 +104,33 @@ export async function winInstall(version: Version, latest: Version): Promise<voi
|
||||
await io.rmRF(installer);
|
||||
return cacheDir;
|
||||
});
|
||||
await exec(`"${toolDir}/xmake.exe" --version`);
|
||||
if (version.type === 'heads') {
|
||||
const sourceDir = await core.group(`download xmake source ${String(version)}`, () =>
|
||||
git.create(version.repo, version.sha),
|
||||
);
|
||||
toolDir = await core.group(`install xmake source ${String(version)}`, async () => {
|
||||
const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`);
|
||||
await installFromSource(`${toolDir}/xmake.exe`, `${sourceDir}/core`, binDir);
|
||||
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', ver);
|
||||
|
||||
await io.rmRF(binDir);
|
||||
await git.cleanup(version.sha);
|
||||
return cacheDir;
|
||||
});
|
||||
}
|
||||
|
||||
if (toolDir) {
|
||||
let cacheDir = '';
|
||||
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
|
||||
cacheDir = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
|
||||
await io.cp(toolDir, cacheDir, {
|
||||
recursive: true,
|
||||
});
|
||||
await cache.saveCache([actionsCacheFolder], cacheKey);
|
||||
toolDir = cacheDir;
|
||||
}
|
||||
}
|
||||
}
|
||||
core.addPath(toolDir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user