From b7ef93c7b71dae2439fcb0c4686dbfa7b986cb63 Mon Sep 17 00:00:00 2001 From: daz Date: Sun, 7 Apr 2024 10:54:55 -0600 Subject: [PATCH] Provide default config values for dependency-submission --- dependency-submission/action.yml | 41 ++++++++++------------- sources/src/dependency-graph.ts | 24 ++++++------- sources/src/dependency-submission/main.ts | 6 ++-- sources/src/input-params.ts | 10 ++++-- 4 files changed, 40 insertions(+), 41 deletions(-) diff --git a/dependency-submission/action.yml b/dependency-submission/action.yml index 2164b0b..9175c1f 100644 --- a/dependency-submission/action.yml +++ b/dependency-submission/action.yml @@ -34,6 +34,15 @@ inputs: Additional arguments to pass to Gradle. For example, `--no-configuration-cache --stacktrace`. required: false + add-job-summary: + description: Specifies when a Job Summary should be inluded in the action results. Valid values are 'never', 'always' (default), and 'on-failure'. + required: false + default: 'always' + add-job-summary-as-pr-comment: + description: Specifies when each Job Summary should be added as a PR comment. Valid values are 'never' (default), 'always', and 'on-failure'. No action will be taken if the workflow was not triggered from a pull request. + required: false + default: 'never' + build-scan-publish: description: | Set to 'true' to automatically publish build results as a Build Scan on scans.gradle.com. @@ -47,29 +56,6 @@ inputs: description: Indicate that you agree to the Build ScanĀ® terms of use. This input value must be "yes". required: false - # HARD-CODED DEFAULTS - These should be removed from here and set directly in code - dependency-graph-continue-on-failure: - required: false - default: false - artifact-retention-days: - required: false - default: 1 - add-job-summary: - required: false - default: 'always' - add-job-summary-as-pr-comment: - required: false - default: 'never' - workflow-job-context: - required: false - default: ${{ toJSON(matrix) }} - github-token: - default: ${{ github.token }} - required: false - cache-disabled: - required: false - default: true - # DEPRECATED ACTION INPUTS build-scan-terms-of-service-url: description: The URL to the Build ScanĀ® terms of use. This input must be set to 'https://gradle.com/terms-of-service'. @@ -81,6 +67,15 @@ inputs: required: false deprecation-message: The input has been renamed to align with the Develocity API. Use 'build-scan-terms-of-use-agree' instead. + # INTERNAL ACTION INPUTS + # These inputs should not be configured directly, and are only used to pass environmental information to the action + workflow-job-context: + required: false + default: ${{ toJSON(matrix) }} + github-token: + default: ${{ github.token }} + required: false + runs: using: 'node20' main: '../dist/dependency-submission/main/index.js' diff --git a/sources/src/dependency-graph.ts b/sources/src/dependency-graph.ts index a539924..01be9e4 100644 --- a/sources/src/dependency-graph.ts +++ b/sources/src/dependency-graph.ts @@ -16,20 +16,19 @@ import {DependencyGraphConfig, DependencyGraphOption, getGithubToken} from './in const DEPENDENCY_GRAPH_PREFIX = 'dependency-graph_' export async function setup(config: DependencyGraphConfig): Promise { - const option = config.getDependencyGraphOption() - if (option === DependencyGraphOption.Disabled) { + if (config.dependencyGraphOption === DependencyGraphOption.Disabled) { core.exportVariable('GITHUB_DEPENDENCY_GRAPH_ENABLED', 'false') return } // Download and submit early, for compatability with dependency review. - if (option === DependencyGraphOption.DownloadAndSubmit) { + if (config.dependencyGraphOption === DependencyGraphOption.DownloadAndSubmit) { await downloadAndSubmitDependencyGraphs(config) return } core.info('Enabling dependency graph generation') core.exportVariable('GITHUB_DEPENDENCY_GRAPH_ENABLED', 'true') - maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_CONTINUE_ON_FAILURE', config.getDependencyGraphContinueOnFailure()) + maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_CONTINUE_ON_FAILURE', config.continueOnFailure) maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR', config.getJobCorrelator()) maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_JOB_ID', github.context.runId) maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_REF', github.context.ref) @@ -41,7 +40,7 @@ export async function setup(config: DependencyGraphConfig): Promise { ) // To clear the dependency graph, we generate an empty graph by excluding all projects and configurations - if (option === DependencyGraphOption.Clear) { + if (config.dependencyGraphOption === DependencyGraphOption.Clear) { core.exportVariable('DEPENDENCY_GRAPH_INCLUDE_PROJECTS', '') core.exportVariable('DEPENDENCY_GRAPH_INCLUDE_CONFIGURATIONS', '') } @@ -59,9 +58,8 @@ export async function complete(config: DependencyGraphConfig): Promise { return } - const option = config.getDependencyGraphOption() try { - switch (option) { + switch (config.dependencyGraphOption) { case DependencyGraphOption.Disabled: case DependencyGraphOption.Generate: // Performed via init-script: nothing to do here case DependencyGraphOption.DownloadAndSubmit: // Performed in setup @@ -74,7 +72,7 @@ export async function complete(config: DependencyGraphConfig): Promise { await uploadDependencyGraphs(await findGeneratedDependencyGraphFiles(), config) } } catch (e) { - warnOrFail(config, option, e) + warnOrFail(config, e) } } @@ -92,7 +90,7 @@ async function uploadDependencyGraphs(dependencyGraphFiles: string[], config: De core.info(`Uploading dependency graph file: ${relativePath}`) const artifactName = `${DEPENDENCY_GRAPH_PREFIX}${path.basename(dependencyGraphFile)}` await artifactClient.uploadArtifact(artifactName, [dependencyGraphFile], workspaceDirectory, { - retentionDays: config.getArtifactRetentionDays() + retentionDays: config.artifactRetentionDays }) } } @@ -106,7 +104,7 @@ async function downloadAndSubmitDependencyGraphs(config: DependencyGraphConfig): try { await submitDependencyGraphs(await downloadDependencyGraphs()) } catch (e) { - warnOrFail(config, DependencyGraphOption.DownloadAndSubmit, e) + warnOrFail(config, e) } } @@ -188,12 +186,12 @@ async function findDependencyGraphFiles(dir: string): Promise { return graphFiles } -function warnOrFail(config: DependencyGraphConfig, option: String, error: unknown): void { - if (!config.getDependencyGraphContinueOnFailure()) { +function warnOrFail(config: DependencyGraphConfig, error: unknown): void { + if (!config.continueOnFailure) { throw new PostActionJobFailure(error) } - core.warning(`Failed to ${option} dependency graph. Will continue.\n${String(error)}`) + core.warning(`Failed to ${config.dependencyGraphOption} dependency graph. Will continue.\n${String(error)}`) } function getOctokit(): InstanceType { diff --git a/sources/src/dependency-submission/main.ts b/sources/src/dependency-submission/main.ts index e9e5110..e48f22b 100644 --- a/sources/src/dependency-submission/main.ts +++ b/sources/src/dependency-submission/main.ts @@ -19,9 +19,12 @@ export async function run(): Promise { // Configure the dependency graph submission const config = new DependencyGraphConfig() + config.artifactRetentionDays = 1 + config.continueOnFailure = false + await dependencyGraph.setup(config) - if (config.getDependencyGraphOption() === DependencyGraphOption.DownloadAndSubmit) { + if (config.dependencyGraphOption === DependencyGraphOption.DownloadAndSubmit) { // No execution to perform return } @@ -40,7 +43,6 @@ export async function run(): Promise { ` const args: string[] = parseArgsStringToArgv(executionArgs) - core.info(args.join('!!!')) const buildRootDirectory = layout.buildRootDirectory() await execution.executeGradleBuild(executable, buildRootDirectory, args) } catch (error) { diff --git a/sources/src/input-params.ts b/sources/src/input-params.ts index bd9449a..d18b74f 100644 --- a/sources/src/input-params.ts +++ b/sources/src/input-params.ts @@ -6,7 +6,11 @@ import {SUMMARY_ENV_VAR} from '@actions/core/lib/summary' import {parseArgsStringToArgv} from 'string-argv' export class DependencyGraphConfig { - getDependencyGraphOption(): DependencyGraphOption { + dependencyGraphOption = this.getDependencyGraphOption() + continueOnFailure = this.getDependencyGraphContinueOnFailure() + artifactRetentionDays = this.getArtifactRetentionDays() + + private getDependencyGraphOption(): DependencyGraphOption { const val = core.getInput('dependency-graph') switch (val.toLowerCase().trim()) { case 'disabled': @@ -27,11 +31,11 @@ export class DependencyGraphConfig { ) } - getDependencyGraphContinueOnFailure(): boolean { + private getDependencyGraphContinueOnFailure(): boolean { return getBooleanInput('dependency-graph-continue-on-failure', true) } - getArtifactRetentionDays(): number { + private getArtifactRetentionDays(): number { const val = core.getInput('artifact-retention-days') return parseNumericInput('artifact-retention-days', val, 0) // Zero indicates that the default repository settings should be used