Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable Job Summaries #169

Merged
merged 16 commits into from
Jul 11, 2024
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,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.
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: "Allows to disable to generation of Job Summaries."
EyalDelarea marked this conversation as resolved.
Show resolved Hide resolved
default: "false"
EyalDelarea marked this conversation as resolved.
Show resolved Hide resolved
EyalDelarea marked this conversation as resolved.
Show resolved Hide resolved
required: false
outputs:
oidc-token:
description: "JFrog OIDC token generated by the Setup JFrog CLI when setting oidc-provider-name."
Expand Down
18 changes: 15 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,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) {
Expand Down Expand Up @@ -596,3 +606,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';
20 changes: 17 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
private static readonly JOB_SUMMARY_DISABLE: string = 'disable-job-summary';

/**
* Retrieves server credentials for accessing JFrog's server
Expand Down Expand Up @@ -360,9 +362,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);
}
}

Expand Down
30 changes: 30 additions & 0 deletions test/main.spec.ts
Original file line number Diff line number Diff line change
@@ -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/';
Expand Down Expand Up @@ -298,4 +301,31 @@ describe('Job Summaries', () => {
expect(async () => await Utils.generateWorkflowSummaryMarkdown()).not.toThrow();
});
});
describe('Command Summaries Disable Flag', () => {
const myCore: jest.Mocked<typeof core> = 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');
});
});
});
Loading