From 7b25951f51003aa11faa7a57511ee49564161b6f Mon Sep 17 00:00:00 2001 From: luca <681992+lukka@users.noreply.github.com> Date: Sun, 30 Jan 2022 17:35:11 +0100 Subject: [PATCH] fixes for: -telemetry -jobstatus -vcpkgconfjson --- README.md | 46 ++++++++++-------- __tests__/functional.test.ts | 2 +- __tests__/unit.test.ts | 41 ++++++++-------- action.yml | 8 --- dist/index.js | 43 ++++++++++++----- dist/post/index.js | 90 ++++++++++++++++++---------------- package-lock.json | 94 ++++++++++++++++++------------------ package.json | 10 ++-- src/post-action.ts | 9 ++-- src/vcpkg-action.ts | 13 +++-- src/vcpkg-post-action.ts | 37 ++++++-------- src/vcpkg-utils.ts | 24 ++++++--- 12 files changed, 224 insertions(+), 193 deletions(-) diff --git a/README.md b/README.md index c5e4b7ef..1596f9bd 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ jobs: # to install the packages when `run-cmake` runs, no packages are installed at # this time. - name: Restore artifacts, or setup vcpkg (do not install any package) - uses: lukka/run-vcpkg@v10 # Always specify the specific _version_ of the + uses: lukka/run-vcpkg@v10.1 # Always specify the specific _version_ of the # action you need, `v10` in this case to stay up # to date with fixes on v10 branch. #with: @@ -100,9 +100,14 @@ jobs: buildPreset: 'ninja-multi-vcpkg' #env: - # VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }} # [OPTIONAL] Define the vcpkg's triplet - # you want to enforce, otherwise the default one for the hosting system will be - # automatically choosen (x64 is the default on all platforms, e.g. x64-osx). + # By default the action disables vcpkg's telemetry by defining VCPKG_DISABLE_METRICS. + # This behavior can be disabled by defining `VCPKG_ENABLE_METRICS` as follows. + # VCPKG_ENABLE_METRICS: 1 + # + # [OPTIONAL] Define the vcpkg's triplet you want to enforce, otherwise the default one + # for the hosting system will be automatically choosen (x64 is the default on all platforms, + # e.g. `x64-osx`). + # VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }} ``` ## Action reference: all input/output parameters @@ -120,21 +125,21 @@ Flowchart with related input in [action.yml](https://github.com/lukka/run-vcpkg/ │ - platform and OS │ - `vcpkgGitCommitId` │ - user provided key │ └─────────────┬────────────┘ - │ - ▼ + │ + ▼ ┌─────────────────────────┐ │ Locate vcpkg.json. │ Inputs: │ If found, add its hash │ - `vcpkgJsonGlob` │ to cache key │ _ `vcpkgJsonIgnores` └────────────┬────────────┘ - │ - ▼ + │ + ▼ ┌─────────────────────────┐ Inputs: │ Restore vcpkg and │ - `doNotCache` │ packages from cache │ - `vcpkgDirectory` │ to cache key │ - `binaryCachePath` └────────────┬────────────┘ Environment variable: - │ - `VCPKG_DEFAULT_BINARY_CACHE`: where previous built packages + │ - `VCPKG_DEFAULT_BINARY_CACHE`: where previous built packages ▼ are going to be restored ┌─────────────────────────┐ │ If vcpkg is not a │ Inputs: @@ -142,14 +147,14 @@ Flowchart with related input in [action.yml](https://github.com/lukka/run-vcpkg/ │ │ - `vcpkgGitURL` └────────────┬────────────┘ - `doNotUpdateVcpkg` │ - `vcpkgDirectory` - ▼ + ▼ ┌─────────────────────────┐ │ Rebuild vcpkg executable│ Inputs: │ if not in sync with │ - `vcpkgGitCommitId` │ sources │ - `vcpkgGitURL` └────────────┬────────────┘ - │ - ▼ + │ + ▼ ┐ Inputs: ────┬──── No│ - `runVcpkgInstall` │ Yes │ @@ -157,17 +162,17 @@ Flowchart with related input in [action.yml](https://github.com/lukka/run-vcpkg/ ┌─────────────────────────┐ │ │ Launch `vcpkg install` │ │ Inputs: │ where vcpkg.json has │ │ - `runVcpkgFormatString` - │ been located │ │ Environment variables: + │ been located │ │ Environment variables: └────────────┬────────────┘ │ - `VCPKG_DEFAULT_TRIPLET` is used. If not yet │ │ set, it is set to the current platform. ▼ │ ┌─────────────────────────┐ │ - │ Set `VCPKG_ROOT` and │ │ - │ `VCPKG_DEFAULT_TRIPLET` │ │ - │ workflow-wide env vars │ │ + │ Set `VCPKG_ROOT` and │ │ + │ `VCPKG_DEFAULT_TRIPLET` │ │ + │ workflow-wide env vars │ │ └────────────┬────────────┘ │ ├───────────── ┘ - ▼ + ▼ ┌───────────────────────────┐ │ Schedule this step at │ │ end of the workflow: │ @@ -175,9 +180,10 @@ Flowchart with related input in [action.yml](https://github.com/lukka/run-vcpkg/ │| If no cache-hit, ││ Inputs: ││ store `VCPKG_ROOT` and ││ - `binaryCachePath` ││ binary packages in cache││ - `doNotCache` - │└────────────┬────────────┘│ - `doNotCacheOnWorkflowFailure` - └────────────┬──────────────┘ - ▼ + ││ ││ Environment variables: + │└────────────┬────────────┘│ - RUNVCPKG_NO_CACHE: Any step before the post action + └────────────┬──────────────┘ may set this environment variable to disable saving + ▼ the cache. ⬬ ``` diff --git a/__tests__/functional.test.ts b/__tests__/functional.test.ts index c7a2fa27..db451ef7 100644 --- a/__tests__/functional.test.ts +++ b/__tests__/functional.test.ts @@ -9,7 +9,7 @@ import { ActionLib } from '@lukka/action-lib'; import { BaseUtilLib } from '@lukka/base-util-lib'; import * as runvcpkglib from "@lukka/run-vcpkg-lib" -jest.setTimeout(400 * 1000); +jest.setTimeout(800 * 1000); const tempDirectory = path.join(__dirname, "temp Directory"); // Note: 'theAssets' must match the directory __tests__/theAssets/ diff --git a/__tests__/unit.test.ts b/__tests__/unit.test.ts index 5252b0b8..34bd56d4 100644 --- a/__tests__/unit.test.ts +++ b/__tests__/unit.test.ts @@ -118,8 +118,6 @@ test('run-vcpkg: basic run with exception', async () => { // Run post action. const vcpkgPostAction = new vcpkgpostaction.VcpkgPostAction( baseUtil, - true, - false, false, baseutil.createKeySet(["primary"]), ['/dummy/Path/'], @@ -138,8 +136,6 @@ test('run-vcpkg: basic run with exception on saving the cache', async () => { // Run post action. const vcpkgPostAction = new vcpkgpostaction.VcpkgPostAction( baseUtil, - true, - false, false, baseutil.createKeySet(["primary"]), ['/dummy/Path/'], @@ -172,8 +168,6 @@ test('run-vcpkg: cache hit', async () => { // Run post action. const vcpkgPostAction = new vcpkgpostaction.VcpkgPostAction(baseUtil, - true, - false, false, keys, ['/dummy/Path/'], @@ -211,8 +205,6 @@ test('run-vcpkg: cache miss', async () => { // code is running by an GitHub runner indeed) process.env.STATE_VCPKG_CACHE_COMPUTEDKEY_STATE = '{"primary":"runnerOS=darwin","restore":[]}'; const vcpkgPostAction = new vcpkgpostaction.VcpkgPostAction(baseUtil, - true, - false, false, baseutil.createKeySet([key]), ['/dummy/Path/'], @@ -325,6 +317,7 @@ test('computeCacheKey(): vcpkg not as a submodule (no commit id user provided an expect(await vcpkgutils.Utils.computeCacheKeys( baseUtil, null, + null, ".", "", "appendedCacheKey")).toStrictEqual(expected); @@ -338,10 +331,10 @@ test('computeCacheKey(): vcpkg not as a submodule (no commit id user provided an test('computeCacheKey(): vcpkg not as a submodule (no commit id user provided)', async () => { // Arrange. const expected: baseutil.KeySet = { - "primary": "runnerOS=imageos-vcpkgGitCommit=1234_vcpkgJson=hash-of-vcpkg.json_appendedKey=appendedCacheKey", + "primary": "runnerOS=imageos-vcpkgGitCommit=1234_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey", "restore": [ - "runnerOS=imageos-vcpkgGitCommit=1234_vcpkgJson=hash-of-vcpkg.json", + "runnerOS=imageos-vcpkgGitCommit=1234_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json", "runnerOS=imageos-vcpkgGitCommit=1234" ] }; @@ -353,7 +346,9 @@ test('computeCacheKey(): vcpkg not as a submodule (no commit id user provided)', // Act and Assert. expect(await vcpkgutils.Utils.computeCacheKeys( - baseUtil, "hash-of-vcpkg.json", + baseUtil, + "hash-of-vcpkg.json", + "hash-of-vcpkg-configuration.json", ".", "", "appendedCacheKey")).toStrictEqual(expected); @@ -366,10 +361,10 @@ test('computeCacheKey(): vcpkg not as a submodule (no commit id user provided)', test('computeCacheKey(): vcpkg as a submodule (no commit id user provided)', async () => { // Arrange. const expected: baseutil.KeySet = { - "primary": "runnerOS=imageos-vcpkgGitCommit=5678_vcpkgJson=hash-of-vcpkg.json_appendedKey=appendedCacheKey", + "primary": "runnerOS=imageos-vcpkgGitCommit=5678_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey", "restore": [ - "runnerOS=imageos-vcpkgGitCommit=5678_vcpkgJson=hash-of-vcpkg.json", + "runnerOS=imageos-vcpkgGitCommit=5678_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json", "runnerOS=imageos-vcpkgGitCommit=5678" ] }; @@ -381,7 +376,9 @@ test('computeCacheKey(): vcpkg as a submodule (no commit id user provided)', asy // Act and Assert. expect(await vcpkgutils.Utils.computeCacheKeys( - baseUtil, "hash-of-vcpkg.json", + baseUtil, + "hash-of-vcpkg.json", + "hash-of-vcpkg-configuration.json", ".", "", "appendedCacheKey")).toStrictEqual(expected); @@ -394,10 +391,10 @@ test('computeCacheKey(): vcpkg as a submodule (no commit id user provided)', asy test('computeCacheKey(): vcpkg as a submodule, with user provided Git commit id, it must trigger a warning', async () => { // Arrange. const expected: baseutil.KeySet = { - "primary": "runnerOS=imageos-vcpkgGitCommit=0912_vcpkgJson=hash-of-vcpkg.json_appendedKey=appendedCacheKey", + "primary": "runnerOS=imageos-vcpkgGitCommit=0912_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey", "restore": [ - "runnerOS=imageos-vcpkgGitCommit=0912_vcpkgJson=hash-of-vcpkg.json", + "runnerOS=imageos-vcpkgGitCommit=0912_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json", "runnerOS=imageos-vcpkgGitCommit=0912" ] }; @@ -409,7 +406,9 @@ test('computeCacheKey(): vcpkg as a submodule, with user provided Git commit id, // Act and Assert. expect(await vcpkgutils.Utils.computeCacheKeys( - baseUtil, "hash-of-vcpkg.json", + baseUtil, + "hash-of-vcpkg.json", + "hash-of-vcpkg-configuration.json", path.resolve("."), "vcpkgcommitid", "appendedCacheKey")).toStrictEqual(expected); @@ -420,9 +419,9 @@ test('computeCacheKey(): vcpkg as a submodule, with user provided Git commit id, test('computeCacheKey(): vcpkg with user provided commit it must not trigger a warning', async () => { // Arrange. const expected: baseutil.KeySet = { - "primary": "runnerOS=imageos-vcpkgGitCommit=userId_vcpkgJson=hash-of-vcpkg.json_appendedKey=appendedCacheKey", + "primary": "runnerOS=imageos-vcpkgGitCommit=userId_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey", "restore": [ - "runnerOS=imageos-vcpkgGitCommit=userId_vcpkgJson=hash-of-vcpkg.json", + "runnerOS=imageos-vcpkgGitCommit=userId_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json", "runnerOS=imageos-vcpkgGitCommit=userId"] }; process.env.ImageOS = "imageos"; @@ -433,7 +432,9 @@ test('computeCacheKey(): vcpkg with user provided commit it must not trigger a w // Act and assert. expect(await vcpkgutils.Utils.computeCacheKeys( - baseUtil, "hash-of-vcpkg.json", + baseUtil, + "hash-of-vcpkg.json", + "hash-of-vcpkg-configuration.json", "/Users/luca/github/run-vcpkg/__tests__/assets/", "userId", "appendedCacheKey")).toStrictEqual(expected); diff --git a/action.yml b/action.yml index 82281799..8eeaa4f5 100644 --- a/action.yml +++ b/action.yml @@ -34,10 +34,6 @@ inputs: default: false required: false description: "Disable the automatic caching mechanism by setting it to true. Default is false." - doNotCacheOnWorkflowFailure: - default: false - required: false - description: "Disable the saving of the cache if the workflow failed." # The following inputs are rarely set by the user, since the default values suffice the most common scenarios. vcpkgJsonGlob: @@ -63,10 +59,6 @@ inputs: default: "\\s*\"(.+CMakeOutput\\.log)\"\\.\\s*;\\s*\"(.+CMakeError\\.log)\"\\.\\s*;\\s*(.+out\\.log)\\s*;\\s+(.+err\\.log)\\s*;\\s*(.+vcpkg.+\\.log)\\s*" required: false description: "Specifies a semicolon separated list of regular expressions that are used to identify log file paths in the workflow output. A regular expression must have a single capturing group, that is a single pair of parenthesis such as 'See also (.+.log)'. When a match occurs, the content of the file is written into the workflow output for disclosing its content to the user. The default regular expressions are for CMake's and vcpkg's log files." - jobStatus: - default: ${{ job.status }} - required: false - description: "Do not set nor use. It is used to get the status of the job and decide whether to save cache on the post action run at the end of the job." runs: using: 'node12' diff --git a/dist/index.js b/dist/index.js index df21e1bb..a673ad0b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -72,7 +72,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.VcpkgAction = exports.VCPKG_ADDITIONAL_CACHED_PATHS_STATE = exports.VCPKG_ROOT_STATE = exports.VCPKG_ADDED_CACHEKEY_STATE = exports.VCPKG_DO_NOT_CACHE_STATE = exports.VCPKG_KEY_CACHE_HIT_STATE = exports.VCPKG_CACHE_COMPUTEDKEY_STATE = exports.logCollectionRegExpsInput = exports.appendedCacheKeyInput = exports.vcpkgUrlInput = exports.doNotUpdateVcpkgInput = exports.vcpkgCommitIdInput = exports.vcpkgDirectoryInput = exports.runVcpkgFormatStringInput = exports.runVcpkgInstallInput = exports.vcpkgJsonIgnoresInput = exports.vcpkgJsonGlobInput = exports.doNotCacheOnWorkflowFailureInput = exports.jobStatusInput = exports.binaryCachePathInput = exports.additionalCachedPathsInput = exports.doNotCacheInput = void 0; +exports.VcpkgAction = exports.VCPKG_SUCCESS_STATE = exports.VCPKG_ADDITIONAL_CACHED_PATHS_STATE = exports.VCPKG_ROOT_STATE = exports.VCPKG_ADDED_CACHEKEY_STATE = exports.VCPKG_DO_NOT_CACHE_STATE = exports.VCPKG_KEY_CACHE_HIT_STATE = exports.VCPKG_CACHE_COMPUTEDKEY_STATE = exports.logCollectionRegExpsInput = exports.appendedCacheKeyInput = exports.vcpkgUrlInput = exports.doNotUpdateVcpkgInput = exports.vcpkgCommitIdInput = exports.vcpkgDirectoryInput = exports.runVcpkgFormatStringInput = exports.runVcpkgInstallInput = exports.vcpkgJsonIgnoresInput = exports.vcpkgJsonGlobInput = exports.binaryCachePathInput = exports.additionalCachedPathsInput = exports.doNotCacheInput = void 0; const path = __nccwpck_require__(5622); const cache = __nccwpck_require__(7799); const runvcpkglib = __nccwpck_require__(4393); @@ -81,8 +81,6 @@ const vcpkgutil = __nccwpck_require__(4534); exports.doNotCacheInput = 'DONOTCACHE'; exports.additionalCachedPathsInput = 'ADDITIONALCACHEDPATHS'; exports.binaryCachePathInput = 'BINARYCACHEPATH'; -exports.jobStatusInput = 'JOBSTATUS'; -exports.doNotCacheOnWorkflowFailureInput = 'DONOTCACHEONWORKFLOWFAILURE'; exports.vcpkgJsonGlobInput = 'VCPKGJSONGLOB'; exports.vcpkgJsonIgnoresInput = "VCPKGJSONIGNORES"; exports.runVcpkgInstallInput = 'RUNVCPKGINSTALL'; @@ -103,6 +101,7 @@ exports.VCPKG_DO_NOT_CACHE_STATE = "VCPKG_DO_NOT_CACHE_STATE"; exports.VCPKG_ADDED_CACHEKEY_STATE = "VCPKG_ADDED_CACHEKEY_STATE"; exports.VCPKG_ROOT_STATE = "VCPKG_ROOT_STATE"; exports.VCPKG_ADDITIONAL_CACHED_PATHS_STATE = "VCPKG_ADDITIONAL_CACHED_PATHS_STATE"; +exports.VCPKG_SUCCESS_STATE = "VCPKG_SUCCESS_STATE"; class VcpkgAction { constructor(baseUtilLib) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; @@ -156,8 +155,8 @@ class VcpkgAction { let keys = null; let vcpkgJsonFilePath = null; yield this.baseUtilLib.wrapOp('Compute vcpkg cache key', () => __awaiter(this, void 0, void 0, function* () { - const [vcpkgJsonFile, vcpkgJsonHash] = yield vcpkgutil.Utils.getVcpkgJsonHash(this.baseUtilLib, this.vcpkgJsonGlob, this.vcpkgJsonIgnores); - keys = yield vcpkgutil.Utils.computeCacheKeys(this.baseUtilLib, vcpkgJsonHash, this.vcpkgRootDir, this.userProvidedCommitId, this.appendedCacheKey); + const [vcpkgJsonFile, vcpkgJsonHash, vcpkgConfigurationJsonHash] = yield vcpkgutil.Utils.getVcpkgJsonHash(this.baseUtilLib, this.vcpkgJsonGlob, this.vcpkgJsonIgnores); + keys = yield vcpkgutil.Utils.computeCacheKeys(this.baseUtilLib, vcpkgJsonHash, vcpkgConfigurationJsonHash, this.vcpkgRootDir, this.userProvidedCommitId, this.appendedCacheKey); if (keys) { baseLib.info(`Computed key: ${JSON.stringify(keys)}`); vcpkgJsonFilePath = vcpkgJsonFile; @@ -172,6 +171,7 @@ class VcpkgAction { } 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); + baseLib.setState(exports.VCPKG_SUCCESS_STATE, "success"); this.baseUtilLib.baseLib.debug("run()>>"); }); } @@ -317,8 +317,14 @@ class Utils { try { const [vcpkgJsonPath, vcpkgJsonHash] = yield baseUtil.getFileHash(vcpkgJsonGlob, vcpkgJsonIgnores); if (vcpkgJsonPath) { - baseUtil.baseLib.info(`Found vcpkg.json at '${vcpkgJsonPath}', its hash is '${vcpkgJsonHash}''.`); - return [vcpkgJsonPath, vcpkgJsonHash]; + baseUtil.baseLib.info(`Found ${runvcpkglib.VCPKG_JSON} at '${vcpkgJsonPath}', its hash is '${vcpkgJsonHash}''.`); + const vcpkgConfJsonPath = path.join(path.dirname(vcpkgJsonPath), runvcpkglib.VCPKG_CONFIGURATION_JSON); + let vcpkgConfigurationHash = null; + if (baseUtil.fileExists(vcpkgConfJsonPath)) { + vcpkgConfigurationHash = yield baseUtil.baseLib.hashFiles(vcpkgConfJsonPath); + baseUtil.baseLib.info(`Found sibling ${runvcpkglib.VCPKG_CONFIGURATION_JSON} at '${vcpkgConfJsonPath}', its hash is '${vcpkgConfigurationHash}'.`); + } + return [vcpkgJsonPath, vcpkgJsonHash, vcpkgConfigurationHash]; } } catch (err) { @@ -327,10 +333,10 @@ class Utils { } } baseUtil.baseLib.warning(`Cannot compute hash of vcpkg.json as it was not found (or multiple hits) with glob expression '${vcpkgJsonGlob}'.`); - return [null, null]; + return [null, null, null]; }); } - static computeCacheKeys(baseUtilLib, vcpkgJsonHash, vcpkgDirectory, userProvidedCommitId, appendedCacheKey) { + static computeCacheKeys(baseUtilLib, vcpkgJsonHash, vcpkgConfJsonHash, vcpkgDirectory, userProvidedCommitId, appendedCacheKey) { return __awaiter(this, void 0, void 0, function* () { baseUtilLib.baseLib.debug(`computeCacheKeys()<<`); const cacheKeySegments = []; @@ -357,8 +363,13 @@ class Utils { } cacheKeySegments.push(firstSegment); if (vcpkgJsonHash) { - cacheKeySegments.push(`vcpkgJson=${vcpkgJsonHash}`); - baseUtilLib.baseLib.info(`Adding hash of vcpkg.json: '${vcpkgJsonHash}'.`); + let hash = `vcpkgJson=${vcpkgJsonHash}`; + baseUtilLib.baseLib.info(`Adding hash of ${runvcpkglib.VCPKG_JSON}: '${vcpkgJsonHash}'.`); + if (vcpkgConfJsonHash) { + baseUtilLib.baseLib.info(`Adding hash of ${runvcpkglib.VCPKG_CONFIGURATION_JSON}: '${vcpkgConfJsonHash}'.`); + hash += `-vcpkgConfigurationJson=${vcpkgConfJsonHash}`; + } + cacheKeySegments.push(hash); } if (appendedCacheKey) { cacheKeySegments.push(`appendedKey=${appendedCacheKey}`); @@ -6924,12 +6935,14 @@ __exportStar(__nccwpck_require__(6188), exports); // Released under the term specified in file LICENSE.txt // SPDX short identifier: MIT Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.VCPKGDEFAULTTRIPLET = exports.VCPKGROOT = exports.vcpkgLastBuiltCommitId = exports.RUNVCPKG_VCPKG_DEFAULT_TRIPLET = exports.RUNVCPKG_VCPKG_ROOT = void 0; +exports.VCPKG_CONFIGURATION_JSON = exports.VCPKG_JSON = exports.VCPKGDEFAULTTRIPLET = exports.VCPKGROOT = exports.vcpkgLastBuiltCommitId = exports.RUNVCPKG_VCPKG_DEFAULT_TRIPLET = exports.RUNVCPKG_VCPKG_ROOT = void 0; exports.RUNVCPKG_VCPKG_ROOT = "RUNVCPKG_VCPKG_ROOT"; exports.RUNVCPKG_VCPKG_DEFAULT_TRIPLET = "RUNVCPKG_VCPKG_DEFAULT_TRIPLET"; exports.vcpkgLastBuiltCommitId = 'vcpkgLastBuiltCommitId'; exports.VCPKGROOT = 'VCPKG_ROOT'; exports.VCPKGDEFAULTTRIPLET = "VCPKG_DEFAULT_TRIPLET"; +exports.VCPKG_JSON = "vcpkg.json"; +exports.VCPKG_CONFIGURATION_JSON = "vcpkg-configuration.json"; //# sourceMappingURL=vcpkg-globals.js.map /***/ }), @@ -7045,6 +7058,10 @@ class VcpkgRunner { runImpl() { return __awaiter(this, void 0, void 0, function* () { this.baseUtils.baseLib.debug("runImpl()<<"); + // By default disable vcpkg telemetry, unless VCPKG_ENABLE_METRICS is set. + if (!process.env[VcpkgRunner.VCPKG_ENABLE_METRICS]) { + process.env[VcpkgRunner.VCPKG_DISABLE_METRICS] = "1"; + } // Ensuring `this.vcpkgDestPath` is existent, since is going to be used as current working directory. if (!(yield this.baseUtils.baseLib.exist(this.vcpkgDestPath))) { this.baseUtils.baseLib.debug(`Creating vcpkg root directory as it is not existing: ${this.vcpkgDestPath}`); @@ -7310,6 +7327,8 @@ class VcpkgRunner { exports.VcpkgRunner = VcpkgRunner; VcpkgRunner.VCPKGINSTALLCMDDEFAULT = '[`install`, `--recurse`, `--clean-after-build`, `--x-install-root`, `$[env.VCPKG_INSTALLED_DIR]`, `--triplet`, `$[env.VCPKG_DEFAULT_TRIPLET]`]'; VcpkgRunner.DEFAULTVCPKGURL = 'https://github.com/microsoft/vcpkg.git'; +VcpkgRunner.VCPKG_ENABLE_METRICS = "VCPKG_ENABLE_METRICS"; +VcpkgRunner.VCPKG_DISABLE_METRICS = "VCPKG_DISABLE_METRICS"; //# sourceMappingURL=vcpkg-runner.js.map /***/ }), diff --git a/dist/post/index.js b/dist/post/index.js index 9683350d..ad4452a3 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -31,16 +31,14 @@ function main() { var _a, _b, _c; return __awaiter(this, void 0, void 0, function* () { try { - const doNotCache = ((_a = core.getState(vcpkgaction.VCPKG_DO_NOT_CACHE_STATE)) !== null && _a !== void 0 ? _a : false) === "true"; + const doNotCache = ((_a = core.getState(vcpkgaction.VCPKG_DO_NOT_CACHE_STATE)) !== null && _a !== void 0 ? _a : false).toLowerCase() === "true"; const actionLib = new actionlib.ActionLib(); const baseUtil = new baseutillib.BaseUtilLib(actionLib); - const jobSucceeded = core.getInput(vcpkgaction.jobStatusInput).toLowerCase() === 'success'; - const doNotCacheOnWorkflowFailure = core.getInput(vcpkgaction.doNotCacheOnWorkflowFailureInput).toLowerCase() === 'true'; - const cacheHit = core.getState(vcpkgaction.VCPKG_KEY_CACHE_HIT_STATE); + const cacheHitKey = core.getState(vcpkgaction.VCPKG_KEY_CACHE_HIT_STATE); const computedCacheKey = JSON.parse(core.getState(vcpkgaction.VCPKG_CACHE_COMPUTEDKEY_STATE)); const vcpkgRoot = core.getState(vcpkgaction.VCPKG_ROOT_STATE); const cachedPaths = vcpkgutil.Utils.getAllCachedPaths(actionLib, vcpkgRoot); - const post = new vcpkgpostaction.VcpkgPostAction(baseUtil, jobSucceeded, doNotCache, doNotCacheOnWorkflowFailure, computedCacheKey, cachedPaths, cacheHit); + const post = new vcpkgpostaction.VcpkgPostAction(baseUtil, doNotCache, computedCacheKey, cachedPaths, cacheHitKey); yield post.run(); } catch (err) { @@ -81,7 +79,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.VcpkgAction = exports.VCPKG_ADDITIONAL_CACHED_PATHS_STATE = exports.VCPKG_ROOT_STATE = exports.VCPKG_ADDED_CACHEKEY_STATE = exports.VCPKG_DO_NOT_CACHE_STATE = exports.VCPKG_KEY_CACHE_HIT_STATE = exports.VCPKG_CACHE_COMPUTEDKEY_STATE = exports.logCollectionRegExpsInput = exports.appendedCacheKeyInput = exports.vcpkgUrlInput = exports.doNotUpdateVcpkgInput = exports.vcpkgCommitIdInput = exports.vcpkgDirectoryInput = exports.runVcpkgFormatStringInput = exports.runVcpkgInstallInput = exports.vcpkgJsonIgnoresInput = exports.vcpkgJsonGlobInput = exports.doNotCacheOnWorkflowFailureInput = exports.jobStatusInput = exports.binaryCachePathInput = exports.additionalCachedPathsInput = exports.doNotCacheInput = void 0; +exports.VcpkgAction = exports.VCPKG_SUCCESS_STATE = exports.VCPKG_ADDITIONAL_CACHED_PATHS_STATE = exports.VCPKG_ROOT_STATE = exports.VCPKG_ADDED_CACHEKEY_STATE = exports.VCPKG_DO_NOT_CACHE_STATE = exports.VCPKG_KEY_CACHE_HIT_STATE = exports.VCPKG_CACHE_COMPUTEDKEY_STATE = exports.logCollectionRegExpsInput = exports.appendedCacheKeyInput = exports.vcpkgUrlInput = exports.doNotUpdateVcpkgInput = exports.vcpkgCommitIdInput = exports.vcpkgDirectoryInput = exports.runVcpkgFormatStringInput = exports.runVcpkgInstallInput = exports.vcpkgJsonIgnoresInput = exports.vcpkgJsonGlobInput = exports.binaryCachePathInput = exports.additionalCachedPathsInput = exports.doNotCacheInput = void 0; const path = __nccwpck_require__(5622); const cache = __nccwpck_require__(7799); const runvcpkglib = __nccwpck_require__(4393); @@ -90,8 +88,6 @@ const vcpkgutil = __nccwpck_require__(4534); exports.doNotCacheInput = 'DONOTCACHE'; exports.additionalCachedPathsInput = 'ADDITIONALCACHEDPATHS'; exports.binaryCachePathInput = 'BINARYCACHEPATH'; -exports.jobStatusInput = 'JOBSTATUS'; -exports.doNotCacheOnWorkflowFailureInput = 'DONOTCACHEONWORKFLOWFAILURE'; exports.vcpkgJsonGlobInput = 'VCPKGJSONGLOB'; exports.vcpkgJsonIgnoresInput = "VCPKGJSONIGNORES"; exports.runVcpkgInstallInput = 'RUNVCPKGINSTALL'; @@ -112,6 +108,7 @@ exports.VCPKG_DO_NOT_CACHE_STATE = "VCPKG_DO_NOT_CACHE_STATE"; exports.VCPKG_ADDED_CACHEKEY_STATE = "VCPKG_ADDED_CACHEKEY_STATE"; exports.VCPKG_ROOT_STATE = "VCPKG_ROOT_STATE"; exports.VCPKG_ADDITIONAL_CACHED_PATHS_STATE = "VCPKG_ADDITIONAL_CACHED_PATHS_STATE"; +exports.VCPKG_SUCCESS_STATE = "VCPKG_SUCCESS_STATE"; class VcpkgAction { constructor(baseUtilLib) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; @@ -165,8 +162,8 @@ class VcpkgAction { let keys = null; let vcpkgJsonFilePath = null; yield this.baseUtilLib.wrapOp('Compute vcpkg cache key', () => __awaiter(this, void 0, void 0, function* () { - const [vcpkgJsonFile, vcpkgJsonHash] = yield vcpkgutil.Utils.getVcpkgJsonHash(this.baseUtilLib, this.vcpkgJsonGlob, this.vcpkgJsonIgnores); - keys = yield vcpkgutil.Utils.computeCacheKeys(this.baseUtilLib, vcpkgJsonHash, this.vcpkgRootDir, this.userProvidedCommitId, this.appendedCacheKey); + const [vcpkgJsonFile, vcpkgJsonHash, vcpkgConfigurationJsonHash] = yield vcpkgutil.Utils.getVcpkgJsonHash(this.baseUtilLib, this.vcpkgJsonGlob, this.vcpkgJsonIgnores); + keys = yield vcpkgutil.Utils.computeCacheKeys(this.baseUtilLib, vcpkgJsonHash, vcpkgConfigurationJsonHash, this.vcpkgRootDir, this.userProvidedCommitId, this.appendedCacheKey); if (keys) { baseLib.info(`Computed key: ${JSON.stringify(keys)}`); vcpkgJsonFilePath = vcpkgJsonFile; @@ -181,6 +178,7 @@ class VcpkgAction { } 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); + baseLib.setState(exports.VCPKG_SUCCESS_STATE, "success"); this.baseUtilLib.baseLib.debug("run()>>"); }); } @@ -265,11 +263,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", ({ value: true })); exports.VcpkgPostAction = void 0; const vcpkgutil = __nccwpck_require__(4534); +const vcpkgaction = __nccwpck_require__(2929); class VcpkgPostAction { - constructor(baseUtil, jobSucceeded, doNotCacheOnWorkflowFailure, doNotCache, keys, cachedPaths, hitCacheKey) { + constructor(baseUtil, doNotCache, keys, cachedPaths, hitCacheKey) { this.baseUtil = baseUtil; - this.jobSucceeded = jobSucceeded; - this.doNotCacheOnWorkflowFailure = doNotCacheOnWorkflowFailure; this.doNotCache = doNotCache; this.keys = keys; this.cachedPaths = cachedPaths; @@ -277,29 +274,21 @@ class VcpkgPostAction { // Intentionally void. } run() { - var _a, _b; return __awaiter(this, void 0, void 0, function* () { - try { - yield this.baseUtil.wrapOp('Save vcpkg and its artifacts into GitHub service cache', () => __awaiter(this, void 0, void 0, function* () { - if (!this.jobSucceeded && this.doNotCacheOnWorkflowFailure) { - this.baseUtil.baseLib.info("Skipping saving cache as job failed and input 'doNotCacheOnWorkflowFailure : true'."); - return; - } - else { - yield vcpkgutil.Utils.saveCache(this.baseUtil.baseLib, this.doNotCache, this.keys, this.hitCacheKey, this.cachedPaths); - } - })); - this.baseUtil.baseLib.info('run-vcpkg post action execution succeeded'); - process.exitCode = 0; - } - catch (err) { - const error = err; - if (error === null || error === void 0 ? void 0 : error.stack) { - this.baseUtil.baseLib.info(error.stack); + const RUNVCPKG_NO_CACHE = "RUNVCPKG_NO_CACHE"; + yield this.baseUtil.wrapOp('Save vcpkg and its artifacts into GitHub service cache', () => __awaiter(this, void 0, void 0, function* () { + const runvcpkgState = this.baseUtil.baseLib.getState(vcpkgaction.VCPKG_SUCCESS_STATE); + if (process.env[RUNVCPKG_NO_CACHE]) { + this.baseUtil.baseLib.info(`Skipping cache as '${RUNVCPKG_NO_CACHE}' is defined!`); } - const errorAsString = (_b = (_a = err) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : "undefined error"; - process.exitCode = -1000; - } + else if (!runvcpkgState) { + this.baseUtil.baseLib.warning('Skipping cache as run-vcpkg step failed!'); + } + else + yield vcpkgutil.Utils.saveCache(this.baseUtil.baseLib, this.doNotCache, this.keys, this.hitCacheKey, this.cachedPaths); + })); + this.baseUtil.baseLib.info('run-vcpkg post action execution succeeded'); + process.exitCode = 0; }); } } @@ -391,8 +380,14 @@ class Utils { try { const [vcpkgJsonPath, vcpkgJsonHash] = yield baseUtil.getFileHash(vcpkgJsonGlob, vcpkgJsonIgnores); if (vcpkgJsonPath) { - baseUtil.baseLib.info(`Found vcpkg.json at '${vcpkgJsonPath}', its hash is '${vcpkgJsonHash}''.`); - return [vcpkgJsonPath, vcpkgJsonHash]; + baseUtil.baseLib.info(`Found ${runvcpkglib.VCPKG_JSON} at '${vcpkgJsonPath}', its hash is '${vcpkgJsonHash}''.`); + const vcpkgConfJsonPath = path.join(path.dirname(vcpkgJsonPath), runvcpkglib.VCPKG_CONFIGURATION_JSON); + let vcpkgConfigurationHash = null; + if (baseUtil.fileExists(vcpkgConfJsonPath)) { + vcpkgConfigurationHash = yield baseUtil.baseLib.hashFiles(vcpkgConfJsonPath); + baseUtil.baseLib.info(`Found sibling ${runvcpkglib.VCPKG_CONFIGURATION_JSON} at '${vcpkgConfJsonPath}', its hash is '${vcpkgConfigurationHash}'.`); + } + return [vcpkgJsonPath, vcpkgJsonHash, vcpkgConfigurationHash]; } } catch (err) { @@ -401,10 +396,10 @@ class Utils { } } baseUtil.baseLib.warning(`Cannot compute hash of vcpkg.json as it was not found (or multiple hits) with glob expression '${vcpkgJsonGlob}'.`); - return [null, null]; + return [null, null, null]; }); } - static computeCacheKeys(baseUtilLib, vcpkgJsonHash, vcpkgDirectory, userProvidedCommitId, appendedCacheKey) { + static computeCacheKeys(baseUtilLib, vcpkgJsonHash, vcpkgConfJsonHash, vcpkgDirectory, userProvidedCommitId, appendedCacheKey) { return __awaiter(this, void 0, void 0, function* () { baseUtilLib.baseLib.debug(`computeCacheKeys()<<`); const cacheKeySegments = []; @@ -431,8 +426,13 @@ class Utils { } cacheKeySegments.push(firstSegment); if (vcpkgJsonHash) { - cacheKeySegments.push(`vcpkgJson=${vcpkgJsonHash}`); - baseUtilLib.baseLib.info(`Adding hash of vcpkg.json: '${vcpkgJsonHash}'.`); + let hash = `vcpkgJson=${vcpkgJsonHash}`; + baseUtilLib.baseLib.info(`Adding hash of ${runvcpkglib.VCPKG_JSON}: '${vcpkgJsonHash}'.`); + if (vcpkgConfJsonHash) { + baseUtilLib.baseLib.info(`Adding hash of ${runvcpkglib.VCPKG_CONFIGURATION_JSON}: '${vcpkgConfJsonHash}'.`); + hash += `-vcpkgConfigurationJson=${vcpkgConfJsonHash}`; + } + cacheKeySegments.push(hash); } if (appendedCacheKey) { cacheKeySegments.push(`appendedKey=${appendedCacheKey}`); @@ -6998,12 +6998,14 @@ __exportStar(__nccwpck_require__(6188), exports); // Released under the term specified in file LICENSE.txt // SPDX short identifier: MIT Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.VCPKGDEFAULTTRIPLET = exports.VCPKGROOT = exports.vcpkgLastBuiltCommitId = exports.RUNVCPKG_VCPKG_DEFAULT_TRIPLET = exports.RUNVCPKG_VCPKG_ROOT = void 0; +exports.VCPKG_CONFIGURATION_JSON = exports.VCPKG_JSON = exports.VCPKGDEFAULTTRIPLET = exports.VCPKGROOT = exports.vcpkgLastBuiltCommitId = exports.RUNVCPKG_VCPKG_DEFAULT_TRIPLET = exports.RUNVCPKG_VCPKG_ROOT = void 0; exports.RUNVCPKG_VCPKG_ROOT = "RUNVCPKG_VCPKG_ROOT"; exports.RUNVCPKG_VCPKG_DEFAULT_TRIPLET = "RUNVCPKG_VCPKG_DEFAULT_TRIPLET"; exports.vcpkgLastBuiltCommitId = 'vcpkgLastBuiltCommitId'; exports.VCPKGROOT = 'VCPKG_ROOT'; exports.VCPKGDEFAULTTRIPLET = "VCPKG_DEFAULT_TRIPLET"; +exports.VCPKG_JSON = "vcpkg.json"; +exports.VCPKG_CONFIGURATION_JSON = "vcpkg-configuration.json"; //# sourceMappingURL=vcpkg-globals.js.map /***/ }), @@ -7119,6 +7121,10 @@ class VcpkgRunner { runImpl() { return __awaiter(this, void 0, void 0, function* () { this.baseUtils.baseLib.debug("runImpl()<<"); + // By default disable vcpkg telemetry, unless VCPKG_ENABLE_METRICS is set. + if (!process.env[VcpkgRunner.VCPKG_ENABLE_METRICS]) { + process.env[VcpkgRunner.VCPKG_DISABLE_METRICS] = "1"; + } // Ensuring `this.vcpkgDestPath` is existent, since is going to be used as current working directory. if (!(yield this.baseUtils.baseLib.exist(this.vcpkgDestPath))) { this.baseUtils.baseLib.debug(`Creating vcpkg root directory as it is not existing: ${this.vcpkgDestPath}`); @@ -7384,6 +7390,8 @@ class VcpkgRunner { exports.VcpkgRunner = VcpkgRunner; VcpkgRunner.VCPKGINSTALLCMDDEFAULT = '[`install`, `--recurse`, `--clean-after-build`, `--x-install-root`, `$[env.VCPKG_INSTALLED_DIR]`, `--triplet`, `$[env.VCPKG_DEFAULT_TRIPLET]`]'; VcpkgRunner.DEFAULTVCPKGURL = 'https://github.com/microsoft/vcpkg.git'; +VcpkgRunner.VCPKG_ENABLE_METRICS = "VCPKG_ENABLE_METRICS"; +VcpkgRunner.VCPKG_DISABLE_METRICS = "VCPKG_DISABLE_METRICS"; //# sourceMappingURL=vcpkg-runner.js.map /***/ }), diff --git a/package-lock.json b/package-lock.json index 0b876cc8..3fe07eb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,11 +14,11 @@ "@actions/exec": "^1.1.0", "@actions/github": "^5.0.0", "@actions/io": "^1.0.1", - "@lukka/action-lib": "2.0.4", - "@lukka/assets-lib": "2.0.4", - "@lukka/base-lib": "2.0.4", - "@lukka/base-util-lib": "2.0.4", - "@lukka/run-vcpkg-lib": "2.0.4", + "@lukka/action-lib": "2.0.5", + "@lukka/assets-lib": "2.0.5", + "@lukka/base-lib": "2.0.5", + "@lukka/base-util-lib": "2.0.5", + "@lukka/run-vcpkg-lib": "2.0.5", "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.8.0", "@types/jest": "^26.0.14", @@ -1109,9 +1109,9 @@ } }, "node_modules/@lukka/action-lib": { - "version": "2.0.4", - "resolved": "https://npm.pkg.github.com/download/@lukka/action-lib/2.0.4/0ab4dd488590acd96aad32e6d7ec7aa838dd3e1257623d9d0dfe0295ffc6b5e9", - "integrity": "sha512-EVhvFs8q3XiwKgEJspG/ZjaJjU95iJ6BeAsixfAiWF64vCMBGCTtWQnKu6yMFU2B6kE9e/Ssf9c8FtYQjdVDJQ==", + "version": "2.0.5", + "resolved": "https://npm.pkg.github.com/download/@lukka/action-lib/2.0.5/8e2283f88ae1fbcdf3ea7d5245fc307cbe245b140e9a9365deca944b7b4d5fe6", + "integrity": "sha512-Vgx3OVnOKhInymhY+2Ik0ZjTtcKCgU8vt1bjEYw9R8OFrSsgVIjXTiB7QNutGOS6AB52nY3ssMN6B1vscgkwuw==", "license": "MIT", "dependencies": { "@actions/core": "^1.2.6", @@ -1119,8 +1119,8 @@ "@actions/github": "^4.0.0", "@actions/glob": "^0.2.0", "@actions/io": "^1.0.2", - "@lukka/base-lib": "^2.0.4", - "@lukka/base-util-lib": "^2.0.4", + "@lukka/base-lib": "^2.0.5", + "@lukka/base-util-lib": "^2.0.5", "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.8.0", "@types/q": "^1.5.1", @@ -1577,15 +1577,15 @@ } }, "node_modules/@lukka/assets-lib": { - "version": "2.0.4", - "resolved": "https://npm.pkg.github.com/download/@lukka/assets-lib/2.0.4/2081123d67dd4316518464bf580f464822bdf23ae87db02ca18c743e605555f7", - "integrity": "sha512-eF65iloBkG8z7NiPDShxkNt3EoGma1MuXwAXQL02MFkt2jrFS2EtJZvgaEL01cv2VJuvcfPg16u+kQYMfZCGpA==", + "version": "2.0.5", + "resolved": "https://npm.pkg.github.com/download/@lukka/assets-lib/2.0.5/7efc19d446b5e121b17969614177769f6c522f2a8fd88a17aa7d4bf969f0b54e", + "integrity": "sha512-AxGMnHekBYXET0303Nny6XqBlMsRy0n+jdh7p3K3ALeOMTDtBFPfmJX4q+UzZW2Qn+JufG2EwdiEOogYWwAUig==", "license": "MIT" }, "node_modules/@lukka/base-lib": { - "version": "2.0.4", - "resolved": "https://npm.pkg.github.com/download/@lukka/base-lib/2.0.4/893d64cda3d64d61b7b0ed440b5f4e9ab1cd2394eba37a46a568166ca5697e25", - "integrity": "sha512-jrjZGgV5c82J95pfw2CZYHBLK5cbbIq9ZhtxvdF1owvVFgwK53uz3Faouo+OMZYq47HxbzGgfbsZvHQQCyZmDA==", + "version": "2.0.5", + "resolved": "https://npm.pkg.github.com/download/@lukka/base-lib/2.0.5/3112e0c6d9db1bef14700c76e01ce4deefd59bf7d9b5eeb421e415b926153da1", + "integrity": "sha512-YPYvoBwewtmMtlyCk/IUaFyzezpv6UgcTcDqum4xw5xu08saqJHxJWFulIkHCu/H5r+EI6TzH8HnlXMIATSF+w==", "license": "MIT", "dependencies": { "@types/adm-zip": "^0.4.32", @@ -2021,24 +2021,24 @@ } }, "node_modules/@lukka/base-util-lib": { - "version": "2.0.4", - "resolved": "https://npm.pkg.github.com/download/@lukka/base-util-lib/2.0.4/5274ca4a79079da4c7179b08be771983027212381c01f0897f68664ce20b6ae8", - "integrity": "sha512-jQeP7xpP6U8TdqvivEUy2ZUVXdla5E/wOgl72NvwW4uNvdIs6jq3u9eLtaIPVclOjdoN1HjhKGbjl/IJKKyCQw==", + "version": "2.0.5", + "resolved": "https://npm.pkg.github.com/download/@lukka/base-util-lib/2.0.5/728c9f201e71f5347fc111be08b5f43b2a7dacc1f626ba7cfe1295816c37965e", + "integrity": "sha512-WB0x6enQr6yhnPTxF0fbjvU7S2odgneSCB1Kc7E5peS4PknCIzrhK7540gViNIUDEjYdBlEHVx/WTe7TJa9azA==", "license": "MIT", "dependencies": { - "@lukka/base-lib": "^2.0.4", + "@lukka/base-lib": "^2.0.5", "fast-glob": "3.2.7" } }, "node_modules/@lukka/run-vcpkg-lib": { - "version": "2.0.4", - "resolved": "https://npm.pkg.github.com/download/@lukka/run-vcpkg-lib/2.0.4/ca2809e5882b4186a94f5d9b580cf0df4a53556efd5e9fda595f6a02c46d14c8", - "integrity": "sha512-gf/yGM6F2jH0aSSZqm6kwO+z6Px+d63ECSjh6iKy+P2d+g3nxLxlToXuSfUzXMe1jUN7FAFrS6nWoz538kmhUA==", + "version": "2.0.5", + "resolved": "https://npm.pkg.github.com/download/@lukka/run-vcpkg-lib/2.0.5/794a6dd527c177860b1c54b3c50dbdc9daf649a4c7afa606e2453b84290c788d", + "integrity": "sha512-RBLFTo4DlsjIHykJ3nDMvY7CnESH0vFaVmlDdcCICDEv2M1eIEKbWGTpSELs4zXXlW/wGmHAQRkkqI9kSjX5uQ==", "license": "MIT", "dependencies": { - "@lukka/action-lib": "^2.0.4", - "@lukka/base-lib": "^2.0.4", - "@lukka/base-util-lib": "^2.0.4", + "@lukka/action-lib": "^2.0.5", + "@lukka/base-lib": "^2.0.5", + "@lukka/base-util-lib": "^2.0.5", "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.8.0", "@types/q": "^1.5.1", @@ -13584,17 +13584,17 @@ } }, "@lukka/action-lib": { - "version": "2.0.4", - "resolved": "https://npm.pkg.github.com/download/@lukka/action-lib/2.0.4/0ab4dd488590acd96aad32e6d7ec7aa838dd3e1257623d9d0dfe0295ffc6b5e9", - "integrity": "sha512-EVhvFs8q3XiwKgEJspG/ZjaJjU95iJ6BeAsixfAiWF64vCMBGCTtWQnKu6yMFU2B6kE9e/Ssf9c8FtYQjdVDJQ==", + "version": "2.0.5", + "resolved": "https://npm.pkg.github.com/download/@lukka/action-lib/2.0.5/8e2283f88ae1fbcdf3ea7d5245fc307cbe245b140e9a9365deca944b7b4d5fe6", + "integrity": "sha512-Vgx3OVnOKhInymhY+2Ik0ZjTtcKCgU8vt1bjEYw9R8OFrSsgVIjXTiB7QNutGOS6AB52nY3ssMN6B1vscgkwuw==", "requires": { "@actions/core": "^1.2.6", "@actions/exec": "^1.0.4", "@actions/github": "^4.0.0", "@actions/glob": "^0.2.0", "@actions/io": "^1.0.2", - "@lukka/base-lib": "^2.0.4", - "@lukka/base-util-lib": "^2.0.4", + "@lukka/base-lib": "^2.0.5", + "@lukka/base-util-lib": "^2.0.5", "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.8.0", "@types/q": "^1.5.1", @@ -13944,14 +13944,14 @@ } }, "@lukka/assets-lib": { - "version": "2.0.4", - "resolved": "https://npm.pkg.github.com/download/@lukka/assets-lib/2.0.4/2081123d67dd4316518464bf580f464822bdf23ae87db02ca18c743e605555f7", - "integrity": "sha512-eF65iloBkG8z7NiPDShxkNt3EoGma1MuXwAXQL02MFkt2jrFS2EtJZvgaEL01cv2VJuvcfPg16u+kQYMfZCGpA==" + "version": "2.0.5", + "resolved": "https://npm.pkg.github.com/download/@lukka/assets-lib/2.0.5/7efc19d446b5e121b17969614177769f6c522f2a8fd88a17aa7d4bf969f0b54e", + "integrity": "sha512-AxGMnHekBYXET0303Nny6XqBlMsRy0n+jdh7p3K3ALeOMTDtBFPfmJX4q+UzZW2Qn+JufG2EwdiEOogYWwAUig==" }, "@lukka/base-lib": { - "version": "2.0.4", - "resolved": "https://npm.pkg.github.com/download/@lukka/base-lib/2.0.4/893d64cda3d64d61b7b0ed440b5f4e9ab1cd2394eba37a46a568166ca5697e25", - "integrity": "sha512-jrjZGgV5c82J95pfw2CZYHBLK5cbbIq9ZhtxvdF1owvVFgwK53uz3Faouo+OMZYq47HxbzGgfbsZvHQQCyZmDA==", + "version": "2.0.5", + "resolved": "https://npm.pkg.github.com/download/@lukka/base-lib/2.0.5/3112e0c6d9db1bef14700c76e01ce4deefd59bf7d9b5eeb421e415b926153da1", + "integrity": "sha512-YPYvoBwewtmMtlyCk/IUaFyzezpv6UgcTcDqum4xw5xu08saqJHxJWFulIkHCu/H5r+EI6TzH8HnlXMIATSF+w==", "requires": { "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.8.0", @@ -14282,22 +14282,22 @@ } }, "@lukka/base-util-lib": { - "version": "2.0.4", - "resolved": "https://npm.pkg.github.com/download/@lukka/base-util-lib/2.0.4/5274ca4a79079da4c7179b08be771983027212381c01f0897f68664ce20b6ae8", - "integrity": "sha512-jQeP7xpP6U8TdqvivEUy2ZUVXdla5E/wOgl72NvwW4uNvdIs6jq3u9eLtaIPVclOjdoN1HjhKGbjl/IJKKyCQw==", + "version": "2.0.5", + "resolved": "https://npm.pkg.github.com/download/@lukka/base-util-lib/2.0.5/728c9f201e71f5347fc111be08b5f43b2a7dacc1f626ba7cfe1295816c37965e", + "integrity": "sha512-WB0x6enQr6yhnPTxF0fbjvU7S2odgneSCB1Kc7E5peS4PknCIzrhK7540gViNIUDEjYdBlEHVx/WTe7TJa9azA==", "requires": { - "@lukka/base-lib": "^2.0.4", + "@lukka/base-lib": "^2.0.5", "fast-glob": "3.2.7" } }, "@lukka/run-vcpkg-lib": { - "version": "2.0.4", - "resolved": "https://npm.pkg.github.com/download/@lukka/run-vcpkg-lib/2.0.4/ca2809e5882b4186a94f5d9b580cf0df4a53556efd5e9fda595f6a02c46d14c8", - "integrity": "sha512-gf/yGM6F2jH0aSSZqm6kwO+z6Px+d63ECSjh6iKy+P2d+g3nxLxlToXuSfUzXMe1jUN7FAFrS6nWoz538kmhUA==", + "version": "2.0.5", + "resolved": "https://npm.pkg.github.com/download/@lukka/run-vcpkg-lib/2.0.5/794a6dd527c177860b1c54b3c50dbdc9daf649a4c7afa606e2453b84290c788d", + "integrity": "sha512-RBLFTo4DlsjIHykJ3nDMvY7CnESH0vFaVmlDdcCICDEv2M1eIEKbWGTpSELs4zXXlW/wGmHAQRkkqI9kSjX5uQ==", "requires": { - "@lukka/action-lib": "^2.0.4", - "@lukka/base-lib": "^2.0.4", - "@lukka/base-util-lib": "^2.0.4", + "@lukka/action-lib": "^2.0.5", + "@lukka/base-lib": "^2.0.5", + "@lukka/base-util-lib": "^2.0.5", "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.8.0", "@types/q": "^1.5.1", diff --git a/package.json b/package.json index afa96f24..fb5bb0c8 100644 --- a/package.json +++ b/package.json @@ -43,11 +43,11 @@ "@actions/exec": "^1.1.0", "@actions/github": "^5.0.0", "@actions/io": "^1.0.1", - "@lukka/action-lib": "2.0.4", - "@lukka/assets-lib": "2.0.4", - "@lukka/base-lib": "2.0.4", - "@lukka/base-util-lib": "2.0.4", - "@lukka/run-vcpkg-lib": "2.0.4", + "@lukka/action-lib": "2.0.5", + "@lukka/assets-lib": "2.0.5", + "@lukka/base-lib": "2.0.5", + "@lukka/base-util-lib": "2.0.5", + "@lukka/run-vcpkg-lib": "2.0.5", "@types/adm-zip": "^0.4.32", "@types/follow-redirects": "^1.8.0", "@types/jest": "^26.0.14", diff --git a/src/post-action.ts b/src/post-action.ts index 267dad3f..1379a5d3 100644 --- a/src/post-action.ts +++ b/src/post-action.ts @@ -11,20 +11,17 @@ import * as vcpkgpostaction from './vcpkg-post-action' export async function main(): Promise { try { - const doNotCache = (core.getState(vcpkgaction.VCPKG_DO_NOT_CACHE_STATE) ?? false) === "true"; + const doNotCache = (core.getState(vcpkgaction.VCPKG_DO_NOT_CACHE_STATE) ?? false).toLowerCase() === "true"; const actionLib = new actionlib.ActionLib(); const baseUtil = new baseutillib.BaseUtilLib(actionLib); - const jobSucceeded: boolean = core.getInput(vcpkgaction.jobStatusInput).toLowerCase() === 'success'; - const doNotCacheOnWorkflowFailure: boolean = core.getInput(vcpkgaction.doNotCacheOnWorkflowFailureInput).toLowerCase() === 'true' - const cacheHit: string = core.getState(vcpkgaction.VCPKG_KEY_CACHE_HIT_STATE); + const cacheHitKey: string = core.getState(vcpkgaction.VCPKG_KEY_CACHE_HIT_STATE); const computedCacheKey: baseutillib.KeySet = JSON.parse(core.getState(vcpkgaction.VCPKG_CACHE_COMPUTEDKEY_STATE)) as baseutillib.KeySet; const vcpkgRoot = core.getState(vcpkgaction.VCPKG_ROOT_STATE); const cachedPaths: string[] = vcpkgutil.Utils.getAllCachedPaths(actionLib, vcpkgRoot); const post = new vcpkgpostaction.VcpkgPostAction(baseUtil, - jobSucceeded, doNotCache, doNotCacheOnWorkflowFailure, - computedCacheKey, cachedPaths, cacheHit); + doNotCache, computedCacheKey, cachedPaths, cacheHitKey); await post.run(); } catch (err) { const error: Error = err as Error; diff --git a/src/vcpkg-action.ts b/src/vcpkg-action.ts index 51a11fa6..5a95878a 100644 --- a/src/vcpkg-action.ts +++ b/src/vcpkg-action.ts @@ -12,8 +12,6 @@ import * as vcpkgutil from './vcpkg-utils' export const doNotCacheInput = 'DONOTCACHE'; export const additionalCachedPathsInput = 'ADDITIONALCACHEDPATHS'; export const binaryCachePathInput = 'BINARYCACHEPATH'; -export const jobStatusInput = 'JOBSTATUS'; -export const doNotCacheOnWorkflowFailureInput = 'DONOTCACHEONWORKFLOWFAILURE'; export const vcpkgJsonGlobInput = 'VCPKGJSONGLOB'; export const vcpkgJsonIgnoresInput = "VCPKGJSONIGNORES"; export const runVcpkgInstallInput = 'RUNVCPKGINSTALL'; @@ -35,6 +33,7 @@ export const VCPKG_DO_NOT_CACHE_STATE = "VCPKG_DO_NOT_CACHE_STATE"; export const VCPKG_ADDED_CACHEKEY_STATE = "VCPKG_ADDED_CACHEKEY_STATE"; export const VCPKG_ROOT_STATE = "VCPKG_ROOT_STATE"; export const VCPKG_ADDITIONAL_CACHED_PATHS_STATE = "VCPKG_ADDITIONAL_CACHED_PATHS_STATE"; +export const VCPKG_SUCCESS_STATE = "VCPKG_SUCCESS_STATE"; export class VcpkgAction { public static readonly VCPKG_DEFAULT_BINARY_CACHE = "VCPKG_DEFAULT_BINARY_CACHE"; @@ -110,9 +109,14 @@ export class VcpkgAction { let keys: baseutillib.KeySet | null = null; let vcpkgJsonFilePath: string | null = null; await this.baseUtilLib.wrapOp('Compute vcpkg cache key', async () => { - const [vcpkgJsonFile, vcpkgJsonHash] = await vcpkgutil.Utils.getVcpkgJsonHash(this.baseUtilLib, this.vcpkgJsonGlob, this.vcpkgJsonIgnores); + const [vcpkgJsonFile, vcpkgJsonHash, vcpkgConfigurationJsonHash] = await vcpkgutil.Utils.getVcpkgJsonHash(this.baseUtilLib, this.vcpkgJsonGlob, this.vcpkgJsonIgnores); keys = await vcpkgutil.Utils.computeCacheKeys( - this.baseUtilLib, vcpkgJsonHash, this.vcpkgRootDir as string, this.userProvidedCommitId, this.appendedCacheKey); + this.baseUtilLib, + vcpkgJsonHash, + vcpkgConfigurationJsonHash, + this.vcpkgRootDir as string, + this.userProvidedCommitId, + this.appendedCacheKey); if (keys) { baseLib.info(`Computed key: ${JSON.stringify(keys)}`); @@ -141,6 +145,7 @@ export class VcpkgAction { this.runVcpkgFormatString ); + baseLib.setState(VCPKG_SUCCESS_STATE, "success"); this.baseUtilLib.baseLib.debug("run()>>"); } diff --git a/src/vcpkg-post-action.ts b/src/vcpkg-post-action.ts index bdcb3251..54721092 100644 --- a/src/vcpkg-post-action.ts +++ b/src/vcpkg-post-action.ts @@ -3,15 +3,13 @@ // Released under the term specified in file LICENSE.txt // SPDX short identifier: MIT -import * as core from '@actions/core' import * as baseutillib from '@lukka/base-util-lib' import * as vcpkgutil from './vcpkg-utils' +import * as vcpkgaction from './vcpkg-action' export class VcpkgPostAction { constructor( private baseUtil: baseutillib.BaseUtilLib, - private jobSucceeded: boolean, - private doNotCacheOnWorkflowFailure: boolean, private doNotCache: boolean, private keys: baseutillib.KeySet, private cachedPaths: string[], @@ -21,25 +19,18 @@ export class VcpkgPostAction { } public async run(): Promise { - try { - await this.baseUtil.wrapOp('Save vcpkg and its artifacts into GitHub service cache', - async () => { - if (!this.jobSucceeded && this.doNotCacheOnWorkflowFailure) { - this.baseUtil.baseLib.info("Skipping saving cache as job failed and input 'doNotCacheOnWorkflowFailure : true'."); - return; - } else { - await vcpkgutil.Utils.saveCache(this.baseUtil.baseLib, this.doNotCache, this.keys, this.hitCacheKey, this.cachedPaths); - } - }); - this.baseUtil.baseLib.info('run-vcpkg post action execution succeeded'); - process.exitCode = 0; - } catch (err) { - const error: Error = err as Error; - if (error?.stack) { - this.baseUtil.baseLib.info(error.stack); - } - const errorAsString = (err as Error)?.message ?? "undefined error"; - process.exitCode = -1000; - } + const RUNVCPKG_NO_CACHE = "RUNVCPKG_NO_CACHE"; + await this.baseUtil.wrapOp('Save vcpkg and its artifacts into GitHub service cache', + async () => { + const runvcpkgState = this.baseUtil.baseLib.getState(vcpkgaction.VCPKG_SUCCESS_STATE); + if (process.env[RUNVCPKG_NO_CACHE]) { + this.baseUtil.baseLib.info(`Skipping cache as '${RUNVCPKG_NO_CACHE}' is defined!`); + } else if (!runvcpkgState) { + this.baseUtil.baseLib.warning('Skipping cache as run-vcpkg step failed!'); + } else + await vcpkgutil.Utils.saveCache(this.baseUtil.baseLib, this.doNotCache, this.keys, this.hitCacheKey, this.cachedPaths); + }); + this.baseUtil.baseLib.info('run-vcpkg post action execution succeeded'); + process.exitCode = 0; } } diff --git a/src/vcpkg-utils.ts b/src/vcpkg-utils.ts index efc1bcbf..ac9d472d 100644 --- a/src/vcpkg-utils.ts +++ b/src/vcpkg-utils.ts @@ -60,12 +60,18 @@ export class Utils { return [id, isSubmodule]; } - public static async getVcpkgJsonHash(baseUtil: baseutillib.BaseUtilLib, vcpkgJsonGlob: string, vcpkgJsonIgnores: string[]): Promise<[string | null, string | null]> { + public static async getVcpkgJsonHash(baseUtil: baseutillib.BaseUtilLib, vcpkgJsonGlob: string, vcpkgJsonIgnores: string[]): Promise<[string | null, string | null, string | null]> { try { const [vcpkgJsonPath, vcpkgJsonHash] = await baseUtil.getFileHash(vcpkgJsonGlob, vcpkgJsonIgnores); if (vcpkgJsonPath) { - baseUtil.baseLib.info(`Found vcpkg.json at '${vcpkgJsonPath}', its hash is '${vcpkgJsonHash}''.`); - return [vcpkgJsonPath, vcpkgJsonHash]; + baseUtil.baseLib.info(`Found ${runvcpkglib.VCPKG_JSON} at '${vcpkgJsonPath}', its hash is '${vcpkgJsonHash}''.`); + const vcpkgConfJsonPath: string = path.join(path.dirname(vcpkgJsonPath), runvcpkglib.VCPKG_CONFIGURATION_JSON); + let vcpkgConfigurationHash = null; + if (baseUtil.fileExists(vcpkgConfJsonPath)) { + vcpkgConfigurationHash = await baseUtil.baseLib.hashFiles(vcpkgConfJsonPath); + baseUtil.baseLib.info(`Found sibling ${runvcpkglib.VCPKG_CONFIGURATION_JSON} at '${vcpkgConfJsonPath}', its hash is '${vcpkgConfigurationHash}'.`) + } + return [vcpkgJsonPath, vcpkgJsonHash, vcpkgConfigurationHash]; } } catch (err) { @@ -75,12 +81,13 @@ export class Utils { } baseUtil.baseLib.warning(`Cannot compute hash of vcpkg.json as it was not found (or multiple hits) with glob expression '${vcpkgJsonGlob}'.`); - return [null, null]; + return [null, null, null]; } public static async computeCacheKeys( baseUtilLib: baseutillib.BaseUtilLib, vcpkgJsonHash: string | null, + vcpkgConfJsonHash: string | null, vcpkgDirectory: string, userProvidedCommitId: string | null, appendedCacheKey: string | null): Promise { @@ -110,8 +117,13 @@ export class Utils { cacheKeySegments.push(firstSegment); if (vcpkgJsonHash) { - cacheKeySegments.push(`vcpkgJson=${vcpkgJsonHash}`); - baseUtilLib.baseLib.info(`Adding hash of vcpkg.json: '${vcpkgJsonHash}'.`); + let hash = `vcpkgJson=${vcpkgJsonHash}`; + baseUtilLib.baseLib.info(`Adding hash of ${runvcpkglib.VCPKG_JSON}: '${vcpkgJsonHash}'.`); + if (vcpkgConfJsonHash) { + baseUtilLib.baseLib.info(`Adding hash of ${runvcpkglib.VCPKG_CONFIGURATION_JSON}: '${vcpkgConfJsonHash}'.`); + hash += `-vcpkgConfigurationJson=${vcpkgConfJsonHash}`; + } + cacheKeySegments.push(hash); } if (appendedCacheKey) {