From eefdee4a8214f05ca12a7a4a550f9d872bd6173d Mon Sep 17 00:00:00 2001 From: luca <681992+lukka@users.noreply.github.com> Date: Sat, 1 Apr 2023 17:14:38 -0700 Subject: [PATCH] - doNotCache default's is true - add vcpkg to PATH - code fix ups --- action.yml | 4 +- dist/index.js | 98 ++++++++++++++++-------------- package-lock.json | 94 ++++++++++++++--------------- package.json | 10 ++-- src/vcpkg-action.ts | 142 +++++++++++++++++++++++--------------------- src/vcpkg-utils.ts | 53 +++++++++-------- 6 files changed, 210 insertions(+), 191 deletions(-) diff --git a/action.yml b/action.yml index e50f14d2..2e3cdabd 100644 --- a/action.yml +++ b/action.yml @@ -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: diff --git a/dist/index.js b/dist/index.js index 20d1c3d2..6a689dcd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -94,7 +94,9 @@ 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; @@ -102,9 +104,9 @@ class VcpkgAction { 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 : []; @@ -134,37 +136,49 @@ class VcpkgAction { if (!this.vcpkgRootDir) { throw new Error(`vcpkgRootDir is not defined!`); } - const [keys, vcpkgJsonFilePath] = yield this.baseUtilLib.wrapOp('Compute vcpkg cache key', () => __awaiter(this, void 0, void 0, function* () { - const vcpkgJsonPath = yield vcpkgutil.Utils.getVcpkgJsonPath(this.baseUtilLib, this.vcpkgJsonGlob, this.vcpkgJsonIgnores); - const keys = yield vcpkgutil.Utils.computeCacheKeys(this.baseUtilLib, this.vcpkgRootDir, // HACK: if it were not set it would have thrown before. - this.userProvidedCommitId); - if (keys && vcpkgJsonPath) { - baseLib.info(`Computed key: ${JSON.stringify(keys)}`); - } - else { - throw new Error("Computation for the cache key or the vcpkg.json location failed!"); - } - 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 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. - ), this.doNotCache, true); + let vcpkgJsonFilePath = null; + const vcpkgJsonPath = yield vcpkgutil.Utils.getVcpkgJsonPath(this.baseUtilLib, this.vcpkgJsonGlob, this.vcpkgJsonIgnores); + vcpkgJsonFilePath = yield this.getCurrentDirectoryForRunningVcpkg(vcpkgJsonPath); + let isCacheHit = null; + let cacheKey = null; + if (this.doNotCache) { + this.baseUtilLib.baseLib.debug(`Skipping restoring vcpkg as caching is disabled. Set input 'doNotCache:false' to enable caching.`); + } + else { + cacheKey = + yield this.baseUtilLib.wrapOp('Compute vcpkg cache key', () => __awaiter(this, void 0, void 0, function* () { + const keys = yield vcpkgutil.Utils.computeCacheKeys(this.baseUtilLib, this.vcpkgRootDir, // HACK: if it were not set it would have thrown before. + this.userProvidedCommitId); + if (keys && vcpkgJsonPath) { + baseLib.info(`Computed key: ${JSON.stringify(keys)}`); + } + else { + throw new Error("Computation for the cache key failed!"); + } + return keys; + })); + isCacheHit = yield this.restoreCache(cacheKey); + } + yield runvcpkglib.VcpkgRunner.run(this.baseUtilLib, this.vcpkgRootDir, this.vcpkgUrl, this.vcpkgCommitId, this.runVcpkgInstall, this.doNotUpdateVcpkg, this.logCollectionRegExps, vcpkgJsonFilePath, this.runVcpkgFormatString); + if (this.doNotCache) { + this.baseUtilLib.baseLib.debug(`Skipping restoring vcpkg as caching is disabled. Set input 'doNotCache:false' to enable caching.`); + } + else { + yield this.saveCache(isCacheHit, cacheKey, // Hack: if it were not set it would have thrown an exception before. + vcpkgutil.Utils.getAllCachedPaths(this.baseUtilLib.baseLib, this.vcpkgRootDir // HACK: if it were not set it would have thrown an exception before. + ), 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}).`); - } - else { + 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"); + 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}'`); @@ -184,31 +198,28 @@ class VcpkgAction { this.baseUtilLib.baseLib.info(`Cache miss.`); isCacheHit = false; } - } + })); this.baseUtilLib.baseLib.debug("restoreCache()>>"); return isCacheHit; }); } - saveCache(isCacheHit, keys, cachedPaths, doNotCache, successStep) { + saveCache(isCacheHit, keys, cachedPaths, 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, keys, isCacheHit ? keys.primary : null, /* Only the primary cache could have hit, since there are no restore keys. */ cachedPaths); this.baseUtilLib.baseLib.debug('saveCache()>>'); }); } getCurrentDirectoryForRunningVcpkg(vcpkgJsonFile) { return __awaiter(this, void 0, void 0, function* () { - this.baseUtilLib.baseLib.debug(`getCurrentDirectoryForRunningVcpkg() << `); + this.baseUtilLib.baseLib.debug(`getCurrentDirectoryForRunningVcpkg(${vcpkgJsonFile}) << `); // When running 'vcpkg install' is requested, ensure the target directory is well known, fail otherwise. let vcpkgJsonPath = null; if (this.runVcpkgInstall) { 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}'. `); } } @@ -253,7 +264,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) @@ -364,14 +374,12 @@ class Utils { return keyset; }); } - static saveCache(baseLib, doNotCache, keys, hitCacheKey, cachedPaths) { + static saveCache(baseUtilLib, keys, hitCacheKey, cachedPaths) { return __awaiter(this, void 0, void 0, function* () { - baseLib.debug(`saveCache(doNotCache:${doNotCache},keys:${JSON.stringify(keys)},hitCacheKey:${hitCacheKey},cachedPaths:${cachedPaths})<<`); + const baseLib = baseUtilLib.baseLib; + baseLib.debug(`saveCache(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}).`); - } - else { + 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}'.`); } @@ -397,7 +405,7 @@ class Utils { } } } - } + })); } catch (err) { baseLib.warning("vcpkg-utils.saveCache() failed!"); @@ -42276,6 +42284,9 @@ class ActionLib { hashFiles(fileGlob, options) { return actionglob.hashFiles(fileGlob, options); } + addPath(path) { + core.addPath(path); + } } exports.ActionLib = ActionLib; //# sourceMappingURL=action-lib.js.map @@ -44154,6 +44165,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()>>"); diff --git a/package-lock.json b/package-lock.json index 991431f4..e4672082 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,11 +14,11 @@ "@actions/exec": "^1.1.1", "@actions/github": "^5.0.3", "@actions/io": "^1.1.2", - "@lukka/action-lib": "3.5.0", - "@lukka/assets-lib": "3.5.0", - "@lukka/base-lib": "3.5.0", - "@lukka/base-util-lib": "3.5.0", - "@lukka/run-vcpkg-lib": "3.5.0", + "@lukka/action-lib": "3.5.1", + "@lukka/assets-lib": "3.5.1", + "@lukka/base-lib": "3.5.1", + "@lukka/base-util-lib": "3.5.1", + "@lukka/run-vcpkg-lib": "3.5.1", "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.14.1", "@types/jest": "^26.0.14", @@ -1363,9 +1363,9 @@ } }, "node_modules/@lukka/action-lib": { - "version": "3.5.0", - "resolved": "https://npm.pkg.github.com/download/@lukka/action-lib/3.5.0/3932ea106e1a680784f30c697aa725d12c27fc16", - "integrity": "sha512-0UmsujYQmr+CraBnT4HaU4IYnw5LAQUEUm6b5VsM5l7sLlkvWh1qvBJIH6irLCeWjHFSRCLS2SYzbjbJbBUSyA==", + "version": "3.5.1", + "resolved": "https://npm.pkg.github.com/download/@lukka/action-lib/3.5.1/e34cf68ac51e892a180070634599a2577dcf31b5", + "integrity": "sha512-U1A8UMJiigfqyuERmbepiFlxoBxAAHZARbm/q4tikuhAGXMRo05DvQ5ypTEW2Uti0okrCwi/hF063w2Ha0ooeQ==", "license": "MIT", "dependencies": { "@actions/core": "^1.9.1", @@ -1373,8 +1373,8 @@ "@actions/github": "^5.0.3", "@actions/glob": "^0.3.0", "@actions/io": "^1.1.2", - "@lukka/base-lib": "^3.5.0", - "@lukka/base-util-lib": "^3.5.0", + "@lukka/base-lib": "^3.5.1", + "@lukka/base-util-lib": "^3.5.1", "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.14.1", "@types/q": "^1.5.1", @@ -1808,15 +1808,15 @@ } }, "node_modules/@lukka/assets-lib": { - "version": "3.5.0", - "resolved": "https://npm.pkg.github.com/download/@lukka/assets-lib/3.5.0/6b369cc8f8baa8f8e4bb0748b03523686c5702fc", - "integrity": "sha512-suMPsDQ9E6OuNWanIv3hFWbCksCa3XX2RdCRdbpHC1EG4r9Idp9eQE+MbvLeZRIUnyOhzqnuwMNwGdcytS6HEg==", + "version": "3.5.1", + "resolved": "https://npm.pkg.github.com/download/@lukka/assets-lib/3.5.1/1ed4fdc57bd3a56f1531101644181c6c56188bff", + "integrity": "sha512-OL7TXFL/6mgyiKt7UEStPXQdsRpebMxEHHwpyu9by401zC9GdEs8a8z9ajclfXgWNHpjN9bpfMg5679I4J3agw==", "license": "MIT" }, "node_modules/@lukka/base-lib": { - "version": "3.5.0", - "resolved": "https://npm.pkg.github.com/download/@lukka/base-lib/3.5.0/6d83fffd2f802631d2e6eb3f2be62ef022cf89e1", - "integrity": "sha512-lEa4XorbTFwHUIRNKKavuo/roQeK50WZMZLVVhgO4aF0kQU2Tx6mtwodG0KzVFQsv/jmahJFYOkrX39y9+RCBA==", + "version": "3.5.1", + "resolved": "https://npm.pkg.github.com/download/@lukka/base-lib/3.5.1/9eb1450ff87d6b6a9166da100df05f4cbf4a71a9", + "integrity": "sha512-CA1ea23sxAZDEGUFrTb1CsjlOjcgmalgNkGdDlGcY3zujzJ+i0Yl44kPuuv2kw9I2G2RlckCH/p768ox4ivRtw==", "license": "MIT", "dependencies": { "@types/adm-zip": "^0.4.32", @@ -2252,12 +2252,12 @@ } }, "node_modules/@lukka/base-util-lib": { - "version": "3.5.0", - "resolved": "https://npm.pkg.github.com/download/@lukka/base-util-lib/3.5.0/5bd54e6da2de6ac695f11ee45a8c370443003fc4", - "integrity": "sha512-hj9CL3j3EEsq26bClGrktk8b3W9Lhd73rstbwlMovKEIkjYpmUccADKKujrXWOdbF3DZiVHmlV3RouS/BNiDAA==", + "version": "3.5.1", + "resolved": "https://npm.pkg.github.com/download/@lukka/base-util-lib/3.5.1/cd0fa81dbd1aaaaa1734257546e0d23d2a59f3a6", + "integrity": "sha512-sKgFI/6K88XdceCNWtPxQJGWwK6taCjFb2rdqNXKn+VicLyAgGDHO4rIzYxkTICtf44N42gxVS0mF99NshqcAQ==", "license": "MIT", "dependencies": { - "@lukka/base-lib": "^3.5.0", + "@lukka/base-lib": "^3.5.1", "fast-glob": "3.2.7" } }, @@ -2277,14 +2277,14 @@ } }, "node_modules/@lukka/run-vcpkg-lib": { - "version": "3.5.0", - "resolved": "https://npm.pkg.github.com/download/@lukka/run-vcpkg-lib/3.5.0/91a3c9c4118b5f25cad1ccc689552adce43f8f47", - "integrity": "sha512-wccpbi4MZ5JiiWGeR8/MMt9aETiUFZl2WmVTKEhUY7SLMVT0ab5wkgfFoQ6zim0dePsK5DVk9OJdLMQT0CFRzw==", + "version": "3.5.1", + "resolved": "https://npm.pkg.github.com/download/@lukka/run-vcpkg-lib/3.5.1/ac6c6f5f83465a99bff177e0ea16fdfb4e68fe5a", + "integrity": "sha512-Wp5yilF+h4OhhOLy2250aj2iO5dOCit7yDNuEa1LW+IyGvPBf9xoUcmZeNT1k9HYCsy+Pe9oNwtc+tkc3VKyZg==", "license": "MIT", "dependencies": { - "@lukka/action-lib": "^3.5.0", - "@lukka/base-lib": "^3.5.0", - "@lukka/base-util-lib": "^3.5.0", + "@lukka/action-lib": "^3.5.1", + "@lukka/base-lib": "^3.5.1", + "@lukka/base-util-lib": "^3.5.1", "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.14.1", "@types/q": "^1.5.1", @@ -14182,17 +14182,17 @@ } }, "@lukka/action-lib": { - "version": "3.5.0", - "resolved": "https://npm.pkg.github.com/download/@lukka/action-lib/3.5.0/3932ea106e1a680784f30c697aa725d12c27fc16", - "integrity": "sha512-0UmsujYQmr+CraBnT4HaU4IYnw5LAQUEUm6b5VsM5l7sLlkvWh1qvBJIH6irLCeWjHFSRCLS2SYzbjbJbBUSyA==", + "version": "3.5.1", + "resolved": "https://npm.pkg.github.com/download/@lukka/action-lib/3.5.1/e34cf68ac51e892a180070634599a2577dcf31b5", + "integrity": "sha512-U1A8UMJiigfqyuERmbepiFlxoBxAAHZARbm/q4tikuhAGXMRo05DvQ5ypTEW2Uti0okrCwi/hF063w2Ha0ooeQ==", "requires": { "@actions/core": "^1.9.1", "@actions/exec": "^1.1.1", "@actions/github": "^5.0.3", "@actions/glob": "^0.3.0", "@actions/io": "^1.1.2", - "@lukka/base-lib": "^3.5.0", - "@lukka/base-util-lib": "^3.5.0", + "@lukka/base-lib": "^3.5.1", + "@lukka/base-util-lib": "^3.5.1", "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.14.1", "@types/q": "^1.5.1", @@ -14522,14 +14522,14 @@ } }, "@lukka/assets-lib": { - "version": "3.5.0", - "resolved": "https://npm.pkg.github.com/download/@lukka/assets-lib/3.5.0/6b369cc8f8baa8f8e4bb0748b03523686c5702fc", - "integrity": "sha512-suMPsDQ9E6OuNWanIv3hFWbCksCa3XX2RdCRdbpHC1EG4r9Idp9eQE+MbvLeZRIUnyOhzqnuwMNwGdcytS6HEg==" + "version": "3.5.1", + "resolved": "https://npm.pkg.github.com/download/@lukka/assets-lib/3.5.1/1ed4fdc57bd3a56f1531101644181c6c56188bff", + "integrity": "sha512-OL7TXFL/6mgyiKt7UEStPXQdsRpebMxEHHwpyu9by401zC9GdEs8a8z9ajclfXgWNHpjN9bpfMg5679I4J3agw==" }, "@lukka/base-lib": { - "version": "3.5.0", - "resolved": "https://npm.pkg.github.com/download/@lukka/base-lib/3.5.0/6d83fffd2f802631d2e6eb3f2be62ef022cf89e1", - "integrity": "sha512-lEa4XorbTFwHUIRNKKavuo/roQeK50WZMZLVVhgO4aF0kQU2Tx6mtwodG0KzVFQsv/jmahJFYOkrX39y9+RCBA==", + "version": "3.5.1", + "resolved": "https://npm.pkg.github.com/download/@lukka/base-lib/3.5.1/9eb1450ff87d6b6a9166da100df05f4cbf4a71a9", + "integrity": "sha512-CA1ea23sxAZDEGUFrTb1CsjlOjcgmalgNkGdDlGcY3zujzJ+i0Yl44kPuuv2kw9I2G2RlckCH/p768ox4ivRtw==", "requires": { "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.14.1", @@ -14860,11 +14860,11 @@ } }, "@lukka/base-util-lib": { - "version": "3.5.0", - "resolved": "https://npm.pkg.github.com/download/@lukka/base-util-lib/3.5.0/5bd54e6da2de6ac695f11ee45a8c370443003fc4", - "integrity": "sha512-hj9CL3j3EEsq26bClGrktk8b3W9Lhd73rstbwlMovKEIkjYpmUccADKKujrXWOdbF3DZiVHmlV3RouS/BNiDAA==", + "version": "3.5.1", + "resolved": "https://npm.pkg.github.com/download/@lukka/base-util-lib/3.5.1/cd0fa81dbd1aaaaa1734257546e0d23d2a59f3a6", + "integrity": "sha512-sKgFI/6K88XdceCNWtPxQJGWwK6taCjFb2rdqNXKn+VicLyAgGDHO4rIzYxkTICtf44N42gxVS0mF99NshqcAQ==", "requires": { - "@lukka/base-lib": "^3.5.0", + "@lukka/base-lib": "^3.5.1", "fast-glob": "3.2.7" }, "dependencies": { @@ -14883,13 +14883,13 @@ } }, "@lukka/run-vcpkg-lib": { - "version": "3.5.0", - "resolved": "https://npm.pkg.github.com/download/@lukka/run-vcpkg-lib/3.5.0/91a3c9c4118b5f25cad1ccc689552adce43f8f47", - "integrity": "sha512-wccpbi4MZ5JiiWGeR8/MMt9aETiUFZl2WmVTKEhUY7SLMVT0ab5wkgfFoQ6zim0dePsK5DVk9OJdLMQT0CFRzw==", + "version": "3.5.1", + "resolved": "https://npm.pkg.github.com/download/@lukka/run-vcpkg-lib/3.5.1/ac6c6f5f83465a99bff177e0ea16fdfb4e68fe5a", + "integrity": "sha512-Wp5yilF+h4OhhOLy2250aj2iO5dOCit7yDNuEa1LW+IyGvPBf9xoUcmZeNT1k9HYCsy+Pe9oNwtc+tkc3VKyZg==", "requires": { - "@lukka/action-lib": "^3.5.0", - "@lukka/base-lib": "^3.5.0", - "@lukka/base-util-lib": "^3.5.0", + "@lukka/action-lib": "^3.5.1", + "@lukka/base-lib": "^3.5.1", + "@lukka/base-util-lib": "^3.5.1", "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.14.1", "@types/q": "^1.5.1", diff --git a/package.json b/package.json index 63f6129f..e15277ff 100644 --- a/package.json +++ b/package.json @@ -43,11 +43,11 @@ "@actions/exec": "^1.1.1", "@actions/github": "^5.0.3", "@actions/io": "^1.1.2", - "@lukka/action-lib": "3.5.0", - "@lukka/assets-lib": "3.5.0", - "@lukka/base-lib": "3.5.0", - "@lukka/base-util-lib": "3.5.0", - "@lukka/run-vcpkg-lib": "3.5.0", + "@lukka/action-lib": "3.5.1", + "@lukka/assets-lib": "3.5.1", + "@lukka/base-lib": "3.5.1", + "@lukka/base-util-lib": "3.5.1", + "@lukka/run-vcpkg-lib": "3.5.1", "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.14.1", "@types/jest": "^26.0.14", diff --git a/src/vcpkg-action.ts b/src/vcpkg-action.ts index 2b1f6be4..d5b33780 100644 --- a/src/vcpkg-action.ts +++ b/src/vcpkg-action.ts @@ -27,13 +27,13 @@ export class VcpkgAction { private static readonly VCPKGJSON_GLOB = "**/vcpkg.json"; private static readonly VCPKGJSON_IGNORES = "['**/vcpkg/**']"; private static readonly DEFAULTVCPKGURL = 'https://github.com/microsoft/vcpkg.git'; - private readonly doNotCache: boolean = false; + private readonly doNotCache: boolean = true; private readonly runVcpkgFormatString: string | null; private readonly vcpkgJsonGlob: string; private readonly vcpkgJsonIgnores: string[]; - private readonly runVcpkgInstall: boolean; + private readonly runVcpkgInstall: boolean = false; private readonly userProvidedCommitId: string | null; - private readonly doNotUpdateVcpkg: boolean; + private readonly doNotUpdateVcpkg: boolean = false; private readonly vcpkgUrl: string | null; private readonly vcpkgCommitId: string | null; private readonly logCollectionRegExps: string[]; @@ -48,9 +48,9 @@ export class VcpkgAction { this.runVcpkgFormatString = baseUtilLib.baseLib.getInput(runVcpkgFormatStringInput, false) ?? null; this.vcpkgJsonGlob = baseUtilLib.baseLib.getInput(vcpkgJsonGlobInput, false) ?? VcpkgAction.VCPKGJSON_GLOB; this.vcpkgJsonIgnores = eval(baseUtilLib.baseLib.getInput(vcpkgJsonIgnoresInput, false) ?? VcpkgAction.VCPKGJSON_IGNORES) as string[]; - this.runVcpkgInstall = baseUtilLib.baseLib.getBoolInput(runVcpkgInstallInput, false) ?? false; - this.doNotCache = baseUtilLib.baseLib.getBoolInput(doNotCacheInput, false) ?? false; - this.doNotUpdateVcpkg = baseUtilLib.baseLib.getBoolInput(doNotUpdateVcpkgInput, false) ?? false; + this.runVcpkgInstall = baseUtilLib.baseLib.getBoolInput(runVcpkgInstallInput, false) ?? this.runVcpkgInstall; + this.doNotCache = baseUtilLib.baseLib.getBoolInput(doNotCacheInput, false) ?? this.doNotCache; + this.doNotUpdateVcpkg = baseUtilLib.baseLib.getBoolInput(doNotUpdateVcpkgInput, false) ?? this.doNotUpdateVcpkg; this.vcpkgUrl = baseUtilLib.baseLib.getInput(vcpkgUrlInput, false) ?? VcpkgAction.DEFAULTVCPKGURL; this.vcpkgCommitId = baseUtilLib.baseLib.getInput(vcpkgCommitIdInput, false) ?? null; this.logCollectionRegExps = baseUtilLib.baseLib.getDelimitedInput(logCollectionRegExpsInput, ';', false) ?? []; @@ -85,28 +85,34 @@ export class VcpkgAction { throw new Error(`vcpkgRootDir is not defined!`); } - const [keys, vcpkgJsonFilePath] = - await this.baseUtilLib.wrapOp('Compute vcpkg cache key', async () => { - const vcpkgJsonPath = await vcpkgutil.Utils.getVcpkgJsonPath( - this.baseUtilLib, this.vcpkgJsonGlob, this.vcpkgJsonIgnores); - const keys = await vcpkgutil.Utils.computeCacheKeys( - this.baseUtilLib, - this.vcpkgRootDir as string, // HACK: if it were not set it would have thrown before. - this.userProvidedCommitId); - - if (keys && vcpkgJsonPath) { - baseLib.info(`Computed key: ${JSON.stringify(keys)}`); - } else { - throw new Error("Computation for the cache key or the vcpkg.json location failed!"); - } - return [keys, vcpkgJsonPath]; - }); + let vcpkgJsonFilePath: string | null = null; + const vcpkgJsonPath = await vcpkgutil.Utils.getVcpkgJsonPath( + this.baseUtilLib, this.vcpkgJsonGlob, this.vcpkgJsonIgnores); + vcpkgJsonFilePath = await this.getCurrentDirectoryForRunningVcpkg(vcpkgJsonPath); - const isCacheHit = - await this.baseUtilLib.wrapOp('Restore vcpkg installation from cache (not the packages, that is done by vcpkg via binary caching using GitHub Action cache)', - async () => await this.restoreCache(keys as baseutillib.KeySet)); + let isCacheHit: boolean | null = null; + let cacheKey: baseutillib.KeySet | null = null; + if (this.doNotCache) { + this.baseUtilLib.baseLib.debug(`Skipping restoring vcpkg as caching is disabled. Set input 'doNotCache:false' to enable caching.`); + } else { + cacheKey = + await this.baseUtilLib.wrapOp('Compute vcpkg cache key', async () => { + const keys = await vcpkgutil.Utils.computeCacheKeys( + this.baseUtilLib, + this.vcpkgRootDir as string, // HACK: if it were not set it would have thrown before. + this.userProvidedCommitId); + + if (keys && vcpkgJsonPath) { + baseLib.info(`Computed key: ${JSON.stringify(keys)}`); + } else { + throw new Error("Computation for the cache key failed!"); + } + return keys; + }); + + isCacheHit = await this.restoreCache(cacheKey); + } - const vcpkgJsonPath: string | null = await this.getCurrentDirectoryForRunningVcpkg(vcpkgJsonFilePath); await runvcpkglib.VcpkgRunner.run( this.baseUtilLib, this.vcpkgRootDir, @@ -115,17 +121,21 @@ export class VcpkgAction { this.runVcpkgInstall, this.doNotUpdateVcpkg, this.logCollectionRegExps, - vcpkgJsonPath, + vcpkgJsonFilePath, this.runVcpkgFormatString ); - await this.saveCache( - isCacheHit, - keys, - vcpkgutil.Utils.getAllCachedPaths(this.baseUtilLib.baseLib, - this.vcpkgRootDir as string // HACK: if it were not set it would have thrown before. - ), - this.doNotCache, true); + if (this.doNotCache) { + this.baseUtilLib.baseLib.debug(`Skipping restoring vcpkg as caching is disabled. Set input 'doNotCache:false' to enable caching.`); + } else { + await this.saveCache( + isCacheHit, + cacheKey as baseutillib.KeySet, // Hack: if it were not set it would have thrown an exception before. + vcpkgutil.Utils.getAllCachedPaths(this.baseUtilLib.baseLib, + this.vcpkgRootDir as string // HACK: if it were not set it would have thrown an exception before. + ), + true); + } this.baseUtilLib.baseLib.debug("run()>>"); } @@ -133,59 +143,55 @@ export class VcpkgAction { private async restoreCache(keys: baseutillib.KeySet): Promise { let isCacheHit = false; this.baseUtilLib.baseLib.debug("restoreCache()<<"); - if (this.doNotCache) { - this.baseUtilLib.baseLib.info(`Skipping restoring cache as caching is disabled (${doNotCacheInput}: ${this.doNotCache}).`); - } else { - if (!this.vcpkgRootDir) throw new Error("vcpkg_ROOT must be defined"); - const pathsToCache: string[] = 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: string | undefined; - try { - keyCacheHit = await cache.restoreCache(pathsToCache, keys.primary, keys.restore); - } - catch (err) { - this.baseUtilLib.baseLib.warning(`cache.restoreCache() failed: '${(err as Error)?.message ?? ""}', skipping restoring from cache.`); - } + await 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)', + async () => { + if (!this.vcpkgRootDir) throw new Error("VCPKG_ROOT must be defined"); + const pathsToCache: string[] = 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: string | undefined; + try { + keyCacheHit = await cache.restoreCache(pathsToCache, keys.primary, keys.restore); + } + catch (err) { + this.baseUtilLib.baseLib.warning(`cache.restoreCache() failed: '${(err as Error)?.message ?? ""}', 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; + 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; } - private async saveCache(isCacheHit: boolean, keys: baseutillib.KeySet, cachedPaths: string[], doNotCache: boolean, + private async saveCache(isCacheHit: boolean | null, keys: baseutillib.KeySet, cachedPaths: string[], successStep: boolean): Promise { this.baseUtilLib.baseLib.debug('saveCache()<<'); - await 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).', - async () => - await 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) - ); + await vcpkgutil.Utils.saveCache(this.baseUtilLib, keys, + isCacheHit ? keys.primary : null, /* Only the primary cache could have hit, since there are no restore keys. */ + cachedPaths); this.baseUtilLib.baseLib.debug('saveCache()>>'); } private async getCurrentDirectoryForRunningVcpkg(vcpkgJsonFile: string | null): Promise { - this.baseUtilLib.baseLib.debug(`getCurrentDirectoryForRunningVcpkg() << `); + this.baseUtilLib.baseLib.debug(`getCurrentDirectoryForRunningVcpkg(${vcpkgJsonFile}) << `); // When running 'vcpkg install' is requested, ensure the target directory is well known, fail otherwise. let vcpkgJsonPath: string | null = null; if (this.runVcpkgInstall) { 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}'. `); } } diff --git a/src/vcpkg-utils.ts b/src/vcpkg-utils.ts index 690ec010..29414b9b 100644 --- a/src/vcpkg-utils.ts +++ b/src/vcpkg-utils.ts @@ -122,37 +122,38 @@ export class Utils { return keyset; } - public static async saveCache(baseLib: baselib.BaseLib, doNotCache: boolean, keys: baseutillib.KeySet, + public static async saveCache(baseUtilLib: baseutillib.BaseUtilLib, keys: baseutillib.KeySet, hitCacheKey: string | null, cachedPaths: string[]): Promise { - baseLib.debug(`saveCache(doNotCache:${doNotCache},keys:${JSON.stringify(keys)},hitCacheKey:${hitCacheKey},cachedPaths:${cachedPaths})<<`) + const baseLib = baseUtilLib.baseLib; + baseLib.debug(`saveCache(keys:${JSON.stringify(keys)},hitCacheKey:${hitCacheKey},cachedPaths:${cachedPaths})<<`) try { - if (doNotCache) { - baseLib.info(`Skipping saving cache as caching is disabled (${doNotCacheInput}: ${doNotCache}).`); - } 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: string[] = cachedPaths; - baseLib.info(`Caching paths: '${pathsToCache}'`); - - try { - baseLib.info(`Saving cache with primary key '${keys.primary}' ...`); - await 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); + await 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).', + async () => { + + 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: string[] = cachedPaths; + baseLib.info(`Caching paths: '${pathsToCache}'`); + + try { + baseLib.info(`Saving cache with primary key '${keys.primary}' ...`); + await 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) { baseLib.warning("vcpkg-utils.saveCache() failed!"); if (err instanceof Error) {