diff --git a/action.yml b/action.yml index baf002c3b..8214af951 100644 --- a/action.yml +++ b/action.yml @@ -4,7 +4,7 @@ author: "JFrog" inputs: version: description: "JFrog CLI Version" - default: "2.72.2" + default: "2.72.3" 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/utils.js b/lib/utils.js index 787d84fb8..4976d09b5 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -98,7 +98,7 @@ class Utils { */ static getApplicationKey() { return __awaiter(this, void 0, void 0, function* () { - const configFilePath = path.join(this.JF_CONFIG_DIR_NAME, this.JF_CONFIG_FILE); + const configFilePath = path.join(this.JF_CONFIG_DIR_NAME, this.JF_CONFIG_FILE_NAME); try { const config = yield this.readConfigFromFileSystem(configFilePath); if (!config) { @@ -445,6 +445,23 @@ class Utils { if (!core.getBooleanInput(Utils.JOB_SUMMARY_DISABLE)) { Utils.enableJobSummaries(); } + Utils.setUsageEnvVars(); + } + // Set usage variables to be captured by JFrog CLI. + static setUsageEnvVars() { + // Repository name, defaulting to an empty string if undefined. + const repoName = process.env.GITHUB_REPOSITORY || ''; + // Workflow name, defaulting to an empty string if undefined. + const jobId = process.env.GITHUB_WORKFLOW || ''; + // Run ID, defaulting to an empty string if undefined. + const runId = process.env.GITHUB_RUN_ID || ''; + // Boolean flag indicating if JF_GIT_TOKEN is set. + const jfGitTokenSet = !!process.env.JF_GIT_TOKEN; + // Export environment variables for JFrog CLI usage. + core.exportVariable('JFROG_CLI_USAGE_JOB_ID', jobId); + core.exportVariable('JFROG_CLI_USAGE_RUN_ID', runId); + core.exportVariable('JFROG_CLI_USAGE_GIT_REPO', repoName); + core.exportVariable('JFROG_CLI_USAGE_GH_TOKEN_FOR_CODE_SCANNING_ALERTS_PROVIDED', jfGitTokenSet); } /** * Enabling job summary is done by setting the output dir for the summaries. @@ -885,7 +902,7 @@ Utils.KEY = 'key'; // Config file directory name Utils.JF_CONFIG_DIR_NAME = '.jfrog'; // Config file name -Utils.JF_CONFIG_FILE = 'config.yml'; +Utils.JF_CONFIG_FILE_NAME = 'config.yml'; // Disable Job Summaries feature flag Utils.JOB_SUMMARY_DISABLE = 'disable-job-summary'; // Disable auto build info publish feature flag diff --git a/src/utils.ts b/src/utils.ts index 301ca21dd..221dcca2f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -513,6 +513,29 @@ export class Utils { if (!core.getBooleanInput(Utils.JOB_SUMMARY_DISABLE)) { Utils.enableJobSummaries(); } + + Utils.setUsageEnvVars() + } + + // Set usage variables to be captured by JFrog CLI. + public static setUsageEnvVars(): void { + // Repository name, defaulting to an empty string if undefined. + const repoName: string = process.env.GITHUB_REPOSITORY || ''; + + // Workflow name, defaulting to an empty string if undefined. + const jobId: string = process.env.GITHUB_WORKFLOW || ''; + + // Run ID, defaulting to an empty string if undefined. + const runId: string = process.env.GITHUB_RUN_ID || ''; + + // Boolean flag indicating if JF_GIT_TOKEN is set. + const jfGitTokenSet: boolean = !!process.env.JF_GIT_TOKEN; + + // Export environment variables for JFrog CLI usage. + core.exportVariable('JFROG_CLI_USAGE_JOB_ID', jobId); + core.exportVariable('JFROG_CLI_USAGE_RUN_ID', runId); + core.exportVariable('JFROG_CLI_USAGE_GIT_REPO', repoName); + core.exportVariable('JFROG_CLI_USAGE_GH_TOKEN_FOR_CODE_SCANNING_ALERTS_PROVIDED', jfGitTokenSet); } /** diff --git a/test/main.spec.ts b/test/main.spec.ts index 93dbd3e3d..0ebea0313 100644 --- a/test/main.spec.ts +++ b/test/main.spec.ts @@ -528,3 +528,44 @@ describe('getApplicationKey', () => { expect(result).toBe(''); }); }); + +describe('setUsageEnvVars', () => { + beforeEach(() => { + // Clear environment variables before each test + delete process.env.GITHUB_REPOSITORY; + delete process.env.GITHUB_WORKFLOW; + delete process.env.GITHUB_RUN_ID; + delete process.env.JF_GIT_TOKEN; + + jest.clearAllMocks(); + }); + + it('should export the correct environment variables when all inputs are set', () => { + // Mock environment variables + process.env.GITHUB_REPOSITORY = 'owner/repo'; + process.env.GITHUB_WORKFLOW = 'test-workflow'; + process.env.GITHUB_RUN_ID = '12345'; + process.env.JF_GIT_TOKEN = 'dummy-token'; + + // Call the function + Utils.setUsageEnvVars(); + + // Verify exported variables + expect(core.exportVariable).toHaveBeenCalledWith('JFROG_CLI_USAGE_JOB_ID', 'test-workflow'); + expect(core.exportVariable).toHaveBeenCalledWith('JFROG_CLI_USAGE_RUN_ID', '12345'); + expect(core.exportVariable).toHaveBeenCalledWith('JFROG_CLI_USAGE_GIT_REPO', 'owner/repo'); + expect(core.exportVariable).toHaveBeenCalledWith('JFROG_CLI_USAGE_GH_TOKEN_FOR_CODE_SCANNING_ALERTS_PROVIDED', true); + }); + + it('should export empty strings for missing environment variables', () => { + // Call the function with no environment variables set + Utils.setUsageEnvVars(); + + // Verify exported variables + expect(core.exportVariable).toHaveBeenCalledWith('JFROG_CLI_USAGE_JOB_ID', ''); + expect(core.exportVariable).toHaveBeenCalledWith('JFROG_CLI_USAGE_RUN_ID', ''); + expect(core.exportVariable).toHaveBeenCalledWith('JFROG_CLI_USAGE_GIT_REPO', ''); + expect(core.exportVariable).toHaveBeenCalledWith('JFROG_CLI_USAGE_GH_TOKEN_FOR_CODE_SCANNING_ALERTS_PROVIDED', false); + }); +}); +