From b9369597547b8beade3bb4e25c0ac3034e688d12 Mon Sep 17 00:00:00 2001 From: David Knise Date: Tue, 31 Oct 2023 12:08:34 -0700 Subject: [PATCH] v1.10.1 - export-file option (#25) * v1.10.0 - export-file option * v1.10.1 * v1.10.1 - fix sarif file export --- package-lock.json | 4 ++-- package.json | 2 +- src/msdo-client.ts | 10 +++++++++- src/msdo-common.ts | 37 +++++++++++++++++++++++++++++++++++++ src/msdo-installer.ts | 1 + 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 91c2ff1..940b046 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@microsoft/security-devops-azdevops-task-lib", - "version": "1.9.0", + "version": "1.10.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@microsoft/security-devops-azdevops-task-lib", - "version": "1.9.0", + "version": "1.10.1", "license": "MIT", "dependencies": { "adm-zip": "0.5.10", diff --git a/package.json b/package.json index fe27419..bdec19b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@microsoft/security-devops-azdevops-task-lib", - "version": "1.9.0", + "version": "1.10.1", "description": "Microsoft Security DevOps for Azure DevOps task library.", "author": "Microsoft Corporation", "license": "MIT", diff --git a/src/msdo-client.ts b/src/msdo-client.ts index 0f6ca36..70ff5b2 100644 --- a/src/msdo-client.ts +++ b/src/msdo-client.ts @@ -127,7 +127,15 @@ export async function run(inputArgs: string[], successfulExitCodes: number[] = n // Write it as an environment variable for follow up tasks to consume tl.setVariable('MSDO_SARIF_FILE', sarifFile); - tool.arg('--export-breaking-results-to-file'); + if (common.isVersionGreaterThanOrEqualTo(process.env.MSDO_INSTALLEDVERSION, '0.183.0')) { + // Export all SARIF results to a file + tool.arg('--export-file'); + } else { + // This still exists, but the behavior was corrected in 0.183.0 + // This defaults to only exporting breaking results, as the name implies + tool.arg('--export-breaking-results-to-file'); + } + tool.arg(sarifFile); tool.arg('--telemetry-environment'); diff --git a/src/msdo-common.ts b/src/msdo-common.ts index 25d7ed2..d84321e 100644 --- a/src/msdo-common.ts +++ b/src/msdo-common.ts @@ -143,4 +143,41 @@ export function getMsdoBreakEnvironmentVariable() : boolean { */ export function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); +} + +/** + * Lazy checks if the version1 is greater than or equal to version2. + * + * @param version1 The version to check. + * @param version2 The version to compare against. + * @returns True if the version is greater than or equal to version2, or true in any error condition. + */ +export function isVersionGreaterThanOrEqualTo(version1: string, version2: string): boolean { + if (version1 == null || version2 == null) { + return true; + } + + let version1Parts = version1.split('.'); + let version2Parts = version2.split('.'); + + if (version1Parts == null || version2Parts == null) { + return true; + } + + let version1Part = 0; + let version2Part = 0; + + for (let i = 0; i < version1Parts.length; i++) { + version1Part = parseInt(version1Parts[i] || '0'); + version2Part = parseInt(version2Parts[i] || '0'); + + if (version1Part > version2Part) { + return true; + } + else if (version1Part < version2Part) { + return false; + } + } + + return true; } \ No newline at end of file diff --git a/src/msdo-installer.ts b/src/msdo-installer.ts index ab52cb4..79a66b2 100644 --- a/src/msdo-installer.ts +++ b/src/msdo-installer.ts @@ -167,6 +167,7 @@ function setVariables( process.env.MSDO_DIRECTORY = msdoDirectory; process.env.MSDO_FILEPATH = msdoFilePath; + process.env.MSDO_INSTALLEDVERSION = cliVersion; let exists = fs.existsSync(process.env.MSDO_FILEPATH);