diff --git a/lib/analyze-action-post-helper.js b/lib/analyze-action-post-helper.js new file mode 100644 index 000000000..991ba9a46 --- /dev/null +++ b/lib/analyze-action-post-helper.js @@ -0,0 +1,42 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.run = void 0; +// REVIEW: What do you think about the name of this file? +const core = __importStar(require("@actions/core")); +const actionsUtil = __importStar(require("./actions-util")); +const config_utils_1 = require("./config-utils"); +const logging_1 = require("./logging"); +async function run(uploadSarifDebugArtifact) { + const logger = (0, logging_1.getActionsLogger)(); + const config = await (0, config_utils_1.getConfig)(actionsUtil.getTemporaryDirectory(), logger); + if (config === undefined) { + throw new Error("Config file could not be found at expected location. Did the 'init' action fail to start?"); + } + // Upload Actions SARIF artifacts for debugging + if (config === null || config === void 0 ? void 0 : config.debugMode) { + core.info("Debug mode is on. Uploading available SARIF files as Actions debugging artifact..."); + const outputDir = actionsUtil.getRequiredInput("output"); + await uploadSarifDebugArtifact(config, outputDir); + } +} +exports.run = run; +//# sourceMappingURL=analyze-action-post-helper.js.map \ No newline at end of file diff --git a/lib/analyze-action-post-helper.js.map b/lib/analyze-action-post-helper.js.map new file mode 100644 index 000000000..7a2f5e5c5 --- /dev/null +++ b/lib/analyze-action-post-helper.js.map @@ -0,0 +1 @@ +{"version":3,"file":"analyze-action-post-helper.js","sourceRoot":"","sources":["../src/analyze-action-post-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAyD;AACzD,oDAAsC;AAEtC,4DAA8C;AAC9C,iDAA2C;AAC3C,uCAA6C;AAEtC,KAAK,UAAU,GAAG,CAAC,wBAAkC;IAC1D,MAAM,MAAM,GAAG,IAAA,0BAAgB,GAAE,CAAC;IAElC,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAS,EAAC,WAAW,CAAC,qBAAqB,EAAE,EAAE,MAAM,CAAC,CAAC;IAC5E,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;KACH;IAED,+CAA+C;IAC/C,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,EAAE;QACrB,IAAI,CAAC,IAAI,CACP,oFAAoF,CACrF,CAAC;QACF,MAAM,SAAS,GAAG,WAAW,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACzD,MAAM,wBAAwB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;KACnD;AACH,CAAC;AAlBD,kBAkBC"} \ No newline at end of file diff --git a/lib/analyze-action-post-helper.test.js b/lib/analyze-action-post-helper.test.js new file mode 100644 index 000000000..1b01c6425 --- /dev/null +++ b/lib/analyze-action-post-helper.test.js @@ -0,0 +1,69 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const ava_1 = __importDefault(require("ava")); +const sinon = __importStar(require("sinon")); +const actionsUtil = __importStar(require("./actions-util")); +const analyzeActionPostHelper = __importStar(require("./analyze-action-post-helper")); +const configUtils = __importStar(require("./config-utils")); +const testing_utils_1 = require("./testing-utils"); +const util = __importStar(require("./util")); +(0, testing_utils_1.setupTests)(ava_1.default); +(0, ava_1.default)("post: analyze action with debug mode off", async (t) => { + return await util.withTmpDir(async (tmpDir) => { + process.env["RUNNER_TEMP"] = tmpDir; + const gitHubVersion = { + type: util.GitHubVariant.DOTCOM, + }; + sinon.stub(configUtils, "getConfig").resolves({ + debugMode: false, + gitHubVersion, + languages: [], + packs: [], + }); + const uploadSarifSpy = sinon.spy(); + await analyzeActionPostHelper.run(uploadSarifSpy); + t.assert(uploadSarifSpy.notCalled); + }); +}); +(0, ava_1.default)("post: analyze action with debug mode on", async (t) => { + return await util.withTmpDir(async (tmpDir) => { + process.env["RUNNER_TEMP"] = tmpDir; + const gitHubVersion = { + type: util.GitHubVariant.DOTCOM, + }; + sinon.stub(configUtils, "getConfig").resolves({ + debugMode: true, + gitHubVersion, + languages: [], + packs: [], + }); + const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput"); + requiredInputStub.withArgs("output").returns("fake-output-dir"); + const uploadSarifSpy = sinon.spy(); + await analyzeActionPostHelper.run(uploadSarifSpy); + t.assert(uploadSarifSpy.called); + }); +}); +//# sourceMappingURL=analyze-action-post-helper.test.js.map \ No newline at end of file diff --git a/lib/analyze-action-post-helper.test.js.map b/lib/analyze-action-post-helper.test.js.map new file mode 100644 index 000000000..0387d891e --- /dev/null +++ b/lib/analyze-action-post-helper.test.js.map @@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,MAAM;SAChC,CAAC;QACF,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC;YAC5C,SAAS,EAAE,IAAI;YACf,aAAa;YACb,SAAS,EAAE,EAAE;YACb,KAAK,EAAE,EAAE;SACuB,CAAC,CAAC;QAEpC,MAAM,iBAAiB,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;QACtE,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAEhE,MAAM,cAAc,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;QAEnC,MAAM,uBAAuB,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAElD,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/analyze-action-post.js b/lib/analyze-action-post.js index f641d211e..38f6c20f9 100644 --- a/lib/analyze-action-post.js +++ b/lib/analyze-action-post.js @@ -25,26 +25,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); * other `post:` hooks. */ const core = __importStar(require("@actions/core")); -const actionsUtil = __importStar(require("./actions-util")); -const config_utils_1 = require("./config-utils"); +const analyzeActionPostHelper = __importStar(require("./analyze-action-post-helper")); const debugArtifacts = __importStar(require("./debug-artifacts")); -const logging_1 = require("./logging"); -async function run(uploadSarifDebugArtifact) { - const logger = (0, logging_1.getActionsLogger)(); - const config = await (0, config_utils_1.getConfig)(actionsUtil.getTemporaryDirectory(), logger); - if (config === undefined) { - throw new Error("Config file could not be found at expected location. Did the 'init' action fail to start?"); - } - // Upload Actions SARIF artifacts for debugging - if (config === null || config === void 0 ? void 0 : config.debugMode) { - core.info("Debug mode is on. Uploading available SARIF files as Actions debugging artifact..."); - const outputDir = actionsUtil.getRequiredInput("output"); - await uploadSarifDebugArtifact(config, outputDir); - } -} async function runWrapper() { try { - await run(debugArtifacts.uploadSarifDebugArtifact); + await analyzeActionPostHelper.run(debugArtifacts.uploadSarifDebugArtifact); } catch (error) { core.setFailed(`analyze post-action step failed: ${error}`); diff --git a/lib/analyze-action-post.js.map b/lib/analyze-action-post.js.map index c13e643aa..664b0d9cf 100644 --- a/lib/analyze-action-post.js.map +++ b/lib/analyze-action-post.js.map @@ -1 +1 @@ -{"version":3,"file":"analyze-action-post.js","sourceRoot":"","sources":["../src/analyze-action-post.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,oDAAsC;AAEtC,4DAA8C;AAC9C,iDAA2C;AAC3C,kEAAoD;AACpD,uCAA6C;AAE7C,KAAK,UAAU,GAAG,CAAC,wBAAkC;IACnD,MAAM,MAAM,GAAG,IAAA,0BAAgB,GAAE,CAAC;IAElC,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAS,EAAC,WAAW,CAAC,qBAAqB,EAAE,EAAE,MAAM,CAAC,CAAC;IAC5E,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;KACH;IAED,+CAA+C;IAC/C,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,EAAE;QACrB,IAAI,CAAC,IAAI,CACP,oFAAoF,CACrF,CAAC;QACF,MAAM,SAAS,GAAG,WAAW,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACzD,MAAM,wBAAwB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;KACnD;AACH,CAAC;AAED,KAAK,UAAU,UAAU;IACvB,IAAI;QACF,MAAM,GAAG,CAAC,cAAc,CAAC,wBAAwB,CAAC,CAAC;KACpD;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,SAAS,CAAC,oCAAoC,KAAK,EAAE,CAAC,CAAC;QAC5D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;KACpB;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"} \ No newline at end of file +{"version":3,"file":"analyze-action-post.js","sourceRoot":"","sources":["../src/analyze-action-post.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,oDAAsC;AAEtC,sFAAwE;AACxE,kEAAoD;AAEpD,KAAK,UAAU,UAAU;IACvB,IAAI;QACF,MAAM,uBAAuB,CAAC,GAAG,CAAC,cAAc,CAAC,wBAAwB,CAAC,CAAC;KAC5E;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,SAAS,CAAC,oCAAoC,KAAK,EAAE,CAAC,CAAC;QAC5D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;KACpB;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"} \ No newline at end of file diff --git a/lib/init-action-post-helper.js b/lib/init-action-post-helper.js new file mode 100644 index 000000000..1d683e0db --- /dev/null +++ b/lib/init-action-post-helper.js @@ -0,0 +1,43 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.run = void 0; +// REVIEW: What do you think about the name of this file? +const core = __importStar(require("@actions/core")); +const actionsUtil = __importStar(require("./actions-util")); +const config_utils_1 = require("./config-utils"); +const logging_1 = require("./logging"); +async function run(uploadDatabaseBundleDebugArtifact, uploadLogsDebugArtifact, printDebugLogs) { + const logger = (0, logging_1.getActionsLogger)(); + const config = await (0, config_utils_1.getConfig)(actionsUtil.getTemporaryDirectory(), logger); + if (config === undefined) { + throw new Error("Config file could not be found at expected location. Did the 'init' action fail to start?"); + } + // Upload appropriate Actions artifacts for debugging + if (config === null || config === void 0 ? void 0 : config.debugMode) { + core.info("Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts..."); + await uploadDatabaseBundleDebugArtifact(config, logger); + await uploadLogsDebugArtifact(config); + await printDebugLogs(config); + } +} +exports.run = run; +//# sourceMappingURL=init-action-post-helper.js.map \ No newline at end of file diff --git a/lib/init-action-post-helper.js.map b/lib/init-action-post-helper.js.map new file mode 100644 index 000000000..f054a3741 --- /dev/null +++ b/lib/init-action-post-helper.js.map @@ -0,0 +1 @@ +{"version":3,"file":"init-action-post-helper.js","sourceRoot":"","sources":["../src/init-action-post-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAyD;AACzD,oDAAsC;AAEtC,4DAA8C;AAC9C,iDAA2C;AAC3C,uCAA6C;AAEtC,KAAK,UAAU,GAAG,CACvB,iCAA2C,EAC3C,uBAAiC,EACjC,cAAwB;IAExB,MAAM,MAAM,GAAG,IAAA,0BAAgB,GAAE,CAAC;IAElC,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAS,EAAC,WAAW,CAAC,qBAAqB,EAAE,EAAE,MAAM,CAAC,CAAC;IAC5E,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;KACH;IAED,qDAAqD;IACrD,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,EAAE;QACrB,IAAI,CAAC,IAAI,CACP,mGAAmG,CACpG,CAAC;QACF,MAAM,iCAAiC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxD,MAAM,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAEtC,MAAM,cAAc,CAAC,MAAM,CAAC,CAAC;KAC9B;AACH,CAAC;AAxBD,kBAwBC"} \ No newline at end of file diff --git a/lib/init-action-post-helper.test.js b/lib/init-action-post-helper.test.js new file mode 100644 index 000000000..a3153ac04 --- /dev/null +++ b/lib/init-action-post-helper.test.js @@ -0,0 +1,74 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const ava_1 = __importDefault(require("ava")); +const sinon = __importStar(require("sinon")); +const configUtils = __importStar(require("./config-utils")); +const initActionPostHelper = __importStar(require("./init-action-post-helper")); +const testing_utils_1 = require("./testing-utils"); +const util = __importStar(require("./util")); +(0, testing_utils_1.setupTests)(ava_1.default); +(0, ava_1.default)("post: init action with debug mode off", async (t) => { + return await util.withTmpDir(async (tmpDir) => { + process.env["RUNNER_TEMP"] = tmpDir; + const gitHubVersion = { + type: util.GitHubVariant.DOTCOM, + }; + sinon.stub(configUtils, "getConfig").resolves({ + debugMode: false, + gitHubVersion, + languages: [], + packs: [], + }); + const uploadDatabaseBundleSpy = sinon.spy(); + const uploadLogsSpy = sinon.spy(); + const printDebugLogsSpy = sinon.spy(); + await initActionPostHelper.run(uploadDatabaseBundleSpy, uploadLogsSpy, printDebugLogsSpy); + t.assert(uploadDatabaseBundleSpy.notCalled); + t.assert(uploadLogsSpy.notCalled); + t.assert(printDebugLogsSpy.notCalled); + }); +}); +(0, ava_1.default)("post: init action with debug mode on", async (t) => { + return await util.withTmpDir(async (tmpDir) => { + process.env["RUNNER_TEMP"] = tmpDir; + const gitHubVersion = { + type: util.GitHubVariant.DOTCOM, + }; + sinon.stub(configUtils, "getConfig").resolves({ + debugMode: true, + gitHubVersion, + languages: [], + packs: [], + }); + const uploadDatabaseBundleSpy = sinon.spy(); + const uploadLogsSpy = sinon.spy(); + const printDebugLogsSpy = sinon.spy(); + await initActionPostHelper.run(uploadDatabaseBundleSpy, uploadLogsSpy, printDebugLogsSpy); + t.assert(uploadDatabaseBundleSpy.called); + t.assert(uploadLogsSpy.called); + t.assert(printDebugLogsSpy.called); + }); +}); +//# sourceMappingURL=init-action-post-helper.test.js.map \ No newline at end of file diff --git a/lib/init-action-post-helper.test.js.map b/lib/init-action-post-helper.test.js.map new file mode 100644 index 000000000..d05a91e14 --- /dev/null +++ b/lib/init-action-post-helper.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"init-action-post-helper.test.js","sourceRoot":"","sources":["../src/init-action-post-helper.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAuB;AACvB,6CAA+B;AAE/B,4DAA8C;AAC9C,gFAAkE;AAClE,mDAA6C;AAC7C,6CAA+B;AAE/B,IAAA,0BAAU,EAAC,aAAI,CAAC,CAAC;AAEjB,IAAA,aAAI,EAAC,uCAAuC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IACxD,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC5C,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC;QAEpC,MAAM,aAAa,GAAuB;YACxC,IAAI,EAAE,IA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M,aAAa,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;QAClC,MAAM,iBAAiB,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;QAEtC,MAAM,oBAAoB,CAAC,GAAG,CAC5B,uBAAuB,EACvB,aAAa,EACb,iBAAiB,CAClB,CAAC;QAEF,CAAC,CAAC,MAAM,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;QACzC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC/B,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/init-action-post.js b/lib/init-action-post.js index ae433afe1..e3be6aed6 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -26,26 +26,11 @@ var __importStar = (this && this.__importStar) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(require("@actions/core")); const actionsUtil = __importStar(require("./actions-util")); -const config_utils_1 = require("./config-utils"); const debugArtifacts = __importStar(require("./debug-artifacts")); -const logging_1 = require("./logging"); -async function run(uploadDatabaseBundleDebugArtifact, uploadLogsDebugArtifact, printDebugLogs) { - const logger = (0, logging_1.getActionsLogger)(); - const config = await (0, config_utils_1.getConfig)(actionsUtil.getTemporaryDirectory(), logger); - if (config === undefined) { - throw new Error("Config file could not be found at expected location. Did the 'init' action fail to start?"); - } - // Upload appropriate Actions artifacts for debugging - if (config === null || config === void 0 ? void 0 : config.debugMode) { - core.info("Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts..."); - await uploadDatabaseBundleDebugArtifact(config, logger); - await uploadLogsDebugArtifact(config); - await printDebugLogs(config); - } -} +const initActionPostHelper = __importStar(require("./init-action-post-helper")); async function runWrapper() { try { - await run(debugArtifacts.uploadDatabaseBundleDebugArtifact, debugArtifacts.uploadLogsDebugArtifact, actionsUtil.printDebugLogs); + await initActionPostHelper.run(debugArtifacts.uploadDatabaseBundleDebugArtifact, debugArtifacts.uploadLogsDebugArtifact, actionsUtil.printDebugLogs); } catch (error) { core.setFailed(`init post-action step failed: ${error}`); diff --git a/lib/init-action-post.js.map b/lib/init-action-post.js.map index 5c9e74cbe..75e07552e 100644 --- a/lib/init-action-post.js.map +++ b/lib/init-action-post.js.map @@ -1 +1 @@ -{"version":3,"file":"init-action-post.js","sourceRoot":"","sources":["../src/init-action-post.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;AAEH,oDAAsC;AAEtC,4DAA8C;AAC9C,iDAA2C;AAC3C,kEAAoD;AACpD,uCAA6C;AAE7C,KAAK,UAAU,GAAG,CAChB,iCAA2C,EAC3C,uBAAiC,EACjC,cAAwB;IAExB,MAAM,MAAM,GAAG,IAAA,0BAAgB,GAAE,CAAC;IAElC,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAS,EAAC,WAAW,CAAC,qBAAqB,EAAE,EAAE,MAAM,CAAC,CAAC;IAC5E,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;KACH;IAED,qDAAqD;IACrD,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,EAAE;QACrB,IAAI,CAAC,IAAI,CACP,mGAAmG,CACpG,CAAC;QACF,MAAM,iCAAiC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxD,MAAM,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAEtC,MAAM,cAAc,CAAC,MAAM,CAAC,CAAC;KAC9B;AACH,CAAC;AAED,KAAK,UAAU,UAAU;IACvB,IAAI;QACF,MAAM,GAAG,CACP,cAAc,CAAC,iCAAiC,EAChD,cAAc,CAAC,uBAAuB,EACtC,WAAW,CAAC,cAAc,CAC3B,CAAC;KACH;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,SAAS,CAAC,iCAAiC,KAAK,EAAE,CAAC,CAAC;QACzD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;KACpB;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"} \ No newline at end of file +{"version":3,"file":"init-action-post.js","sourceRoot":"","sources":["../src/init-action-post.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;AAEH,oDAAsC;AAEtC,4DAA8C;AAC9C,kEAAoD;AACpD,gFAAkE;AAElE,KAAK,UAAU,UAAU;IACvB,IAAI;QACF,MAAM,oBAAoB,CAAC,GAAG,CAC5B,cAAc,CAAC,iCAAiC,EAChD,cAAc,CAAC,uBAAuB,EACtC,WAAW,CAAC,cAAc,CAC3B,CAAC;KACH;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,SAAS,CAAC,iCAAiC,KAAK,EAAE,CAAC,CAAC;QACzD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;KACpB;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"} \ No newline at end of file diff --git a/src/analyze-action-post-helper.test.ts b/src/analyze-action-post-helper.test.ts new file mode 100644 index 000000000..628b2b6f7 --- /dev/null +++ b/src/analyze-action-post-helper.test.ts @@ -0,0 +1,57 @@ +import test from "ava"; +import * as sinon from "sinon"; + +import * as actionsUtil from "./actions-util"; +import * as analyzeActionPostHelper from "./analyze-action-post-helper"; +import * as configUtils from "./config-utils"; +import { setupTests } from "./testing-utils"; +import * as util from "./util"; + +setupTests(test); + +test("post: analyze action with debug mode off", async (t) => { + return await util.withTmpDir(async (tmpDir) => { + process.env["RUNNER_TEMP"] = tmpDir; + + const gitHubVersion: util.GitHubVersion = { + type: util.GitHubVariant.DOTCOM, + }; + sinon.stub(configUtils, "getConfig").resolves({ + debugMode: false, + gitHubVersion, + languages: [], + packs: [], + } as unknown as configUtils.Config); + + const uploadSarifSpy = sinon.spy(); + + await analyzeActionPostHelper.run(uploadSarifSpy); + + t.assert(uploadSarifSpy.notCalled); + }); +}); + +test("post: analyze action with debug mode on", async (t) => { + return await util.withTmpDir(async (tmpDir) => { + process.env["RUNNER_TEMP"] = tmpDir; + + const gitHubVersion: util.GitHubVersion = { + type: util.GitHubVariant.DOTCOM, + }; + sinon.stub(configUtils, "getConfig").resolves({ + debugMode: true, + gitHubVersion, + languages: [], + packs: [], + } as unknown as configUtils.Config); + + const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput"); + requiredInputStub.withArgs("output").returns("fake-output-dir"); + + const uploadSarifSpy = sinon.spy(); + + await analyzeActionPostHelper.run(uploadSarifSpy); + + t.assert(uploadSarifSpy.called); + }); +}); diff --git a/src/analyze-action-post-helper.ts b/src/analyze-action-post-helper.ts new file mode 100644 index 000000000..236d0b8c1 --- /dev/null +++ b/src/analyze-action-post-helper.ts @@ -0,0 +1,26 @@ +// REVIEW: What do you think about the name of this file? +import * as core from "@actions/core"; + +import * as actionsUtil from "./actions-util"; +import { getConfig } from "./config-utils"; +import { getActionsLogger } from "./logging"; + +export async function run(uploadSarifDebugArtifact: Function) { + const logger = getActionsLogger(); + + const config = await getConfig(actionsUtil.getTemporaryDirectory(), logger); + if (config === undefined) { + throw new Error( + "Config file could not be found at expected location. Did the 'init' action fail to start?" + ); + } + + // Upload Actions SARIF artifacts for debugging + if (config?.debugMode) { + core.info( + "Debug mode is on. Uploading available SARIF files as Actions debugging artifact..." + ); + const outputDir = actionsUtil.getRequiredInput("output"); + await uploadSarifDebugArtifact(config, outputDir); + } +} diff --git a/src/analyze-action-post.test.ts b/src/analyze-action-post.test.ts deleted file mode 100644 index 3beb22093..000000000 --- a/src/analyze-action-post.test.ts +++ /dev/null @@ -1 +0,0 @@ -// TODO(angelapwen): Test run() here diff --git a/src/analyze-action-post.ts b/src/analyze-action-post.ts index 6e29405fa..66e2f58c9 100644 --- a/src/analyze-action-post.ts +++ b/src/analyze-action-post.ts @@ -5,34 +5,12 @@ */ import * as core from "@actions/core"; -import * as actionsUtil from "./actions-util"; -import { getConfig } from "./config-utils"; +import * as analyzeActionPostHelper from "./analyze-action-post-helper"; import * as debugArtifacts from "./debug-artifacts"; -import { getActionsLogger } from "./logging"; - -async function run(uploadSarifDebugArtifact: Function) { - const logger = getActionsLogger(); - - const config = await getConfig(actionsUtil.getTemporaryDirectory(), logger); - if (config === undefined) { - throw new Error( - "Config file could not be found at expected location. Did the 'init' action fail to start?" - ); - } - - // Upload Actions SARIF artifacts for debugging - if (config?.debugMode) { - core.info( - "Debug mode is on. Uploading available SARIF files as Actions debugging artifact..." - ); - const outputDir = actionsUtil.getRequiredInput("output"); - await uploadSarifDebugArtifact(config, outputDir); - } -} async function runWrapper() { try { - await run(debugArtifacts.uploadSarifDebugArtifact); + await analyzeActionPostHelper.run(debugArtifacts.uploadSarifDebugArtifact); } catch (error) { core.setFailed(`analyze post-action step failed: ${error}`); console.log(error); diff --git a/src/init-action-post-helper.test.ts b/src/init-action-post-helper.test.ts new file mode 100644 index 000000000..e24ee5064 --- /dev/null +++ b/src/init-action-post-helper.test.ts @@ -0,0 +1,69 @@ +import test from "ava"; +import * as sinon from "sinon"; + +import * as configUtils from "./config-utils"; +import * as initActionPostHelper from "./init-action-post-helper"; +import { setupTests } from "./testing-utils"; +import * as util from "./util"; + +setupTests(test); + +test("post: init action with debug mode off", async (t) => { + return await util.withTmpDir(async (tmpDir) => { + process.env["RUNNER_TEMP"] = tmpDir; + + const gitHubVersion: util.GitHubVersion = { + type: util.GitHubVariant.DOTCOM, + }; + sinon.stub(configUtils, "getConfig").resolves({ + debugMode: false, + gitHubVersion, + languages: [], + packs: [], + } as unknown as configUtils.Config); + + const uploadDatabaseBundleSpy = sinon.spy(); + const uploadLogsSpy = sinon.spy(); + const printDebugLogsSpy = sinon.spy(); + + await initActionPostHelper.run( + uploadDatabaseBundleSpy, + uploadLogsSpy, + printDebugLogsSpy + ); + + t.assert(uploadDatabaseBundleSpy.notCalled); + t.assert(uploadLogsSpy.notCalled); + t.assert(printDebugLogsSpy.notCalled); + }); +}); + +test("post: init action with debug mode on", async (t) => { + return await util.withTmpDir(async (tmpDir) => { + process.env["RUNNER_TEMP"] = tmpDir; + + const gitHubVersion: util.GitHubVersion = { + type: util.GitHubVariant.DOTCOM, + }; + sinon.stub(configUtils, "getConfig").resolves({ + debugMode: true, + gitHubVersion, + languages: [], + packs: [], + } as unknown as configUtils.Config); + + const uploadDatabaseBundleSpy = sinon.spy(); + const uploadLogsSpy = sinon.spy(); + const printDebugLogsSpy = sinon.spy(); + + await initActionPostHelper.run( + uploadDatabaseBundleSpy, + uploadLogsSpy, + printDebugLogsSpy + ); + + t.assert(uploadDatabaseBundleSpy.called); + t.assert(uploadLogsSpy.called); + t.assert(printDebugLogsSpy.called); + }); +}); diff --git a/src/init-action-post-helper.ts b/src/init-action-post-helper.ts new file mode 100644 index 000000000..882587ddf --- /dev/null +++ b/src/init-action-post-helper.ts @@ -0,0 +1,32 @@ +// REVIEW: What do you think about the name of this file? +import * as core from "@actions/core"; + +import * as actionsUtil from "./actions-util"; +import { getConfig } from "./config-utils"; +import { getActionsLogger } from "./logging"; + +export async function run( + uploadDatabaseBundleDebugArtifact: Function, + uploadLogsDebugArtifact: Function, + printDebugLogs: Function +) { + const logger = getActionsLogger(); + + const config = await getConfig(actionsUtil.getTemporaryDirectory(), logger); + if (config === undefined) { + throw new Error( + "Config file could not be found at expected location. Did the 'init' action fail to start?" + ); + } + + // Upload appropriate Actions artifacts for debugging + if (config?.debugMode) { + core.info( + "Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts..." + ); + await uploadDatabaseBundleDebugArtifact(config, logger); + await uploadLogsDebugArtifact(config); + + await printDebugLogs(config); + } +} diff --git a/src/init-action-post.test.ts b/src/init-action-post.test.ts deleted file mode 100644 index 9720b146c..000000000 --- a/src/init-action-post.test.ts +++ /dev/null @@ -1 +0,0 @@ -// TODO(angelapwen): Test run() here. diff --git a/src/init-action-post.ts b/src/init-action-post.ts index 3a80745f0..75c4f3a82 100644 --- a/src/init-action-post.ts +++ b/src/init-action-post.ts @@ -7,39 +7,12 @@ import * as core from "@actions/core"; import * as actionsUtil from "./actions-util"; -import { getConfig } from "./config-utils"; import * as debugArtifacts from "./debug-artifacts"; -import { getActionsLogger } from "./logging"; - -async function run( - uploadDatabaseBundleDebugArtifact: Function, - uploadLogsDebugArtifact: Function, - printDebugLogs: Function -) { - const logger = getActionsLogger(); - - const config = await getConfig(actionsUtil.getTemporaryDirectory(), logger); - if (config === undefined) { - throw new Error( - "Config file could not be found at expected location. Did the 'init' action fail to start?" - ); - } - - // Upload appropriate Actions artifacts for debugging - if (config?.debugMode) { - core.info( - "Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts..." - ); - await uploadDatabaseBundleDebugArtifact(config, logger); - await uploadLogsDebugArtifact(config); - - await printDebugLogs(config); - } -} +import * as initActionPostHelper from "./init-action-post-helper"; async function runWrapper() { try { - await run( + await initActionPostHelper.run( debugArtifacts.uploadDatabaseBundleDebugArtifact, debugArtifacts.uploadLogsDebugArtifact, actionsUtil.printDebugLogs