Skip to content

Commit eb8f440

Browse files
committed
improve cache key
1 parent 5d3a04c commit eb8f440

File tree

6 files changed

+80
-58
lines changed

6 files changed

+80
-58
lines changed

dist/index.js

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70512,9 +70512,9 @@ const core = __nccwpck_require__(7484);
7051270512
const exec_1 = __nccwpck_require__(5236);
7051370513
const io = __nccwpck_require__(4994);
7051470514
const cache = __nccwpck_require__(5116);
70515-
const os = __nccwpck_require__(857);
7051670515
const path = __nccwpck_require__(6928);
7051770516
const fsutils = __nccwpck_require__(7999);
70517+
const system_1 = __nccwpck_require__(7666);
7051870518
function getBuildTime(hours) {
7051970519
let key = 'BuildTime';
7052070520
if (hours && hours !== '') {
@@ -70545,16 +70545,16 @@ function getProjectRootPath() {
7054570545
}
7054670546
return projectRootPath;
7054770547
}
70548-
function getBuildCacheKey(buildCacheTime) {
70549-
var _a;
70548+
async function getBuildCacheKey(buildCacheTime) {
7055070549
let buildCacheKey = core.getInput('build-cache-key');
7055170550
if (!buildCacheKey) {
7055270551
buildCacheKey = '';
7055370552
}
7055470553
if (!buildCacheTime || buildCacheTime === '') {
7055570554
buildCacheTime = getBuildTime();
7055670555
}
70557-
return `xmake-build-cache-${buildCacheKey}-${buildCacheTime}-${os.arch()}-${os.platform()}-${(_a = process.env.RUNNER_OS) !== null && _a !== void 0 ? _a : 'unknown'}`;
70556+
const platformIdentifier = await (0, system_1.getPlatformIdentifier)();
70557+
return `xmake-build-cache-${buildCacheKey}-${buildCacheTime}-${platformIdentifier}`;
7055870558
}
7055970559
async function getBuildCachePath() {
7056070560
let buildCachePath = core.getInput('build-cache-path');
@@ -70611,7 +70611,7 @@ async function loadBuildCache() {
7061170611
if (hours < 0) {
7061270612
break;
7061370613
}
70614-
const buildCacheKey = getBuildCacheKey(getBuildTime(String(hours).padStart(2, '0')));
70614+
const buildCacheKey = await getBuildCacheKey(getBuildTime(String(hours).padStart(2, '0')));
7061570615
if (!fsutils.isFile(filepath)) {
7061670616
core.info(`Restore build cache path: ${fullCachePath} to ${buildCachePath}, key: ${buildCacheKey}`);
7061770617
await cache.restoreCache([buildCacheFolder], buildCacheKey);
@@ -70644,7 +70644,7 @@ async function saveBuildCache() {
7064470644
return;
7064570645
}
7064670646
const buildCacheFolder = getBuildCacheFolder();
70647-
const buildCacheKey = getBuildCacheKey();
70647+
const buildCacheKey = await getBuildCacheKey();
7064870648
const buildCachePath = await getBuildCachePath();
7064970649
const hitBuildCache = !!core.getState('hitBuildCache');
7065070650
if (!hitBuildCache && buildCacheFolder && process.env.GITHUB_WORKSPACE && fsutils.isDir(buildCachePath)) {
@@ -70832,9 +70832,9 @@ const core = __nccwpck_require__(7484);
7083270832
const exec_1 = __nccwpck_require__(5236);
7083370833
const io = __nccwpck_require__(4994);
7083470834
const cache = __nccwpck_require__(5116);
70835-
const os = __nccwpck_require__(857);
7083670835
const path = __nccwpck_require__(6928);
7083770836
const fsutils = __nccwpck_require__(7999);
70837+
const system_1 = __nccwpck_require__(7666);
7083870838
function getProjectRootPath() {
7083970839
let projectRootPath = core.getInput('project-path');
7084070840
if (!projectRootPath) {
@@ -70847,7 +70847,6 @@ function getProjectRootPath() {
7084770847
return projectRootPath;
7084870848
}
7084970849
async function getPackageCacheKey() {
70850-
var _a;
7085170850
let packageCacheKey = core.getInput('package-cache-key');
7085270851
if (!packageCacheKey) {
7085370852
packageCacheKey = '';
@@ -70870,7 +70869,8 @@ async function getPackageCacheKey() {
7087070869
await (0, exec_1.exec)('xmake', ['l', 'utils.ci.packageskey'], options);
7087170870
packageCacheHash = packageCacheHash.trim();
7087270871
}
70873-
return `xmake-package-cache-${packageCacheKey}-${packageCacheHash}-${os.arch()}-${os.platform()}-${(_a = process.env.RUNNER_OS) !== null && _a !== void 0 ? _a : 'unknown'}`;
70872+
const platformIdentifier = await (0, system_1.getPlatformIdentifier)();
70873+
return `xmake-package-cache-${packageCacheKey}-${packageCacheHash}-${platformIdentifier}`;
7087470874
}
7087570875
async function getPackageCachePath() {
7087670876
let packageCachePath = '';
@@ -70976,23 +70976,16 @@ if (!exports.IsPost) {
7097670976

7097770977
/***/ }),
7097870978

70979-
/***/ 9095:
70979+
/***/ 7666:
7098070980
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
7098170981

7098270982
"use strict";
7098370983

7098470984
Object.defineProperty(exports, "__esModule", ({ value: true }));
70985-
exports.unixInstall = unixInstall;
70985+
exports.getPlatformIdentifier = getPlatformIdentifier;
7098670986
const core = __nccwpck_require__(7484);
7098770987
const exec_1 = __nccwpck_require__(5236);
70988-
const io = __nccwpck_require__(4994);
70989-
const toolCache = __nccwpck_require__(3472);
70990-
const cache = __nccwpck_require__(5116);
7099170988
const os = __nccwpck_require__(857);
70992-
const fs = __nccwpck_require__(9896);
70993-
const path = __nccwpck_require__(6928);
70994-
const semver = __nccwpck_require__(2088);
70995-
const git = __nccwpck_require__(1243);
7099670989
async function getPlatformIdentifier() {
7099770990
var _a;
7099870991
let identifier = `${os.platform()}-${os.arch()}-${(_a = process.env.RUNNER_OS) !== null && _a !== void 0 ? _a : 'unknown'}`;
@@ -71017,6 +71010,28 @@ async function getPlatformIdentifier() {
7101771010
}
7101871011
return identifier;
7101971012
}
71013+
71014+
71015+
/***/ }),
71016+
71017+
/***/ 9095:
71018+
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
71019+
71020+
"use strict";
71021+
71022+
Object.defineProperty(exports, "__esModule", ({ value: true }));
71023+
exports.unixInstall = unixInstall;
71024+
const core = __nccwpck_require__(7484);
71025+
const exec_1 = __nccwpck_require__(5236);
71026+
const io = __nccwpck_require__(4994);
71027+
const toolCache = __nccwpck_require__(3472);
71028+
const cache = __nccwpck_require__(5116);
71029+
const os = __nccwpck_require__(857);
71030+
const fs = __nccwpck_require__(9896);
71031+
const path = __nccwpck_require__(6928);
71032+
const semver = __nccwpck_require__(2088);
71033+
const git = __nccwpck_require__(1243);
71034+
const system_1 = __nccwpck_require__(7666);
7102071035
async function install(sourceDir, binDir) {
7102171036
if (fs.existsSync(path.join(sourceDir, 'configure'))) {
7102271037
await (0, exec_1.exec)('sh', ['./configure'], { cwd: sourceDir });
@@ -71038,7 +71053,7 @@ async function unixInstall(version) {
7103871053
if (version.type !== 'local') {
7103971054
const ver = version.version;
7104071055
const sha = version.sha;
71041-
const platformIdentifier = await getPlatformIdentifier();
71056+
const platformIdentifier = await (0, system_1.getPlatformIdentifier)();
7104271057
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${platformIdentifier}`;
7104371058
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
7104471059
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
@@ -71287,6 +71302,7 @@ const fs = __nccwpck_require__(9896);
7128771302
const path = __nccwpck_require__(6928);
7128871303
const semver = __nccwpck_require__(2088);
7128971304
const git = __nccwpck_require__(1243);
71305+
const system_1 = __nccwpck_require__(7666);
7129071306
function getInstallerUrl(version, latest) {
7129171307
let ver = version.version;
7129271308
switch (version.type) {
@@ -71322,7 +71338,6 @@ async function installFromSource(xmakeBin, sourceDir, binDir) {
7132271338
await (0, exec_1.exec)(xmakeBin, ['install', '-o', binDir, 'cli'], { cwd: sourceDir });
7132371339
}
7132471340
async function winInstall(version, latest) {
71325-
var _a;
7132671341
if (version.type === 'local' || latest.type === 'local') {
7132771342
throw new Error('Local builds for windows is not supported');
7132871343
}
@@ -71333,22 +71348,23 @@ async function winInstall(version, latest) {
7133371348
}
7133471349
const ver = version.version;
7133571350
const sha = version.sha;
71336-
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${os.arch()}-${os.platform()}-${(_a = process.env.RUNNER_OS) !== null && _a !== void 0 ? _a : 'unknown'}`;
71351+
const platformIdentifier = await (0, system_1.getPlatformIdentifier)();
71352+
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${platformIdentifier}`;
7133771353
let toolDir = '';
7133871354
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
7133971355
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
7134071356
try {
7134171357
try {
7134271358
fs.accessSync(path.join(fullCachePath, 'xmake.exe'), fs.constants.X_OK);
7134371359
}
71344-
catch (_b) {
71360+
catch (_a) {
7134571361
await cache.restoreCache([actionsCacheFolder], cacheKey);
7134671362
}
7134771363
fs.accessSync(path.join(fullCachePath, 'xmake.exe'), fs.constants.X_OK);
7134871364
toolDir = fullCachePath;
7134971365
core.info(`cache path: ${toolDir}, key: ${cacheKey}`);
7135071366
}
71351-
catch (_c) {
71367+
catch (_b) {
7135271368
core.warning(`No cached files found at path "${fullCachePath}".`);
7135371369
await io.rmRF(fullCachePath);
7135471370
}

src/build-cache.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as core from '@actions/core';
22
import { exec, ExecOptions } from '@actions/exec';
33
import * as io from '@actions/io';
44
import * as cache from '@actions/cache';
5-
import * as os from 'os';
65
import * as path from 'path';
76
import * as fsutils from './fsutils';
7+
import { getPlatformIdentifier } from './system';
88

99
function getBuildTime(hours?: string): string {
1010
let key = 'BuildTime';
@@ -38,15 +38,16 @@ function getProjectRootPath(): string {
3838
return projectRootPath;
3939
}
4040

41-
function getBuildCacheKey(buildCacheTime?: string): string {
41+
async function getBuildCacheKey(buildCacheTime?: string): Promise<string> {
4242
let buildCacheKey = core.getInput('build-cache-key');
4343
if (!buildCacheKey) {
4444
buildCacheKey = '';
4545
}
4646
if (!buildCacheTime || buildCacheTime === '') {
4747
buildCacheTime = getBuildTime();
4848
}
49-
return `xmake-build-cache-${buildCacheKey}-${buildCacheTime}-${os.arch()}-${os.platform()}-${process.env.RUNNER_OS ?? 'unknown'}`;
49+
const platformIdentifier = await getPlatformIdentifier();
50+
return `xmake-build-cache-${buildCacheKey}-${buildCacheTime}-${platformIdentifier}`;
5051
}
5152

5253
async function getBuildCachePath(): Promise<string> {
@@ -112,7 +113,7 @@ export async function loadBuildCache(): Promise<void> {
112113
if (hours < 0) {
113114
break;
114115
}
115-
const buildCacheKey = getBuildCacheKey(getBuildTime(String(hours).padStart(2, '0')));
116+
const buildCacheKey = await getBuildCacheKey(getBuildTime(String(hours).padStart(2, '0')));
116117
if (!fsutils.isFile(filepath)) {
117118
core.info(`Restore build cache path: ${fullCachePath} to ${buildCachePath}, key: ${buildCacheKey}`);
118119
await cache.restoreCache([buildCacheFolder], buildCacheKey);
@@ -147,7 +148,7 @@ export async function saveBuildCache(): Promise<void> {
147148
}
148149

149150
const buildCacheFolder = getBuildCacheFolder();
150-
const buildCacheKey = getBuildCacheKey();
151+
const buildCacheKey = await getBuildCacheKey();
151152
const buildCachePath = await getBuildCachePath();
152153

153154
const hitBuildCache = !!core.getState('hitBuildCache');

src/package-cache.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as core from '@actions/core';
22
import { exec, ExecOptions } from '@actions/exec';
33
import * as io from '@actions/io';
44
import * as cache from '@actions/cache';
5-
import * as os from 'os';
65
import * as path from 'path';
76
import * as fsutils from './fsutils';
7+
import { getPlatformIdentifier } from './system';
88

99
function getProjectRootPath(): string {
1010
let projectRootPath = core.getInput('project-path');
@@ -41,7 +41,8 @@ async function getPackageCacheKey(): Promise<string> {
4141
await exec('xmake', ['l', 'utils.ci.packageskey'], options);
4242
packageCacheHash = packageCacheHash.trim();
4343
}
44-
return `xmake-package-cache-${packageCacheKey}-${packageCacheHash}-${os.arch()}-${os.platform()}-${process.env.RUNNER_OS ?? 'unknown'}`;
44+
const platformIdentifier = await getPlatformIdentifier();
45+
return `xmake-package-cache-${packageCacheKey}-${packageCacheHash}-${platformIdentifier}`;
4546
}
4647

4748
async function getPackageCachePath(): Promise<string> {

src/system.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as core from '@actions/core';
2+
import { exec } from '@actions/exec';
3+
import * as os from 'os';
4+
5+
export async function getPlatformIdentifier(): Promise<string> {
6+
let identifier = `${os.platform()}-${os.arch()}-${process.env.RUNNER_OS ?? 'unknown'}`;
7+
if (os.platform() === 'darwin') {
8+
let productVersion = '';
9+
try {
10+
await exec('sw_vers', ['-productVersion'], {
11+
silent: true,
12+
listeners: {
13+
stdout: (data: Buffer) => {
14+
productVersion = data.toString().trim();
15+
},
16+
},
17+
});
18+
if (productVersion) {
19+
identifier += `-${productVersion}`;
20+
}
21+
} catch (error: unknown) {
22+
core.warning(
23+
`Failed to get macOS product version: ${error instanceof Error ? error.message : String(error)}`,
24+
);
25+
}
26+
}
27+
return identifier;
28+
}

src/unix-install.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,7 @@ import * as path from 'path';
99
import * as semver from 'semver';
1010
import * as git from './git';
1111
import { Version } from './interfaces';
12-
13-
async function getPlatformIdentifier(): Promise<string> {
14-
let identifier = `${os.platform()}-${os.arch()}-${process.env.RUNNER_OS ?? 'unknown'}`;
15-
if (os.platform() === 'darwin') {
16-
let productVersion = '';
17-
try {
18-
await exec('sw_vers', ['-productVersion'], {
19-
silent: true,
20-
listeners: {
21-
stdout: (data: Buffer) => {
22-
productVersion = data.toString().trim();
23-
},
24-
},
25-
});
26-
if (productVersion) {
27-
identifier += `-${productVersion}`;
28-
}
29-
} catch (error: unknown) {
30-
core.warning(
31-
`Failed to get macOS product version: ${error instanceof Error ? error.message : String(error)}`,
32-
);
33-
}
34-
}
35-
return identifier;
36-
}
12+
import { getPlatformIdentifier } from './system';
3713

3814
async function install(sourceDir: string, binDir: string): Promise<void> {
3915
if (fs.existsSync(path.join(sourceDir, 'configure'))) {

src/win-install.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as path from 'path';
99
import * as semver from 'semver';
1010
import * as git from './git';
1111
import { Version, GitVersion } from './interfaces';
12+
import { getPlatformIdentifier } from './system';
1213

1314
function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
1415
let ver = version.version;
@@ -59,9 +60,8 @@ export async function winInstall(version: Version, latest: Version): Promise<voi
5960

6061
const ver = version.version;
6162
const sha = version.sha;
62-
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${os.arch()}-${os.platform()}-${
63-
process.env.RUNNER_OS ?? 'unknown'
64-
}`;
63+
const platformIdentifier = await getPlatformIdentifier();
64+
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${platformIdentifier}`;
6565

6666
let toolDir = '';
6767
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {

0 commit comments

Comments
 (0)