cache packages
This commit is contained in:
Vendored
-87666
File diff suppressed because one or more lines are too long
+33
-32
@@ -7,6 +7,29 @@ import * as fs from 'fs';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fsutils from './fsutils';
|
import * as fsutils from './fsutils';
|
||||||
|
|
||||||
|
function getBuildCacheKey(): string {
|
||||||
|
let buildCacheKey = core.getInput('build-cache-key');
|
||||||
|
if (!buildCacheKey) {
|
||||||
|
buildCacheKey = '';
|
||||||
|
}
|
||||||
|
return `xmake-build-cache-${buildCacheKey}-${os.arch()}-${os.platform()}-${
|
||||||
|
process.env.RUNNER_OS ?? 'unknown'
|
||||||
|
}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBuildCachePath(): string {
|
||||||
|
let buildCachePath = core.getInput('build-cache-path');
|
||||||
|
if (!buildCachePath) {
|
||||||
|
buildCachePath = 'build/.build_cache';
|
||||||
|
}
|
||||||
|
return buildCachePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBuildCacheFolder(): string {
|
||||||
|
return '.xmake-build-cache';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function loadBuildCache(): Promise<void> {
|
export async function loadBuildCache(): Promise<void> {
|
||||||
const buildCache = core.getBooleanInput('build-cache');
|
const buildCache = core.getBooleanInput('build-cache');
|
||||||
if (!buildCache) {
|
if (!buildCache) {
|
||||||
@@ -16,27 +39,16 @@ export async function loadBuildCache(): Promise<void> {
|
|||||||
// export $XMAKE_ACTION_BUILD_CACHE, xmake will check it and enable build cache by default on ci.
|
// export $XMAKE_ACTION_BUILD_CACHE, xmake will check it and enable build cache by default on ci.
|
||||||
core.exportVariable('XMAKE_ACTION_BUILD_CACHE', 'true');
|
core.exportVariable('XMAKE_ACTION_BUILD_CACHE', 'true');
|
||||||
|
|
||||||
const buildCacheFolder = '.xmake-build-cache';
|
const buildCacheFolder = getBuildCacheFolder();
|
||||||
|
const buildCacheKey = getBuildCacheKey();
|
||||||
let buildCacheKey = core.getInput('build-cache-key');
|
const buildCachePath = getBuildCachePath();
|
||||||
if (!buildCacheKey) {
|
|
||||||
buildCacheKey = '';
|
|
||||||
}
|
|
||||||
const cacheKey = `xmake-build-cache-${buildCacheKey}-${os.arch()}-${os.platform()}-${
|
|
||||||
process.env.RUNNER_OS ?? 'unknown'
|
|
||||||
}`;
|
|
||||||
|
|
||||||
let buildCachePath = core.getInput('build-cache-path');
|
|
||||||
if (!buildCachePath) {
|
|
||||||
buildCachePath = 'build/.build_cache';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buildCacheFolder && process.env.GITHUB_WORKSPACE) {
|
if (buildCacheFolder && process.env.GITHUB_WORKSPACE) {
|
||||||
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, buildCacheFolder);
|
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, buildCacheFolder);
|
||||||
const filepath = path.join(fullCachePath, 'build_cache_saved.txt');
|
const filepath = path.join(fullCachePath, 'build_cache_saved.txt');
|
||||||
if (!fsutils.isFile(filepath)) {
|
if (!fsutils.isFile(filepath)) {
|
||||||
core.info(`Restore build cache path: ${fullCachePath} to ${buildCachePath}, key: ${cacheKey}`);
|
core.info(`Restore build cache path: ${fullCachePath} to ${buildCachePath}, key: ${buildCacheKey}`);
|
||||||
await cache.restoreCache([buildCacheFolder], cacheKey);
|
await cache.restoreCache([buildCacheFolder], buildCacheKey);
|
||||||
}
|
}
|
||||||
if (fsutils.isFile(filepath)) {
|
if (fsutils.isFile(filepath)) {
|
||||||
await io.cp(fullCachePath, buildCachePath, {
|
await io.cp(fullCachePath, buildCachePath, {
|
||||||
@@ -55,28 +67,17 @@ export async function saveBuildCache(): Promise<void> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildCacheFolder = '.xmake-build-cache';
|
const buildCacheFolder = getBuildCacheFolder();
|
||||||
|
const buildCacheKey = getBuildCacheKey();
|
||||||
let buildCacheKey = core.getInput('build-cache-key');
|
const buildCachePath = getBuildCachePath();
|
||||||
if (!buildCacheKey) {
|
|
||||||
buildCacheKey = '';
|
|
||||||
}
|
|
||||||
const cacheKey = `xmake-build-cache-${buildCacheKey}-${os.arch()}-${os.platform()}-${
|
|
||||||
process.env.RUNNER_OS ?? 'unknown'
|
|
||||||
}`;
|
|
||||||
|
|
||||||
let buildCachePath = core.getInput('build-cache-path');
|
|
||||||
if (!buildCachePath) {
|
|
||||||
buildCachePath = 'build/.build_cache';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buildCacheFolder && process.env.GITHUB_WORKSPACE && fsutils.isDir(buildCachePath)) {
|
if (buildCacheFolder && process.env.GITHUB_WORKSPACE && fsutils.isDir(buildCachePath)) {
|
||||||
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, buildCacheFolder);
|
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, buildCacheFolder);
|
||||||
core.info(`Save build cache path: ${buildCachePath} to ${fullCachePath}, key: ${cacheKey}`);
|
core.info(`Save build cache path: ${buildCachePath} to ${fullCachePath}, key: ${buildCacheKey}`);
|
||||||
await io.cp(buildCachePath, fullCachePath, {
|
await io.cp(buildCachePath, fullCachePath, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
await exec('xmake', ['l', 'os.touch', path.join(fullCachePath, 'build_cache_saved.txt')]);
|
await exec('xmake', ['l', 'os.touch', path.join(fullCachePath, 'build_cache_saved.txt')]);
|
||||||
await cache.saveCache([buildCacheFolder], cacheKey);
|
await cache.saveCache([buildCacheFolder], buildCacheKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+82
-2
@@ -5,7 +5,87 @@ import * as cache from '@actions/cache';
|
|||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as fsutils from './fsutils';
|
||||||
|
|
||||||
export async function loadPackageCache(): Promise<void> {}
|
function getPackageCacheKey(): string {
|
||||||
|
let packageCacheKey = core.getInput('package-cache-key');
|
||||||
|
if (!packageCacheKey) {
|
||||||
|
packageCacheKey = '';
|
||||||
|
}
|
||||||
|
return `xmake-package-cache-${packageCacheKey}-${os.arch()}-${os.platform()}-${
|
||||||
|
process.env.RUNNER_OS ?? 'unknown'
|
||||||
|
}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPackageCachePath(): string {
|
||||||
|
let packageCachePath = "";
|
||||||
|
await exec('xmake', ['l', 'core.package.package.installdir'], (error: Error | null, stdout: string, stderr: string) => {
|
||||||
|
if (error) {
|
||||||
|
core.info(`exec error: ${error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
packageCachePath = stdout;
|
||||||
|
});
|
||||||
|
core.info(`packageCachePath: ${packageCachePath}`);
|
||||||
|
return packageCachePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPackageCacheFolder(): string {
|
||||||
|
return '.xmake-package-cache';
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function loadPackageCache(): Promise<void> {
|
||||||
|
const packageCache = core.getBooleanInput('package-cache');
|
||||||
|
if (!packageCache) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const packageCacheFolder = getPackageCacheFolder();
|
||||||
|
const packageCacheKey = getPackageCacheKey();
|
||||||
|
const packageCachePath = getPackageCachePath();
|
||||||
|
if (!packageCachePath || packageCachePath === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packageCacheFolder && process.env.GITHUB_WORKSPACE) {
|
||||||
|
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, packageCacheFolder);
|
||||||
|
const filepath = path.join(fullCachePath, 'package_cache_saved.txt');
|
||||||
|
if (!fsutils.isFile(filepath)) {
|
||||||
|
core.info(`Restore package cache path: ${fullCachePath} to ${packageCachePath}, key: ${packageCacheKey}`);
|
||||||
|
await cache.restoreCache([packageCacheFolder], packageCacheKey);
|
||||||
|
}
|
||||||
|
if (fsutils.isFile(filepath)) {
|
||||||
|
await io.cp(fullCachePath, packageCachePath, {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
core.warning(`No cached files found at path "${fullCachePath}".`);
|
||||||
|
await io.rmRF(fullCachePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function savePackageCache(): Promise<void> {
|
||||||
|
const packageCache = core.getBooleanInput('package-cache');
|
||||||
|
if (!packageCache) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const packageCacheFolder = getPackageCacheFolder();
|
||||||
|
const packageCacheKey = getPackageCacheKey();
|
||||||
|
const packageCachePath = getPackageCachePath();
|
||||||
|
if (!packageCachePath || packageCachePath === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packageCacheFolder && process.env.GITHUB_WORKSPACE && fsutils.isDir(packageCachePath)) {
|
||||||
|
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, packageCacheFolder);
|
||||||
|
core.info(`Save package cache path: ${packageCachePath} to ${fullCachePath}, key: ${packageCacheKey}`);
|
||||||
|
await io.cp(packageCachePath, fullCachePath, {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
await exec('xmake', ['l', 'os.touch', path.join(fullCachePath, 'package_cache_saved.txt')]);
|
||||||
|
await cache.saveCache([packageCacheFolder], packageCacheKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function savePackageCache(): Promise<void> {}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user