Skip to content

Commit

Permalink
Upgrade Default CLI version (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea committed Sep 5, 2024
1 parent 883a85f commit 9fe0f98
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
3 changes: 3 additions & 0 deletions lib/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
15 changes: 10 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -654,15 +654,20 @@ export class Utils {
* @returns <string[]> the paths of the code scanning sarif files.
*/
private static async getCodeScanningEncodedSarif(): Promise<string> {
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() {
Expand Down
33 changes: 32 additions & 1 deletion test/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/';
Expand Down Expand Up @@ -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);
});
});

0 comments on commit 9fe0f98

Please sign in to comment.