custom cache folder

This commit is contained in:
yzhu
2022-11-01 07:11:06 +08:00
Unverified
parent c941099fd8
commit 2d4bbbd7ce
2 changed files with 71458 additions and 3 deletions
+71422
View File
File diff suppressed because one or more lines are too long
+35 -2
View File
@@ -2,7 +2,9 @@ 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';
@@ -14,10 +16,31 @@ async function install(sourceDir: string, binDir: string): Promise<void> {
}
export async function unixInstall(version: Version): Promise<void> {
let toolDir: string;
let toolDir = '';
const actionsCacheFolder = core.getInput('actions-cache-folder');
if (version.type !== 'local') {
const ver = version.version;
const cacheKey = `xmake-cache-${ver}-${os.arch()}-${os.platform()}-${process.env.RUNNER_OS ?? 'unknown'}`;
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 {
await cache.restoreCache([actionsCacheFolder], cacheKey);
}
fs.accessSync(path.join(fullCachePath, 'bin', 'xmake'), fs.constants.X_OK);
toolDir = fullCachePath;
} catch {
core.warning(`No cached files found at path "${fullCachePath}".`);
await io.rmRF(fullCachePath);
}
} else {
toolDir = toolCache.find('xmake', ver);
}
if (!toolDir) {
const sourceDir = await core.group(`download xmake ${String(version)}`, () =>
git.create(version.repo, version.sha),
@@ -25,7 +48,17 @@ export async function unixInstall(version: Version): Promise<void> {
toolDir = await core.group(`install xmake ${String(version)}`, async () => {
const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`);
await install(sourceDir, binDir);
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', ver);
let cacheDir = '';
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
cacheDir = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
await io.cp(binDir, cacheDir, {
recursive: true,
});
await cache.saveCache([actionsCacheFolder], cacheKey);
} else {
cacheDir = await toolCache.cacheDir(binDir, 'xmake', ver);
}
await io.rmRF(binDir);
await git.cleanup(version.sha);
return cacheDir;