@@ -34,10 +34,7 @@ export async function setup(config: DependencyGraphConfig): Promise<void> {
34
34
maybeExportVariable ( 'GITHUB_DEPENDENCY_GRAPH_REF' , github . context . ref )
35
35
maybeExportVariable ( 'GITHUB_DEPENDENCY_GRAPH_SHA' , getShaFromContext ( ) )
36
36
maybeExportVariable ( 'GITHUB_DEPENDENCY_GRAPH_WORKSPACE' , getWorkspaceDirectory ( ) )
37
- maybeExportVariable (
38
- 'DEPENDENCY_GRAPH_REPORT_DIR' ,
39
- path . resolve ( getWorkspaceDirectory ( ) , 'dependency-graph-reports' )
40
- )
37
+ maybeExportVariable ( 'DEPENDENCY_GRAPH_REPORT_DIR' , config . getReportDirectory ( ) )
41
38
42
39
// To clear the dependency graph, we generate an empty graph by excluding all projects and configurations
43
40
if ( option === DependencyGraphOption . Clear ) {
@@ -62,22 +59,22 @@ export async function complete(config: DependencyGraphConfig): Promise<void> {
62
59
return
63
60
case DependencyGraphOption . GenerateAndSubmit :
64
61
case DependencyGraphOption . Clear : // Submit the empty dependency graph
65
- await submitDependencyGraphs ( await findGeneratedDependencyGraphFiles ( ) )
62
+ await submitDependencyGraphs ( await findDependencyGraphFiles ( ) )
66
63
return
67
64
case DependencyGraphOption . GenerateAndUpload :
68
- await uploadDependencyGraphs ( await findGeneratedDependencyGraphFiles ( ) , config )
65
+ await uploadDependencyGraphs ( await findDependencyGraphFiles ( ) , config )
69
66
}
70
67
} catch ( e ) {
71
68
warnOrFail ( config , option , e )
72
69
}
73
70
}
74
71
75
- async function findGeneratedDependencyGraphFiles ( ) : Promise < string [ ] > {
76
- const workspaceDirectory = getWorkspaceDirectory ( )
77
- return await findDependencyGraphFiles ( workspaceDirectory )
78
- }
79
-
80
72
async function uploadDependencyGraphs ( dependencyGraphFiles : string [ ] , config : DependencyGraphConfig ) : Promise < void > {
73
+ if ( dependencyGraphFiles . length === 0 ) {
74
+ core . info ( 'No dependency graph files found to upload.' )
75
+ return
76
+ }
77
+
81
78
if ( isRunningInActEnvironment ( ) ) {
82
79
core . info ( 'Dependency graph upload not supported in the ACT environment.' )
83
80
core . info ( `Would upload: ${ dependencyGraphFiles . join ( ', ' ) } ` )
@@ -111,6 +108,11 @@ async function downloadAndSubmitDependencyGraphs(config: DependencyGraphConfig):
111
108
}
112
109
113
110
async function submitDependencyGraphs ( dependencyGraphFiles : string [ ] ) : Promise < void > {
111
+ if ( dependencyGraphFiles . length === 0 ) {
112
+ core . info ( 'No dependency graph files found to submit.' )
113
+ return
114
+ }
115
+
114
116
if ( isRunningInActEnvironment ( ) ) {
115
117
core . info ( 'Dependency graph submit not supported in the ACT environment.' )
116
118
core . info ( `Would submit: ${ dependencyGraphFiles . join ( ', ' ) } ` )
@@ -156,8 +158,6 @@ async function submitDependencyGraphFile(jsonFile: string): Promise<void> {
156
158
}
157
159
158
160
async function downloadDependencyGraphs ( ) : Promise < string [ ] > {
159
- const workspaceDirectory = getWorkspaceDirectory ( )
160
-
161
161
const findBy = github . context . payload . workflow_run
162
162
? {
163
163
token : getGithubToken ( ) ,
@@ -168,34 +168,37 @@ async function downloadDependencyGraphs(): Promise<string[]> {
168
168
: undefined
169
169
170
170
const artifactClient = new DefaultArtifactClient ( )
171
- const downloadPath = path . resolve ( workspaceDirectory , 'dependency-graph' )
172
171
173
172
const dependencyGraphArtifacts = (
174
173
await artifactClient . listArtifacts ( {
175
174
latest : true ,
176
175
findBy
177
176
} )
178
- ) . artifacts . filter ( candidate => candidate . name . startsWith ( DEPENDENCY_GRAPH_PREFIX ) )
177
+ ) . artifacts . filter ( artifact => artifact . name . startsWith ( DEPENDENCY_GRAPH_PREFIX ) )
179
178
180
179
for ( const artifact of dependencyGraphArtifacts ) {
181
180
const downloadedArtifact = await artifactClient . downloadArtifact ( artifact . id , {
182
- path : downloadPath ,
183
181
findBy
184
182
} )
185
183
core . info ( `Downloading dependency-graph artifact ${ artifact . name } to ${ downloadedArtifact . downloadPath } ` )
186
184
}
187
185
188
- return findDependencyGraphFiles ( downloadPath )
186
+ return findDependencyGraphFiles ( )
189
187
}
190
188
191
- async function findDependencyGraphFiles ( dir : string ) : Promise < string [ ] > {
192
- const globber = await glob . create ( `${ dir } /dependency-graph-reports /*.json` )
189
+ async function findDependencyGraphFiles ( ) : Promise < string [ ] > {
190
+ const globber = await glob . create ( `${ getReportDirectory ( ) } /** /*.json` )
193
191
const allFiles = await globber . glob ( )
194
192
const unprocessedFiles = allFiles . filter ( file => ! isProcessed ( file ) )
195
193
unprocessedFiles . forEach ( markProcessed )
194
+ core . info ( `Found dependency graph files: ${ unprocessedFiles . join ( ', ' ) } ` )
196
195
return unprocessedFiles
197
196
}
198
197
198
+ function getReportDirectory ( ) : string {
199
+ return process . env . DEPENDENCY_GRAPH_REPORT_DIR !
200
+ }
201
+
199
202
function isProcessed ( dependencyGraphFile : string ) : boolean {
200
203
const markerFile = `${ dependencyGraphFile } .processed`
201
204
return fs . existsSync ( markerFile )
0 commit comments