cache build cache
This commit is contained in:
@@ -22,16 +22,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
xmake-version: ${{ matrix.version }}
|
xmake-version: ${{ matrix.version }}
|
||||||
actions-cache-folder: '.xmake-cache'
|
actions-cache-folder: '.xmake-cache'
|
||||||
build-cache-folder: '.xmake-build-cache'
|
build-cache: true
|
||||||
package-cache-folder: '.xmake-package-cache'
|
build-cache-path: 'tests/sample/build/.build_cache'
|
||||||
|
package-cache: true
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
xmake --version
|
xmake --version
|
||||||
xmake create test
|
cd tests/sample
|
||||||
cd test
|
xmake -y -vD
|
||||||
echo 'add_packages("libpng")' >> xmake.lua
|
|
||||||
echo 'target_end()' >> xmake.lua
|
|
||||||
echo 'add_requires("libpng", {system = false})' >> xmake.lua
|
|
||||||
xmake -vD -y
|
|
||||||
xmake run
|
xmake run
|
||||||
|
|||||||
@@ -74,6 +74,14 @@ with:
|
|||||||
|
|
||||||
### Cache build
|
### Cache build
|
||||||
|
|
||||||
|
By default, xmake disables build cache when building on ci, so we need to enable it first.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ xmake f --policies=build.ccache:y
|
||||||
|
```
|
||||||
|
|
||||||
|
And xmake v2.9.8 will enable it by default if action/build-cache is enabled.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
uses: xmake-io/github-action-setup-xmake@v1
|
uses: xmake-io/github-action-setup-xmake@v1
|
||||||
with:
|
with:
|
||||||
@@ -84,7 +92,6 @@ with:
|
|||||||
|
|
||||||
Cache build with the specific build path.
|
Cache build with the specific build path.
|
||||||
|
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
uses: xmake-io/github-action-setup-xmake@v1
|
uses: xmake-io/github-action-setup-xmake@v1
|
||||||
with:
|
with:
|
||||||
|
|||||||
Vendored
+87666
File diff suppressed because one or more lines are too long
+24
-25
@@ -1,19 +1,22 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import { exec } from '@actions/exec';
|
import { exec } from '@actions/exec';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
import * as toolCache from '@actions/tool-cache';
|
|
||||||
import * as cache from '@actions/cache';
|
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 loadBuildCache(): Promise<void> {
|
export async function loadBuildCache(): Promise<void> {
|
||||||
let buildCache = core.getInput('build-cache');
|
const buildCache = core.getBooleanInput('build-cache');
|
||||||
if (!buildCache) {
|
if (!buildCache) {
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildCacheFolder = ".xmake-build-cache";
|
// export $XMAKE_ACTION_BUILD_CACHE, xmake will check it and enable build cache by default on ci.
|
||||||
|
core.exportVariable('XMAKE_ACTION_BUILD_CACHE', 'true');
|
||||||
|
|
||||||
|
const buildCacheFolder = '.xmake-build-cache';
|
||||||
|
|
||||||
let buildCacheKey = core.getInput('build-cache-key');
|
let buildCacheKey = core.getInput('build-cache-key');
|
||||||
if (!buildCacheKey) {
|
if (!buildCacheKey) {
|
||||||
@@ -25,25 +28,21 @@ export async function loadBuildCache(): Promise<void> {
|
|||||||
|
|
||||||
let buildCachePath = core.getInput('build-cache-path');
|
let buildCachePath = core.getInput('build-cache-path');
|
||||||
if (!buildCachePath) {
|
if (!buildCachePath) {
|
||||||
buildCachePath = "build/.build_cache";
|
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);
|
||||||
try {
|
const filepath = path.join(fullCachePath, 'build_cache_saved.txt');
|
||||||
try {
|
if (!fsutils.isFile(filepath)) {
|
||||||
fs.accessSync(path.join(fullCachePath, 'build_cache_saved.txt'), fs.constants.X_OK);
|
core.info(`Restore build cache path: ${fullCachePath} to ${buildCachePath}, key: ${cacheKey}`);
|
||||||
} catch {
|
await cache.restoreCache([buildCacheFolder], cacheKey);
|
||||||
await cache.restoreCache([buildCacheFolder], cacheKey);
|
}
|
||||||
}
|
if (fsutils.isFile(filepath)) {
|
||||||
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, {
|
await io.cp(fullCachePath, buildCachePath, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
} catch {
|
} else {
|
||||||
core.warning(`No cached files found at path "${fullCachePath}".`);
|
core.warning(`No cached files found at path "${fullCachePath}".`);
|
||||||
await io.rmRF(fullCachePath);
|
await io.rmRF(fullCachePath);
|
||||||
}
|
}
|
||||||
@@ -51,12 +50,12 @@ export async function loadBuildCache(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function saveBuildCache(): Promise<void> {
|
export async function saveBuildCache(): Promise<void> {
|
||||||
let buildCache = core.getInput('build-cache');
|
const buildCache = core.getBooleanInput('build-cache');
|
||||||
if (!buildCache) {
|
if (!buildCache) {
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildCacheFolder = ".xmake-build-cache";
|
const buildCacheFolder = '.xmake-build-cache';
|
||||||
|
|
||||||
let buildCacheKey = core.getInput('build-cache-key');
|
let buildCacheKey = core.getInput('build-cache-key');
|
||||||
if (!buildCacheKey) {
|
if (!buildCacheKey) {
|
||||||
@@ -68,16 +67,16 @@ export async function saveBuildCache(): Promise<void> {
|
|||||||
|
|
||||||
let buildCachePath = core.getInput('build-cache-path');
|
let buildCachePath = core.getInput('build-cache-path');
|
||||||
if (!buildCachePath) {
|
if (!buildCachePath) {
|
||||||
buildCachePath = "build/.build_cache";
|
buildCachePath = 'build/.build_cache';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buildCacheFolder && process.env.GITHUB_WORKSPACE) {
|
if (buildCacheFolder && process.env.GITHUB_WORKSPACE && fsutils.isDir(buildCachePath)) {
|
||||||
cacheDir = path.join(process.env.GITHUB_WORKSPACE, buildCacheFolder);
|
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, buildCacheFolder);
|
||||||
core.info(`save build cache path: ${buildCachePath} to ${cacheDir}, key: ${cacheKey}`);
|
core.info(`Save build cache path: ${buildCachePath} to ${fullCachePath}, key: ${cacheKey}`);
|
||||||
await io.cp(buildCachePath, cacheDir, {
|
await io.cp(buildCachePath, fullCachePath, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
await exec("xmake", ["l", "io.touch", path.join(cacheDir, "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], cacheKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
export function isFile(filepath: string): boolean {
|
||||||
|
try {
|
||||||
|
fs.accessSync(filepath, fs.constants.F_OK);
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isDir(filepath: string): boolean {
|
||||||
|
try {
|
||||||
|
const stats = fs.statSync(filepath);
|
||||||
|
if (stats.isDirectory()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import { exec } from '@actions/exec';
|
import { exec } from '@actions/exec';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
import * as toolCache from '@actions/tool-cache';
|
|
||||||
import * as cache from '@actions/cache';
|
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';
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Xmake cache
|
||||||
|
.xmake/
|
||||||
|
build/
|
||||||
|
|
||||||
|
# MacOS Cache
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
std::cout << "hello world!" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
add_rules("mode.debug", "mode.release")
|
||||||
|
|
||||||
|
add_requires("libpng", {system = false})
|
||||||
|
|
||||||
|
target("sample")
|
||||||
|
set_kind("binary")
|
||||||
|
add_files("src/*.cpp")
|
||||||
|
add_packages("libpng")
|
||||||
|
|
||||||
Reference in New Issue
Block a user