Skip to content

Commit

Permalink
Add option to disable Job Summaries (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea authored Jul 11, 2024
1 parent b6ae82d commit 8db8d2b
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 10 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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
```
Expand Down Expand Up @@ -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.
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: "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."
Expand Down
4 changes: 3 additions & 1 deletion lib/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 15 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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';
4 changes: 3 additions & 1 deletion src/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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((<any>error).message);
} finally {
Expand Down
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
public static readonly JOB_SUMMARY_DISABLE: string = 'disable-job-summary';

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

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,6 +301,33 @@ 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');
});
});
});

describe('isColorSchemeSupported', () => {
Expand Down

0 comments on commit 8db8d2b

Please sign in to comment.