From 9fe0f98bd45b19e6e931d457f4e98f8f84461fb5 Mon Sep 17 00:00:00 2001 From: Eyal Delarea Date: Thu, 5 Sep 2024 11:25:59 +0300 Subject: [PATCH] Upgrade Default CLI version (#208) --- README.md | 4 ++++ action.yml | 2 +- lib/cleanup.js | 3 +++ lib/utils.js | 4 ++-- node_modules/.package-lock.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/cleanup.ts | 2 ++ src/utils.ts | 15 ++++++++++----- test/main.spec.ts | 33 ++++++++++++++++++++++++++++++++- 10 files changed, 58 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 899a61671..b78b15571 100644 --- a/README.md +++ b/README.md @@ -350,6 +350,10 @@ To read more about the JFrog CLI supported commands, visit the following link: [JFrog CLI Command Summaries Documentation](https://docs.jfrog-applications.jfrog.io/jfrog-applications/jfrog-cli/cli-command-summaries). ## Code Scanning Alerts + +**Note:** To use code scanning alerts, ensure you are using JFrog CLI version `v2.67.0` or above. + + The action also supports the display of code scanning alerts in the GitHub Actions UI. Code scanning alerts are generated following the execution of the `jf docker scan` and `jf scan` commands. diff --git a/action.yml b/action.yml index 8a8d7c409..eab8b4f86 100644 --- a/action.yml +++ b/action.yml @@ -4,7 +4,7 @@ author: "JFrog" inputs: version: description: "JFrog CLI Version" - default: "2.66.0" + default: "2.67.0" required: false download-repository: description: "Remote repository in Artifactory pointing to 'https://releases.jfrog.io/artifactory/jfrog-cli'. Use this parameter in case you don't have an Internet access." diff --git a/lib/cleanup.js b/lib/cleanup.js index 0f6c25147..43f009beb 100644 --- a/lib/cleanup.js +++ b/lib/cleanup.js @@ -141,6 +141,9 @@ function collectAndPublishBuildInfoIfNeeded() { core.startGroup('Publish the build info to JFrog Artifactory'); yield utils_1.Utils.runCli(['rt', 'build-publish'], { cwd: workingDirectory }); } + catch (error) { + core.warning('Failed while attempting to publish the build info to JFrog Artifactory: ' + error); + } finally { core.endGroup(); } diff --git a/lib/utils.js b/lib/utils.js index f2b0bc629..9cecf8908 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -489,7 +489,7 @@ class Utils { } static isJobSummarySupported() { const version = core.getInput(Utils.CLI_VERSION_ARG); - return version === Utils.LATEST_CLI_VERSION || (0, semver_1.gt)(version, Utils.MIN_CLI_VERSION_JOB_SUMMARY); + return version === Utils.LATEST_CLI_VERSION || (0, semver_1.gte)(version, Utils.MIN_CLI_VERSION_JOB_SUMMARY); } /** * Generates GitHub workflow unified Summary report. @@ -603,7 +603,7 @@ class Utils { const finalSarifFile = path.join(Utils.getJobOutputDirectoryPath(), this.SECURITY_DIR_NAME, this.SARIF_REPORTS_DIR_NAME, this.CODE_SCANNING_FINAL_SARIF_FILE); if (!(0, fs_1.existsSync)(finalSarifFile)) { console.debug('No code scanning sarif file was found.'); - return ""; + return ''; } // Read the SARIF file, compress and encode it to match the code-scanning/sarif API requirements. const sarif = yield fs_1.promises.readFile(finalSarifFile, 'utf-8'); diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 679c49b1f..88491b181 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -1,6 +1,6 @@ { "name": "@jfrog/setup-jfrog-cli", - "version": "4.4.0", + "version": "4.4.1", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/package-lock.json b/package-lock.json index 349372f0f..ef41fa397 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@jfrog/setup-jfrog-cli", - "version": "4.4.0", + "version": "4.4.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@jfrog/setup-jfrog-cli", - "version": "4.4.0", + "version": "4.4.1", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index 0d4e57a7c..752772d91 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jfrog/setup-jfrog-cli", - "version": "4.4.0", + "version": "4.4.1", "private": true, "description": "Setup JFrog CLI in GitHub Actions", "main": "lib/main.js", diff --git a/src/cleanup.ts b/src/cleanup.ts index 83ca4d918..5fcfedbbb 100644 --- a/src/cleanup.ts +++ b/src/cleanup.ts @@ -107,6 +107,8 @@ async function collectAndPublishBuildInfoIfNeeded() { try { core.startGroup('Publish the build info to JFrog Artifactory'); await Utils.runCli(['rt', 'build-publish'], { cwd: workingDirectory }); + } catch (error) { + core.warning('Failed while attempting to publish the build info to JFrog Artifactory: ' + error); } finally { core.endGroup(); } diff --git a/src/utils.ts b/src/utils.ts index d730857c7..a6adbe2e9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -7,7 +7,7 @@ import { OutgoingHttpHeaders } from 'http'; import { arch, platform, tmpdir } from 'os'; import * as path from 'path'; import { join } from 'path'; -import { gt, lt } from 'semver'; +import { gte, lt } from 'semver'; import { Octokit } from '@octokit/core'; import { OctokitResponse } from '@octokit/types/dist-types/OctokitResponse'; import * as github from '@actions/github'; @@ -547,7 +547,7 @@ export class Utils { public static isJobSummarySupported(): boolean { const version: string = core.getInput(Utils.CLI_VERSION_ARG); - return version === Utils.LATEST_CLI_VERSION || gt(version, Utils.MIN_CLI_VERSION_JOB_SUMMARY); + return version === Utils.LATEST_CLI_VERSION || gte(version, Utils.MIN_CLI_VERSION_JOB_SUMMARY); } /** @@ -654,15 +654,20 @@ export class Utils { * @returns the paths of the code scanning sarif files. */ private static async getCodeScanningEncodedSarif(): Promise { - const finalSarifFile: string = path.join(Utils.getJobOutputDirectoryPath(), this.SECURITY_DIR_NAME, this.SARIF_REPORTS_DIR_NAME, this.CODE_SCANNING_FINAL_SARIF_FILE); + const finalSarifFile: string = path.join( + Utils.getJobOutputDirectoryPath(), + this.SECURITY_DIR_NAME, + this.SARIF_REPORTS_DIR_NAME, + this.CODE_SCANNING_FINAL_SARIF_FILE, + ); if (!existsSync(finalSarifFile)) { console.debug('No code scanning sarif file was found.'); - return ""; + return ''; } // Read the SARIF file, compress and encode it to match the code-scanning/sarif API requirements. const sarif: string = await fs.readFile(finalSarifFile, 'utf-8'); - return await this.compressAndEncodeSarif(sarif) + return await this.compressAndEncodeSarif(sarif); } private static async readMarkdownContent() { diff --git a/test/main.spec.ts b/test/main.spec.ts index 2b4cbdeab..98ae7c634 100644 --- a/test/main.spec.ts +++ b/test/main.spec.ts @@ -2,9 +2,10 @@ import * as os from 'os'; import * as core from '@actions/core'; import { Utils, DownloadDetails, JfrogCredentials, JWTTokenData } from '../src/utils'; -import { tmpdir } from 'os'; +import semver = require('semver/preload'); jest.mock('os'); jest.mock('@actions/core'); +jest.mock('semver'); const DEFAULT_CLI_URL: string = 'https://releases.jfrog.io/artifactory/jfrog-cli/'; const CUSTOM_CLI_URL: string = 'http://127.0.0.1:8081/artifactory/jfrog-cli-remote/'; @@ -365,3 +366,33 @@ describe('Job Summaries', () => { }); }); }); + +describe('isJobSummarySupported', () => { + const MIN_CLI_VERSION_JOB_SUMMARY: string = '2.66.0'; + const LATEST_CLI_VERSION: string = 'latest'; + + beforeEach(() => { + jest.resetAllMocks(); + }); + + it('should return true if the version is the latest', () => { + jest.spyOn(core, 'getInput').mockReturnValue(LATEST_CLI_VERSION); + expect(Utils.isJobSummarySupported()).toBe(true); + }); + + it('should return true if the version is greater than or equal to the minimum supported version', () => { + const version: string = '2.66.0'; + jest.spyOn(core, 'getInput').mockReturnValue(version); + (semver.gte as jest.Mock).mockReturnValue(true); + expect(Utils.isJobSummarySupported()).toBe(true); + expect(semver.gte).toHaveBeenCalledWith(version, MIN_CLI_VERSION_JOB_SUMMARY); + }); + + it('should return false if the version is less than the minimum supported version', () => { + const version: string = '2.65.0'; + jest.spyOn(core, 'getInput').mockReturnValue(version); + (semver.gte as jest.Mock).mockReturnValue(false); + expect(Utils.isJobSummarySupported()).toBe(false); + expect(semver.gte).toHaveBeenCalledWith(version, MIN_CLI_VERSION_JOB_SUMMARY); + }); +});