From 97dfeb95055845d654d9b18ba2af3331b557c174 Mon Sep 17 00:00:00 2001 From: MarkAckert Date: Thu, 1 Feb 2024 09:53:35 -0500 Subject: [PATCH] add log level and publish logs Signed-off-by: MarkAckert --- .github/workflows/license-generation.yml | 15 +++++++++++++++ .../src/actions/ort/OrtReportAction.ts | 1 + .../src/actions/ort/OrtSbomAction.ts | 1 + .../src/actions/ort/OrtScanAction.ts | 1 + .../dependency-scan/src/constants/Constants.ts | 2 ++ licenses/dependency-scan/src/utils/Utilities.ts | 17 +++++++++++++++++ 6 files changed, 37 insertions(+) diff --git a/.github/workflows/license-generation.yml b/.github/workflows/license-generation.yml index 3bf7fe3f..cc4aac20 100644 --- a/.github/workflows/license-generation.yml +++ b/.github/workflows/license-generation.yml @@ -40,6 +40,16 @@ on: options: - 'true' - 'false' + ort_log_level: + description: Set ORT's Log Level. Defaults to 'warn' + required: false + type: choice + default: 'warn' + options: + - 'warn' + - 'info' + - 'error' + - 'debug' env: PUBLISH_RELEASE: ${{ github.event.inputs.publish_release }} @@ -96,8 +106,10 @@ jobs: - uses: actions/setup-node@v2 with: node-version: '20' + - name: 'Install Ansible' uses: zowe-actions/shared-actions/prepare-workflow@main + - name: '[Zowe Actions] Prepare workflow' uses: zowe-actions/shared-actions/prepare-workflow@main @@ -167,6 +179,8 @@ jobs: cp build/sbom_reports/${{ env.CLI_SBOM_ARTIFACT_NAME }} ${{ env.CLI_SBOM_ARTIFACT_NAME }} cp build/sbom_reports/${{ env.ZOS_SBOM_ARTIFACT_NAME }} ${{ env.ZOS_SBOM_ARTIFACT_NAME }} + zip -rj logs.zip build/logs/* + - name: Remove existing artifacts id: cleanup if: ${{ github.event.inputs.publish_release }} && ${{ github.event.inputs.overwrite_release }} @@ -229,6 +243,7 @@ jobs: uses: actions/upload-artifact@v3 with: path: | + ${{ env.DEPENDENCY_SCAN_HOME }}/logs.zip ${{ env.DEPENDENCY_SCAN_HOME }}/${{ env.AGG_ARTIFACT_NAME }} ${{ env.DEPENDENCY_SCAN_HOME }}/${{ env.AGG_ARTIFACT_NAME }}.bundle ${{ env.DEPENDENCY_SCAN_HOME }}/${{ env.CLI_ARTIFACT_NAME }} diff --git a/licenses/dependency-scan/src/actions/ort/OrtReportAction.ts b/licenses/dependency-scan/src/actions/ort/OrtReportAction.ts index 9a7d290a..2343b50e 100644 --- a/licenses/dependency-scan/src/actions/ort/OrtReportAction.ts +++ b/licenses/dependency-scan/src/actions/ort/OrtReportAction.ts @@ -215,6 +215,7 @@ export class OrtReportAction implements IAction { console.log("Running ORT License and Notice report on " + resolvedDir); const reportProcess = spawn("ort", ["report", "-i", resolvedDir + "/analyzer-result.json", "-o", Constants.LICENSE_REPORTS_DIR + path.sep + path.basename(projectPath), + Constants.ORT_DEBUG_LEVEL, "-f", "PlainTextTemplate", "-O", "PlainTextTemplate=template.id=NOTICE_DEFAULT", // generates notices "-O", `PlainTextTemplate=template.path=${Constants.SOURCE_RESOURCES_DIR}/../resources/tpsr-full-template.md.ftl` //generates tpsr section diff --git a/licenses/dependency-scan/src/actions/ort/OrtSbomAction.ts b/licenses/dependency-scan/src/actions/ort/OrtSbomAction.ts index 65c7b142..6d0d0d17 100644 --- a/licenses/dependency-scan/src/actions/ort/OrtSbomAction.ts +++ b/licenses/dependency-scan/src/actions/ort/OrtSbomAction.ts @@ -103,6 +103,7 @@ export class OrtSbomAction implements IAction { console.log("Running ORT SBOM generation for " + resolvedDir); const reportProcess = spawn("ort", ["report", "-i", resolvedDir + "/analyzer-result.json", "-o", Constants.SBOM_REPORTS_DIR + path.sep + path.basename(projectPath), + Constants.ORT_DEBUG_LEVEL, "-O", `SpdxDocument=document.name=${path.basename(projectPath)}`, "-f", "SpdxDocument" ], { diff --git a/licenses/dependency-scan/src/actions/ort/OrtScanAction.ts b/licenses/dependency-scan/src/actions/ort/OrtScanAction.ts index 38f1edae..a2fc81e4 100644 --- a/licenses/dependency-scan/src/actions/ort/OrtScanAction.ts +++ b/licenses/dependency-scan/src/actions/ort/OrtScanAction.ts @@ -65,6 +65,7 @@ export class OrtScanAction implements IAction { projectDir, "-o", projectDir, + Constants.ORT_DEBUG_LEVEL, "-f", "JSON"], { cwd: process.env.cwd, diff --git a/licenses/dependency-scan/src/constants/Constants.ts b/licenses/dependency-scan/src/constants/Constants.ts index c9a4e582..de92f74c 100644 --- a/licenses/dependency-scan/src/constants/Constants.ts +++ b/licenses/dependency-scan/src/constants/Constants.ts @@ -88,4 +88,6 @@ export class Constants { public static readonly SCAN_AGGREGATE: boolean = Utilities.getEnv("ZOWE_SCAN_AGGREGATE", true); public static readonly SKIP_INSTALL_SPECIFIC: string = Utilities.getEnvStr("SKIP_INSTALL_SPECIFIC", "") + + public static readonly ORT_DEBUG_LEVEL: string = Utilities.getOrtDebug("ORT_DEBUG_LEVEL", "--warn"); } diff --git a/licenses/dependency-scan/src/utils/Utilities.ts b/licenses/dependency-scan/src/utils/Utilities.ts index 8b69bfc3..6dd74a3b 100644 --- a/licenses/dependency-scan/src/utils/Utilities.ts +++ b/licenses/dependency-scan/src/utils/Utilities.ts @@ -11,10 +11,27 @@ import * as fs from "fs"; import * as path from "path"; +import { env } from "process"; import { isNullOrUndefined } from "util"; export class Utilities { + public static getOrtDebug(envVar: string, defaultLevel: string): string { + const envValue = Utilities.getEnvStr(envVar, defaultLevel); + switch(envValue.toLowerCase()) { + case "info": + return "--info"; + case "warn": + return "--warn"; + case "debug": + return "--debug"; + case "error": + return "--error"; + default: + throw new Error(`Ort debug level set by ${envVar} must be one of 'info', 'debug', 'error', or 'warn'. Defaults to 'warn'` ); + } + } + public static getEnvStr(envVar: string, defaultValue: string = ""): string { if (!isNullOrUndefined(process.argv) && process.argv.includes(envVar)) { const argIndex = process.argv.indexOf(envVar);