Add new option to clear 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.
This commit is contained in:
daz 2024-01-23 15:22:33 -07:00
parent 7c8a278ea0
commit 9283312acb
No known key found for this signature in database
3 changed files with 12 additions and 2 deletions

View file

@ -69,7 +69,7 @@ inputs:
default: true default: true
dependency-graph: 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' 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', 'download-and-submit' and 'clear'.
required: false required: false
default: 'disabled' default: 'disabled'

View file

@ -36,6 +36,12 @@ export async function setup(option: DependencyGraphOption): Promise<void> {
'DEPENDENCY_GRAPH_REPORT_DIR', 'DEPENDENCY_GRAPH_REPORT_DIR',
path.resolve(layout.workspaceDirectory(), 'dependency-graph-reports') 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', '')
}
} }
export async function complete(option: DependencyGraphOption): Promise<void> { export async function complete(option: DependencyGraphOption): Promise<void> {
@ -47,6 +53,7 @@ export async function complete(option: DependencyGraphOption): Promise<void> {
await uploadDependencyGraphs() await uploadDependencyGraphs()
return return
case DependencyGraphOption.GenerateAndSubmit: case DependencyGraphOption.GenerateAndSubmit:
case DependencyGraphOption.Clear: // Submit the empty dependency graph
await submitDependencyGraphs(await uploadDependencyGraphs()) await submitDependencyGraphs(await uploadDependencyGraphs())
return return
} }

View file

@ -82,6 +82,8 @@ export function getDependencyGraphOption(): DependencyGraphOption {
return DependencyGraphOption.GenerateAndSubmit return DependencyGraphOption.GenerateAndSubmit
case 'download-and-submit': case 'download-and-submit':
return DependencyGraphOption.DownloadAndSubmit return DependencyGraphOption.DownloadAndSubmit
case 'clear':
return DependencyGraphOption.Clear
} }
throw TypeError( throw TypeError(
`The value '${val} is not valid for 'dependency-graph. Valid values are: [disabled, generate-and-upload, generate-and-submit, download-and-submit]. The default value is 'disabled'.` `The value '${val} is not valid for 'dependency-graph. Valid values are: [disabled, generate-and-upload, generate-and-submit, download-and-submit]. The default value is 'disabled'.`
@ -122,5 +124,6 @@ export enum DependencyGraphOption {
Disabled, Disabled,
Generate, Generate,
GenerateAndSubmit, GenerateAndSubmit,
DownloadAndSubmit DownloadAndSubmit,
Clear
} }