cache build cache
This commit is contained in:
@@ -68,7 +68,7 @@ with:
|
|||||||
uses: xmake-io/github-action-setup-xmake@v1
|
uses: xmake-io/github-action-setup-xmake@v1
|
||||||
with:
|
with:
|
||||||
xmake-version: '2.9.7'
|
xmake-version: '2.9.7'
|
||||||
package-cache-folder: '.xmake-package-cache'
|
package-cache: true
|
||||||
package-cache-key: 'archlinux-ci'
|
package-cache-key: 'archlinux-ci'
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -78,10 +78,21 @@ with:
|
|||||||
uses: xmake-io/github-action-setup-xmake@v1
|
uses: xmake-io/github-action-setup-xmake@v1
|
||||||
with:
|
with:
|
||||||
xmake-version: '2.9.7'
|
xmake-version: '2.9.7'
|
||||||
build-cache-folder: '.xmake-build-cache'
|
build-cache: true
|
||||||
build-cache-key: 'archlinux-ci'
|
build-cache-key: 'archlinux-ci'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Cache build with the specific build path.
|
||||||
|
|
||||||
|
|
||||||
|
```yml
|
||||||
|
uses: xmake-io/github-action-setup-xmake@v1
|
||||||
|
with:
|
||||||
|
xmake-version: '2.9.7'
|
||||||
|
build-cache: true
|
||||||
|
build-cache-path: 'build/.build_cache'
|
||||||
|
```
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
### Prepare development environment
|
### Prepare development environment
|
||||||
|
|||||||
+8
-5
@@ -16,14 +16,17 @@ inputs:
|
|||||||
actions-cache-key:
|
actions-cache-key:
|
||||||
description: The actions cache key.
|
description: The actions cache key.
|
||||||
default: ''
|
default: ''
|
||||||
package-cache-folder:
|
package-cache:
|
||||||
description: 'Directory to cache package in. This folder will go under $GITHUB_HOME (I.e. build dir) and be cached using @actions/cache.'
|
description: Enable package cache.
|
||||||
default: ''
|
default: false
|
||||||
package-cache-key:
|
package-cache-key:
|
||||||
description: The packages cache key.
|
description: The packages cache key.
|
||||||
default: ''
|
default: ''
|
||||||
build-cache-folder:
|
build-cache:
|
||||||
description: 'Directory to cache build artifacts in. This folder will go under $GITHUB_HOME (I.e. build dir) and be cached using @actions/cache.'
|
description: Enable build cache.
|
||||||
|
default: false
|
||||||
|
build-cache-path:
|
||||||
|
description: The build cache path.
|
||||||
default: ''
|
default: ''
|
||||||
build-cache-key:
|
build-cache-key:
|
||||||
description: The build cache key.
|
description: The build cache key.
|
||||||
|
|||||||
Vendored
-87564
File diff suppressed because one or more lines are too long
+73
-2
@@ -7,6 +7,77 @@ 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';
|
||||||
|
|
||||||
export async function loadBuildCache(): Promise<void> {}
|
export async function loadBuildCache(): Promise<void> {
|
||||||
|
let buildCache = core.getInput('build-cache');
|
||||||
|
if (!buildCache) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
export async function saveBuildCache(): Promise<void> {}
|
const buildCacheFolder = ".xmake-build-cache";
|
||||||
|
|
||||||
|
let buildCacheKey = core.getInput('build-cache-key');
|
||||||
|
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) {
|
||||||
|
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, buildCacheFolder);
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
fs.accessSync(path.join(fullCachePath, 'build_cache_saved.txt'), fs.constants.X_OK);
|
||||||
|
} catch {
|
||||||
|
await cache.restoreCache([buildCacheFolder], cacheKey);
|
||||||
|
}
|
||||||
|
fs.accessSync(path.join(fullCachePath, 'build_cache_saved.txt'), fs.constants.X_OK);
|
||||||
|
core.info(`restore build cache path: ${fullCachePath} to ${buildCachePath}, key: ${cacheKey}`);
|
||||||
|
|
||||||
|
// restore build cache
|
||||||
|
await io.cp(fullCachePath, buildCachePath, {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
core.warning(`No cached files found at path "${fullCachePath}".`);
|
||||||
|
await io.rmRF(fullCachePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function saveBuildCache(): Promise<void> {
|
||||||
|
let buildCache = core.getInput('build-cache');
|
||||||
|
if (!buildCache) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
const buildCacheFolder = ".xmake-build-cache";
|
||||||
|
|
||||||
|
let buildCacheKey = core.getInput('build-cache-key');
|
||||||
|
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) {
|
||||||
|
cacheDir = path.join(process.env.GITHUB_WORKSPACE, buildCacheFolder);
|
||||||
|
core.info(`save build cache path: ${buildCachePath} to ${cacheDir}, key: ${cacheKey}`);
|
||||||
|
await io.cp(buildCachePath, cacheDir, {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
await exec("xmake", ["l", "io.touch", path.join(cacheDir, "build_cache_saved.txt")]);
|
||||||
|
await cache.saveCache([buildCacheFolder], cacheKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import { exec } from '@actions/exec';
|
|
||||||
import * as os from 'os';
|
|
||||||
import * as stateHelper from './state-helper';
|
import * as stateHelper from './state-helper';
|
||||||
import { installXmake } from './install';
|
import { installXmake } from './install';
|
||||||
import { loadBuildCache, saveBuildCache } from './build-cache';
|
import { loadBuildCache, saveBuildCache } from './build-cache';
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import * as core from '@actions/core';
|
|
||||||
import { exec } from '@actions/exec';
|
import { exec } from '@actions/exec';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import { selectVersion } from './versions';
|
import { selectVersion } from './versions';
|
||||||
|
|||||||
Reference in New Issue
Block a user