From 205a4bde2b6ddf941a102fb50320ea1aa9338233 Mon Sep 17 00:00:00 2001 From: Luca <681992+lukka@users.noreply.github.com> Date: Fri, 5 Feb 2021 23:46:59 -0800 Subject: [PATCH] fix return code (#73) npm run pack --- dist/index.js | 46 ++++++++++++++++++++------------------------- dist/post/index.js | 46 ++++++++++++++++++++------------------------- src/vcpkg-action.ts | 41 +++++++++++++++------------------------- 3 files changed, 55 insertions(+), 78 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2949c737..81745596 100644 --- a/dist/index.js +++ b/dist/index.js @@ -109,34 +109,23 @@ class VcpkgAction { } run() { return __awaiter(this, void 0, void 0, function* () { - try { - const vcpkgCacheComputedKey = yield vcpkgutil.Utils.computeCacheKey(this.appendedCacheKey); - if (!vcpkgCacheComputedKey) { - core.error("Computation for the cache key failed!"); + const vcpkgCacheComputedKey = yield vcpkgutil.Utils.computeCacheKey(this.appendedCacheKey); + if (!vcpkgCacheComputedKey) { + core.error("Computation for the cache key failed!"); + } + else { + core.saveState(exports.VCPKG_CACHE_COMPUTED_KEY, vcpkgCacheComputedKey); + core.info(`Cache's key = '${vcpkgCacheComputedKey}'.`); + yield this.baseUtilLib.wrapOp('Restore vcpkg and its artifacts from cache', () => this.restoreCache(vcpkgCacheComputedKey)); + const runner = new runvcpkglib.VcpkgRunner(this.baseUtilLib.baseLib); + yield runner.run(); + if (this.isSetupOnly) { + yield this.baseUtilLib.wrapOp('Cache vcpkg and its artifacts', () => this.saveCache(vcpkgCacheComputedKey)); } else { - core.saveState(exports.VCPKG_CACHE_COMPUTED_KEY, vcpkgCacheComputedKey); - core.info(`Cache's key = '${vcpkgCacheComputedKey}'.`); - yield this.baseUtilLib.wrapOp('Restore vcpkg and its artifacts from cache', () => this.restoreCache(vcpkgCacheComputedKey)); - const runner = new runvcpkglib.VcpkgRunner(this.baseUtilLib.baseLib); - yield runner.run(); - if (this.isSetupOnly) { - yield this.baseUtilLib.wrapOp('Cache vcpkg and its artifacts', () => this.saveCache(vcpkgCacheComputedKey)); - } - else { - // If 'setupOnly' is true, trigger the saving of the cache during the post-action execution. - core.saveState(exports.VCPKG_DO_CACHE_ON_POST_ACTION_KEY, "true"); - } - } - } - catch (err) { - const error = err; - if (error === null || error === void 0 ? void 0 : error.stack) { - core.info(error.stack); + // If 'setupOnly' is true, trigger the saving of the cache during the post-action execution. + core.saveState(exports.VCPKG_DO_CACHE_ON_POST_ACTION_KEY, "true"); } - const errorAsString = (err !== null && err !== void 0 ? err : "undefined error").toString(); - core.setFailed(`run-vcpkg action execution failed: '${errorAsString}`); - process.exitCode = -1000; } }); } @@ -5760,7 +5749,7 @@ class VcpkgRunner { checkExecutable() { return __awaiter(this, void 0, void 0, function* () { let needRebuild = false; - // If the executable file ./vcpkg/vcpkg is not present, force build. The fact that 'the repository is up to date' is meaningless. + // If the executable file ./vcpkg/vcpkg is not present or it is not wokring, force build. The fact that 'the repository is up to date' is meaningless. const vcpkgExePath = this.baseUtils.getVcpkgExePath(this.vcpkgDestPath); if (!this.baseUtils.fileExists(vcpkgExePath)) { this.tl.info("Building vcpkg is necessary as executable is missing."); @@ -5771,6 +5760,11 @@ class VcpkgRunner { yield this.tl.execSync('chmod', ["+x", vcpkgExePath]); } this.tl.info(`vcpkg executable exists at: '${vcpkgExePath}'.`); + const result = yield this.tl.execSync(vcpkgExePath, ['--version']); + if (result.code != 0) { + needRebuild = true; + this.tl.info(`vcpkg executable returned code ${result.code}, forcing a rebuild.`); + } } return needRebuild; }); diff --git a/dist/post/index.js b/dist/post/index.js index 112fed59..34111dd9 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -121,34 +121,23 @@ class VcpkgAction { } run() { return __awaiter(this, void 0, void 0, function* () { - try { - const vcpkgCacheComputedKey = yield vcpkgutil.Utils.computeCacheKey(this.appendedCacheKey); - if (!vcpkgCacheComputedKey) { - core.error("Computation for the cache key failed!"); + const vcpkgCacheComputedKey = yield vcpkgutil.Utils.computeCacheKey(this.appendedCacheKey); + if (!vcpkgCacheComputedKey) { + core.error("Computation for the cache key failed!"); + } + else { + core.saveState(exports.VCPKG_CACHE_COMPUTED_KEY, vcpkgCacheComputedKey); + core.info(`Cache's key = '${vcpkgCacheComputedKey}'.`); + yield this.baseUtilLib.wrapOp('Restore vcpkg and its artifacts from cache', () => this.restoreCache(vcpkgCacheComputedKey)); + const runner = new runvcpkglib.VcpkgRunner(this.baseUtilLib.baseLib); + yield runner.run(); + if (this.isSetupOnly) { + yield this.baseUtilLib.wrapOp('Cache vcpkg and its artifacts', () => this.saveCache(vcpkgCacheComputedKey)); } else { - core.saveState(exports.VCPKG_CACHE_COMPUTED_KEY, vcpkgCacheComputedKey); - core.info(`Cache's key = '${vcpkgCacheComputedKey}'.`); - yield this.baseUtilLib.wrapOp('Restore vcpkg and its artifacts from cache', () => this.restoreCache(vcpkgCacheComputedKey)); - const runner = new runvcpkglib.VcpkgRunner(this.baseUtilLib.baseLib); - yield runner.run(); - if (this.isSetupOnly) { - yield this.baseUtilLib.wrapOp('Cache vcpkg and its artifacts', () => this.saveCache(vcpkgCacheComputedKey)); - } - else { - // If 'setupOnly' is true, trigger the saving of the cache during the post-action execution. - core.saveState(exports.VCPKG_DO_CACHE_ON_POST_ACTION_KEY, "true"); - } - } - } - catch (err) { - const error = err; - if (error === null || error === void 0 ? void 0 : error.stack) { - core.info(error.stack); + // If 'setupOnly' is true, trigger the saving of the cache during the post-action execution. + core.saveState(exports.VCPKG_DO_CACHE_ON_POST_ACTION_KEY, "true"); } - const errorAsString = (err !== null && err !== void 0 ? err : "undefined error").toString(); - core.setFailed(`run-vcpkg action execution failed: '${errorAsString}`); - process.exitCode = -1000; } }); } @@ -5772,7 +5761,7 @@ class VcpkgRunner { checkExecutable() { return __awaiter(this, void 0, void 0, function* () { let needRebuild = false; - // If the executable file ./vcpkg/vcpkg is not present, force build. The fact that 'the repository is up to date' is meaningless. + // If the executable file ./vcpkg/vcpkg is not present or it is not wokring, force build. The fact that 'the repository is up to date' is meaningless. const vcpkgExePath = this.baseUtils.getVcpkgExePath(this.vcpkgDestPath); if (!this.baseUtils.fileExists(vcpkgExePath)) { this.tl.info("Building vcpkg is necessary as executable is missing."); @@ -5783,6 +5772,11 @@ class VcpkgRunner { yield this.tl.execSync('chmod', ["+x", vcpkgExePath]); } this.tl.info(`vcpkg executable exists at: '${vcpkgExePath}'.`); + const result = yield this.tl.execSync(vcpkgExePath, ['--version']); + if (result.code != 0) { + needRebuild = true; + this.tl.info(`vcpkg executable returned code ${result.code}, forcing a rebuild.`); + } } return needRebuild; }); diff --git a/src/vcpkg-action.ts b/src/vcpkg-action.ts index 2312f55d..b5f92673 100644 --- a/src/vcpkg-action.ts +++ b/src/vcpkg-action.ts @@ -47,34 +47,23 @@ export class VcpkgAction { } public async run(): Promise { - try { - const vcpkgCacheComputedKey = await vcpkgutil.Utils.computeCacheKey(this.appendedCacheKey); - if (!vcpkgCacheComputedKey) { - core.error("Computation for the cache key failed!"); - } else { - core.saveState(VCPKG_CACHE_COMPUTED_KEY, vcpkgCacheComputedKey); - core.info(`Cache's key = '${vcpkgCacheComputedKey}'.`); - await this.baseUtilLib.wrapOp('Restore vcpkg and its artifacts from cache', - () => this.restoreCache(vcpkgCacheComputedKey as string)); - const runner: runvcpkglib.VcpkgRunner = new runvcpkglib.VcpkgRunner(this.baseUtilLib.baseLib); - await runner.run(); + const vcpkgCacheComputedKey = await vcpkgutil.Utils.computeCacheKey(this.appendedCacheKey); + if (!vcpkgCacheComputedKey) { + core.error("Computation for the cache key failed!"); + } else { + core.saveState(VCPKG_CACHE_COMPUTED_KEY, vcpkgCacheComputedKey); + core.info(`Cache's key = '${vcpkgCacheComputedKey}'.`); + await this.baseUtilLib.wrapOp('Restore vcpkg and its artifacts from cache', + () => this.restoreCache(vcpkgCacheComputedKey as string)); + const runner: runvcpkglib.VcpkgRunner = new runvcpkglib.VcpkgRunner(this.baseUtilLib.baseLib); + await runner.run(); - if (this.isSetupOnly) { - await this.baseUtilLib.wrapOp('Cache vcpkg and its artifacts', () => this.saveCache(vcpkgCacheComputedKey as string)); - } else { - // If 'setupOnly' is true, trigger the saving of the cache during the post-action execution. - core.saveState(VCPKG_DO_CACHE_ON_POST_ACTION_KEY, "true"); - } - } - } - catch (err) { - const error: Error = err as Error; - if (error?.stack) { - core.info(error.stack); + if (this.isSetupOnly) { + await this.baseUtilLib.wrapOp('Cache vcpkg and its artifacts', () => this.saveCache(vcpkgCacheComputedKey as string)); + } else { + // If 'setupOnly' is true, trigger the saving of the cache during the post-action execution. + core.saveState(VCPKG_DO_CACHE_ON_POST_ACTION_KEY, "true"); } - const errorAsString = (err ?? "undefined error").toString(); - core.setFailed(`run-vcpkg action execution failed: '${errorAsString}`); - process.exitCode = -1000; } }