diff --git a/README.md b/README.md index fcc5e052f..97e96a431 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ You can use these environment variables in your workflow as follows: - uses: jfrog/setup-jfrog-cli@v4 env: # JFrog platform url (for example: https://acme.jfrog.io) - JF_URL: ${{ secrets.JF_URL }} + JF_URL: ${{ vars.JF_URL }} # Basic authentication credentials JF_USER: ${{ secrets.JF_USER }} @@ -192,7 +192,7 @@ Example step utilizing OpenID Connect: ```yml - uses: jfrog/setup-jfrog-cli@v4 env: - JF_URL: ${{ secrets.JF_URL }} + JF_URL: ${{ vars.JF_URL }} with: oidc-provider-name: setup-jfrog-cli ``` @@ -303,6 +303,15 @@ Example JFrog Job Summary: ![JFrog-Job-Summary](images/JFrog-Job-Summary.png) + +Job summaries can be disabled by setting the `disable-job-summary` input to `true`. + +```yml +- uses: jfrog/setup-jfrog-cli@v4 + with: + disable-job-summary: true +``` + ## Example projects To help you get started, you can use [these](https://github.com/jfrog/project-examples/tree/master/github-action-examples) sample projects on GitHub. diff --git a/action.yml b/action.yml index c62729cba..5d5d89cee 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,10 @@ inputs: oidc-audience: description: "By default, this is the URL of the GitHub repository owner, such as the organization that owns the repository." required: false + disable-job-summary: + description: "Set to true to disable the generation of Job Summaries." + default: false + required: false outputs: oidc-token: description: "JFrog OIDC token generated by the Setup JFrog CLI when setting oidc-provider-name." diff --git a/lib/cleanup.js b/lib/cleanup.js index 0c43fdf90..8a2b236b4 100644 --- a/lib/cleanup.js +++ b/lib/cleanup.js @@ -42,7 +42,9 @@ function cleanup() { return; } yield utils_1.Utils.removeJFrogServers(); - yield utils_1.Utils.generateWorkflowSummaryMarkdown(); + if (!core.getBooleanInput(utils_1.Utils.JOB_SUMMARY_DISABLE)) { + yield utils_1.Utils.generateWorkflowSummaryMarkdown(); + } } catch (error) { core.setFailed(error.message); diff --git a/lib/utils.js b/lib/utils.js index 7f79e2ad5..536471130 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -338,9 +338,19 @@ class Utils { if (projectKey) { Utils.exportVariableIfNotSet('JFROG_CLI_BUILD_PROJECT', projectKey); } - let jobSummariesOutputDir = process.env.RUNNER_TEMP; - if (jobSummariesOutputDir) { - Utils.exportVariableIfNotSet('JFROG_CLI_COMMAND_SUMMARY_OUTPUT_DIR', jobSummariesOutputDir); + // Enable Job summaries if needed + if (!core.getBooleanInput(Utils.JOB_SUMMARY_DISABLE)) { + Utils.enableJobSummaries(); + } + } + /** + * Enabling job summary is done by setting the output dir for the summaries. + * If the output dir is not set, the CLI won't generate the summary markdown files. + */ + static enableJobSummaries() { + let commandSummariesOutputDir = process.env.RUNNER_TEMP; + if (commandSummariesOutputDir) { + Utils.exportVariableIfNotSet('JFROG_CLI_COMMAND_SUMMARY_OUTPUT_DIR', commandSummariesOutputDir); } } static exportVariableIfNotSet(key, value) { @@ -628,3 +638,5 @@ Utils.CLI_REMOTE_ARG = 'download-repository'; Utils.OIDC_AUDIENCE_ARG = 'oidc-audience'; // OpenID Connect provider_name input Utils.OIDC_INTEGRATION_PROVIDER_NAME = 'oidc-provider-name'; +// Job Summaries feature flag +Utils.JOB_SUMMARY_DISABLE = 'disable-job-summary'; diff --git a/src/cleanup.ts b/src/cleanup.ts index 3ccdc4d40..53b956eb2 100644 --- a/src/cleanup.ts +++ b/src/cleanup.ts @@ -8,7 +8,9 @@ async function cleanup() { return; } await Utils.removeJFrogServers(); - await Utils.generateWorkflowSummaryMarkdown(); + if (!core.getBooleanInput(Utils.JOB_SUMMARY_DISABLE)) { + await Utils.generateWorkflowSummaryMarkdown(); + } } catch (error) { core.setFailed((error).message); } finally { diff --git a/src/utils.ts b/src/utils.ts index e7fbc03eb..50da05623 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -52,6 +52,8 @@ export class Utils { private static readonly OIDC_AUDIENCE_ARG: string = 'oidc-audience'; // OpenID Connect provider_name input private static readonly OIDC_INTEGRATION_PROVIDER_NAME: string = 'oidc-provider-name'; + // Job Summaries feature flag + public static readonly JOB_SUMMARY_DISABLE: string = 'disable-job-summary'; /** * Retrieves server credentials for accessing JFrog's server @@ -367,9 +369,21 @@ export class Utils { if (projectKey) { Utils.exportVariableIfNotSet('JFROG_CLI_BUILD_PROJECT', projectKey); } - let jobSummariesOutputDir: string | undefined = process.env.RUNNER_TEMP; - if (jobSummariesOutputDir) { - Utils.exportVariableIfNotSet('JFROG_CLI_COMMAND_SUMMARY_OUTPUT_DIR', jobSummariesOutputDir); + + // Enable Job summaries if needed + if (!core.getBooleanInput(Utils.JOB_SUMMARY_DISABLE)) { + Utils.enableJobSummaries(); + } + } + + /** + * Enabling job summary is done by setting the output dir for the summaries. + * If the output dir is not set, the CLI won't generate the summary markdown files. + */ + private static enableJobSummaries() { + let commandSummariesOutputDir: string | undefined = process.env.RUNNER_TEMP; + if (commandSummariesOutputDir) { + Utils.exportVariableIfNotSet('JFROG_CLI_COMMAND_SUMMARY_OUTPUT_DIR', commandSummariesOutputDir); } } diff --git a/test/main.spec.ts b/test/main.spec.ts index b00da0f28..36ab17790 100644 --- a/test/main.spec.ts +++ b/test/main.spec.ts @@ -1,6 +1,9 @@ import * as os from 'os'; +import * as core from '@actions/core'; + import { Utils, DownloadDetails, JfrogCredentials } from '../src/utils'; jest.mock('os'); +jest.mock('@actions/core'); 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/'; @@ -298,6 +301,33 @@ describe('Job Summaries', () => { expect(async () => await Utils.generateWorkflowSummaryMarkdown()).not.toThrow(); }); }); + describe('Command Summaries Disable Flag', () => { + const myCore: jest.Mocked = core as any; + beforeEach(() => { + delete process.env.JFROG_CLI_COMMAND_SUMMARY_OUTPUT_DIR; + delete process.env.RUNNER_TEMP; + }); + + it('should not set JFROG_CLI_COMMAND_SUMMARY_OUTPUT_DIR if disable-job-summary is true', () => { + myCore.getBooleanInput = jest.fn().mockImplementation(() => { + return true; + }); + Utils.setCliEnv(); + expect(process.env.JFROG_CLI_COMMAND_SUMMARY_OUTPUT_DIR).toBeUndefined(); + }); + + it('should set JFROG_CLI_COMMAND_SUMMARY_OUTPUT_DIR if disable-job-summary is false', () => { + process.env.RUNNER_TEMP = '/tmp'; + myCore.getBooleanInput = jest.fn().mockImplementation(() => { + return false; + }); + (myCore.exportVariable = jest.fn().mockImplementation((name: string, val: string) => { + process.env[name] = val; + })), + Utils.setCliEnv(); + expect(process.env.JFROG_CLI_COMMAND_SUMMARY_OUTPUT_DIR).toBe('/tmp'); + }); + }); }); describe('isColorSchemeSupported', () => {