Skip to content

Commit

Permalink
- doNotCache default's is true
Browse files Browse the repository at this point in the history
- add vcpkg to PATH
- code fix ups
  • Loading branch information
lukka committed Apr 2, 2023
1 parent a5d1f94 commit 20a2cd0
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 177 deletions.
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ inputs:
required: false
description: "Avoid to update vcpkg (launching git) in the specified 'vcpkgDirectory'. This is useful when vcpkg is being checkout independently of the run-vcpkg action. Default is false."
doNotCache:
default: false
default: true
required: false
description: "Disable the run-vcpkg's automatic caching mechanism by setting it to true. Default is false. This does not disable vcpkg's binary cache which is always on."
description: "Enable the caching of the vcpkg executable and its data files (e.g. ports) by setting it to false. Default is true. Set this input to false when the vcpkg's executable is not delivered as a prebuilt file upon bootstrapping vcpkg. This does not disable vcpkg's binary cache which is always on and can be controlled by the user with the env var VCPKG_BINARY_SOURCES."

# The following inputs are rarely set by the user, since the default values suffice the most common scenarios.
vcpkgJsonGlob:
Expand Down
123 changes: 65 additions & 58 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,19 @@ class VcpkgAction {
constructor(baseUtilLib) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
this.baseUtilLib = baseUtilLib;
this.doNotCache = false;
this.doNotCache = true;
this.runVcpkgInstall = false;
this.doNotUpdateVcpkg = false;
// Fetch inputs.
const vcpkgRootDir = baseUtilLib.baseLib.getPathInput(exports.vcpkgDirectoryInput, false, false);
this.vcpkgRootDir = vcpkgRootDir ? path.normalize(path.resolve(vcpkgRootDir)) : null;
this.userProvidedCommitId = (_a = baseUtilLib.baseLib.getInput(exports.vcpkgCommitIdInput, false)) !== null && _a !== void 0 ? _a : null;
this.runVcpkgFormatString = (_b = baseUtilLib.baseLib.getInput(exports.runVcpkgFormatStringInput, false)) !== null && _b !== void 0 ? _b : null;
this.vcpkgJsonGlob = (_c = baseUtilLib.baseLib.getInput(exports.vcpkgJsonGlobInput, false)) !== null && _c !== void 0 ? _c : VcpkgAction.VCPKGJSON_GLOB;
this.vcpkgJsonIgnores = eval((_d = baseUtilLib.baseLib.getInput(exports.vcpkgJsonIgnoresInput, false)) !== null && _d !== void 0 ? _d : VcpkgAction.VCPKGJSON_IGNORES);
this.runVcpkgInstall = (_e = baseUtilLib.baseLib.getBoolInput(exports.runVcpkgInstallInput, false)) !== null && _e !== void 0 ? _e : false;
this.doNotCache = (_f = baseUtilLib.baseLib.getBoolInput(exports.doNotCacheInput, false)) !== null && _f !== void 0 ? _f : false;
this.doNotUpdateVcpkg = (_g = baseUtilLib.baseLib.getBoolInput(exports.doNotUpdateVcpkgInput, false)) !== null && _g !== void 0 ? _g : false;
this.runVcpkgInstall = (_e = baseUtilLib.baseLib.getBoolInput(exports.runVcpkgInstallInput, false)) !== null && _e !== void 0 ? _e : this.runVcpkgInstall;
this.doNotCache = (_f = baseUtilLib.baseLib.getBoolInput(exports.doNotCacheInput, false)) !== null && _f !== void 0 ? _f : this.doNotCache;
this.doNotUpdateVcpkg = (_g = baseUtilLib.baseLib.getBoolInput(exports.doNotUpdateVcpkgInput, false)) !== null && _g !== void 0 ? _g : this.doNotUpdateVcpkg;
this.vcpkgUrl = (_h = baseUtilLib.baseLib.getInput(exports.vcpkgUrlInput, false)) !== null && _h !== void 0 ? _h : VcpkgAction.DEFAULTVCPKGURL;
this.vcpkgCommitId = (_j = baseUtilLib.baseLib.getInput(exports.vcpkgCommitIdInput, false)) !== null && _j !== void 0 ? _j : null;
this.logCollectionRegExps = (_k = baseUtilLib.baseLib.getDelimitedInput(exports.logCollectionRegExpsInput, ';', false)) !== null && _k !== void 0 ? _k : [];
Expand Down Expand Up @@ -146,44 +148,46 @@ class VcpkgAction {
}
return [keys, vcpkgJsonPath];
}));
const isCacheHit = yield this.baseUtilLib.wrapOp('Restore vcpkg installation from cache (not the packages, that is done by vcpkg via binary caching using GitHub Action cache)', () => __awaiter(this, void 0, void 0, function* () { return yield this.restoreCache(keys); }));
const isCacheHit = yield this.restoreCache(keys);
const vcpkgJsonPath = yield this.getCurrentDirectoryForRunningVcpkg(vcpkgJsonFilePath);
yield runvcpkglib.VcpkgRunner.run(this.baseUtilLib, this.vcpkgRootDir, this.vcpkgUrl, this.vcpkgCommitId, this.runVcpkgInstall, this.doNotUpdateVcpkg, this.logCollectionRegExps, vcpkgJsonPath, this.runVcpkgFormatString);
yield this.saveCache(isCacheHit, keys, vcpkgutil.Utils.getAllCachedPaths(this.baseUtilLib.baseLib, this.vcpkgRootDir // HACK: if it were not set it would have thrown before.
yield this.saveCache(isCacheHit, keys, vcpkgutil.Utils.getAllCachedPaths(this.baseUtilLib.baseLib, this.vcpkgRootDir // HACK: if it were not set it would have thrown an exception before.
), this.doNotCache, true);
this.baseUtilLib.baseLib.debug("run()>>");
});
}
restoreCache(keys) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
let isCacheHit = false;
this.baseUtilLib.baseLib.debug("restoreCache()<<");
if (this.doNotCache) {
this.baseUtilLib.baseLib.info(`Skipping restoring cache as caching is disabled (${exports.doNotCacheInput}: ${this.doNotCache}).`);
this.baseUtilLib.baseLib.debug(`Skipping restoring vcpkg as caching is disabled (${exports.doNotCacheInput}: ${this.doNotCache}).`);
}
else {
if (!this.vcpkgRootDir)
throw new Error("vcpkg_ROOT must be defined");
const pathsToCache = vcpkgutil.Utils.getAllCachedPaths(this.baseUtilLib.baseLib, this.vcpkgRootDir);
this.baseUtilLib.baseLib.info(`Cache key: '${keys.primary}'`);
this.baseUtilLib.baseLib.info(`Cache restore keys: '${keys.restore}'`);
this.baseUtilLib.baseLib.info(`Cached paths: '${pathsToCache}'`);
let keyCacheHit;
try {
keyCacheHit = yield cache.restoreCache(pathsToCache, keys.primary, keys.restore);
}
catch (err) {
this.baseUtilLib.baseLib.warning(`cache.restoreCache() failed: '${(_b = (_a = err) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : "<undefined error>"}', skipping restoring from cache.`);
}
if (keyCacheHit) {
this.baseUtilLib.baseLib.info(`Cache hit, key = '${keyCacheHit}'.`);
isCacheHit = true;
}
else {
this.baseUtilLib.baseLib.info(`Cache miss.`);
isCacheHit = false;
}
yield this.baseUtilLib.wrapOp('Restore vcpkg installation from cache (not the packages, that is done by vcpkg via Binary Caching stored onto the GitHub Action cache)', () => __awaiter(this, void 0, void 0, function* () {
var _a, _b;
if (!this.vcpkgRootDir)
throw new Error("VCPKG_ROOT must be defined");
const pathsToCache = vcpkgutil.Utils.getAllCachedPaths(this.baseUtilLib.baseLib, this.vcpkgRootDir);
this.baseUtilLib.baseLib.info(`Cache key: '${keys.primary}'`);
this.baseUtilLib.baseLib.info(`Cache restore keys: '${keys.restore}'`);
this.baseUtilLib.baseLib.info(`Cached paths: '${pathsToCache}'`);
let keyCacheHit;
try {
keyCacheHit = yield cache.restoreCache(pathsToCache, keys.primary, keys.restore);
}
catch (err) {
this.baseUtilLib.baseLib.warning(`cache.restoreCache() failed: '${(_b = (_a = err) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : "<undefined error>"}', skipping restoring from cache.`);
}
if (keyCacheHit) {
this.baseUtilLib.baseLib.info(`Cache hit, key = '${keyCacheHit}'.`);
isCacheHit = true;
}
else {
this.baseUtilLib.baseLib.info(`Cache miss.`);
isCacheHit = false;
}
}));
}
this.baseUtilLib.baseLib.debug("restoreCache()>>");
return isCacheHit;
Expand All @@ -192,9 +196,7 @@ class VcpkgAction {
saveCache(isCacheHit, keys, cachedPaths, doNotCache, successStep) {
return __awaiter(this, void 0, void 0, function* () {
this.baseUtilLib.baseLib.debug('saveCache()<<');
yield this.baseUtilLib.wrapOp('Save vcpkg into the GitHub Action cache (only the tool, not the built packages which are saved by vcpkg`s Binary Caching on GitHub Action`s cache).', () => __awaiter(this, void 0, void 0, function* () {
return yield vcpkgutil.Utils.saveCache(this.baseUtilLib.baseLib, this.doNotCache, keys, isCacheHit ? keys.primary : null, /* Only the primary cache could have hit, since there are no restore keys. */ cachedPaths);
}));
yield vcpkgutil.Utils.saveCache(this.baseUtilLib, this.doNotCache, keys, isCacheHit ? keys.primary : null, /* Only the primary cache could have hit, since there are no restore keys. */ cachedPaths);
this.baseUtilLib.baseLib.debug('saveCache()>>');
});
}
Expand All @@ -207,8 +209,7 @@ class VcpkgAction {
vcpkgJsonPath = vcpkgJsonFile === null ? null : path.dirname(path.resolve(vcpkgJsonFile));
this.baseUtilLib.baseLib.debug(`vcpkgJsonFile='${vcpkgJsonFile}', vcpkgJsonPath='${vcpkgJsonPath}'.`);
if (vcpkgJsonPath === null) {
this.baseUtilLib.baseLib.error(`Failing the workflow since the 'vcpkg.json' file has not been found, and its containing directory
is required and used as the 'working directory' when launching vcpkg with arguments:
this.baseUtilLib.baseLib.error(`Failing the workflow since the 'vcpkg.json' file has not been found: its directory is used as the 'working directory' when launching vcpkg with arguments:
'${this.runVcpkgFormatString}'. `);
}
}
Expand Down Expand Up @@ -253,7 +254,6 @@ const runvcpkglib = __nccwpck_require__(4393);
const baseutillib = __nccwpck_require__(2365);
const cache = __nccwpck_require__(7799);
const fastglob = __nccwpck_require__(3664);
const vcpkg_action_1 = __nccwpck_require__(2929);
class Utils {
static isExactKeyMatch(key, cacheKey) {
if (cacheKey)
Expand Down Expand Up @@ -364,39 +364,42 @@ class Utils {
return keyset;
});
}
static saveCache(baseLib, doNotCache, keys, hitCacheKey, cachedPaths) {
static saveCache(baseUtilLib, doNotCache, keys, hitCacheKey, cachedPaths) {
return __awaiter(this, void 0, void 0, function* () {
const baseLib = baseUtilLib.baseLib;
baseLib.debug(`saveCache(doNotCache:${doNotCache},keys:${JSON.stringify(keys)},hitCacheKey:${hitCacheKey},cachedPaths:${cachedPaths})<<`);
try {
if (doNotCache) {
baseLib.info(`Skipping saving cache as caching is disabled (${vcpkg_action_1.doNotCacheInput}: ${doNotCache}).`);
baseLib.debug(`Skipping saving cache as caching is disabled by default. See DoNotCache input.`);
}
else {
if (hitCacheKey && Utils.isExactKeyMatch(keys.primary, hitCacheKey)) {
baseLib.info(`Saving cache is skipped, because cache hit occurred on the cache key '${keys.primary}'.`);
}
else {
baseLib.info(`Saving a new cache entry, because primary key was missed or a fallback restore key was hit.`);
const pathsToCache = cachedPaths;
baseLib.info(`Caching paths: '${pathsToCache}'`);
try {
baseLib.info(`Saving cache with primary key '${keys.primary}' ...`);
yield cache.saveCache(pathsToCache, keys.primary);
yield baseUtilLib.wrapOp('Save vcpkg into the GitHub Action cache (only the tool, not the built packages which are saved by vcpkg`s Binary Caching on GitHub Action`s cache).', () => __awaiter(this, void 0, void 0, function* () {
if (hitCacheKey && Utils.isExactKeyMatch(keys.primary, hitCacheKey)) {
baseLib.info(`Saving cache is skipped, because cache hit occurred on the cache key '${keys.primary}'.`);
}
catch (error) {
if (error instanceof Error) {
if (error.name === cache.ValidationError.name) {
throw error;
}
else if (error.name === cache.ReserveCacheError.name) {
baseLib.info(error.message);
}
else {
baseLib.warning(error.message);
else {
baseLib.info(`Saving a new cache entry, because primary key was missed or a fallback restore key was hit.`);
const pathsToCache = cachedPaths;
baseLib.info(`Caching paths: '${pathsToCache}'`);
try {
baseLib.info(`Saving cache with primary key '${keys.primary}' ...`);
yield cache.saveCache(pathsToCache, keys.primary);
}
catch (error) {
if (error instanceof Error) {
if (error.name === cache.ValidationError.name) {
throw error;
}
else if (error.name === cache.ReserveCacheError.name) {
baseLib.info(error.message);
}
else {
baseLib.warning(error.message);
}
}
}
}
}
}));
}
}
catch (err) {
Expand Down Expand Up @@ -42276,6 +42279,9 @@ class ActionLib {
hashFiles(fileGlob, options) {
return actionglob.hashFiles(fileGlob, options);
}
addPath(path) {
core.addPath(path);
}
}
exports.ActionLib = ActionLib;
//# sourceMappingURL=action-lib.js.map
Expand Down Expand Up @@ -44154,6 +44160,7 @@ class VcpkgRunner {
if (needRebuild) {
yield this.baseUtils.wrapOp("Build vcpkg executable", () => this.build());
}
this.baseUtils.wrapOpSync(`Add to PATH vcpkg at '${this.vcpkgDestPath}'`, () => this.baseUtils.baseLib.addPath(this.vcpkgDestPath));
yield this.runVcpkgInstall();
this.baseUtils.wrapOpSync("Set output environment variables", () => this.setOutputs());
this.baseUtils.baseLib.debug("runImpl()>>");
Expand Down

0 comments on commit 20a2cd0

Please sign in to comment.