From 49ade81b5d4db6d0c2d43fc2b4c96384e5d57d4d Mon Sep 17 00:00:00 2001 From: daz Date: Tue, 23 Jan 2024 14:55:59 -0700 Subject: [PATCH] Add a new option to clear the dependency-graph When changing workflow names or when changing to the new 'dependency-submission' action, it can be useful to clear existing dependency graph snapshots from previous submissions. While the old graphs will eventually "age out", the 'clear' option will submit an empty dependency graph for an existing Job correlator, ensuring that old dependency graphs don't linger. --- action.yml | 2 +- src/dependency-graph.ts | 7 +++++++ src/input-params.ts | 7 +++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 0738cde..13beb6e 100644 --- a/action.yml +++ b/action.yml @@ -69,7 +69,7 @@ inputs: default: 'never' dependency-graph: - description: Specifies if a GitHub dependency snapshot should be generated for each Gradle build, and if so, how. Valid values are 'disabled' (default), 'generate', 'generate-and-submit', 'generate-and-upload' and 'download-and-submit'. + description: Specifies if a GitHub dependency snapshot should be generated for each Gradle build, and if so, how. Valid values are 'disabled' (default), 'generate', 'generate-and-submit', 'generate-and-upload', 'download-and-submit' and 'clear'. required: false default: 'disabled' diff --git a/src/dependency-graph.ts b/src/dependency-graph.ts index 6163af8..f315a99 100644 --- a/src/dependency-graph.ts +++ b/src/dependency-graph.ts @@ -42,6 +42,12 @@ export async function setup(option: DependencyGraphOption): Promise { 'DEPENDENCY_GRAPH_REPORT_DIR', path.resolve(layout.workspaceDirectory(), 'dependency-graph-reports') ) + + // To clear the dependency graph, we generate an empty graph by excluding all projects and configurations + if (option === DependencyGraphOption.Clear) { + core.exportVariable('DEPENDENCY_GRAPH_INCLUDE_PROJECTS', '') + core.exportVariable('DEPENDENCY_GRAPH_INCLUDE_CONFIGURATIONS', '') + } } function maybeExportVariable(variableName: string, value: unknown): void { @@ -58,6 +64,7 @@ export async function complete(option: DependencyGraphOption): Promise { case DependencyGraphOption.DownloadAndSubmit: // Performed in setup return case DependencyGraphOption.GenerateAndSubmit: + case DependencyGraphOption.Clear: // Submit the empty dependency graph await submitDependencyGraphs(await findGeneratedDependencyGraphFiles()) return case DependencyGraphOption.GenerateAndUpload: diff --git a/src/input-params.ts b/src/input-params.ts index 9f498cc..4043aea 100644 --- a/src/input-params.ts +++ b/src/input-params.ts @@ -101,9 +101,11 @@ export function getDependencyGraphOption(): DependencyGraphOption { return DependencyGraphOption.GenerateAndUpload case 'download-and-submit': return DependencyGraphOption.DownloadAndSubmit + case 'clear': + return DependencyGraphOption.Clear } throw TypeError( - `The value '${val}' is not valid for 'dependency-graph'. Valid values are: [disabled, generate, generate-and-submit, generate-and-upload, download-and-submit]. The default value is 'disabled'.` + `The value '${val}' is not valid for 'dependency-graph'. Valid values are: [disabled, generate, generate-and-submit, generate-and-upload, download-and-submit, clear]. The default value is 'disabled'.` ) } @@ -146,7 +148,8 @@ export enum DependencyGraphOption { Generate = 'generate', GenerateAndSubmit = 'generate-and-submit', GenerateAndUpload = 'generate-and-upload', - DownloadAndSubmit = 'download-and-submit' + DownloadAndSubmit = 'download-and-submit', + Clear = 'clear' } export enum JobSummaryOption {