@@ -60,44 +60,19 @@ export async function complete(config: DependencyGraphConfig): Promise<void> {
60
60
return
61
61
case DependencyGraphOption . GenerateAndSubmit :
62
62
case DependencyGraphOption . Clear : // Submit the empty dependency graph
63
- await submitDependencyGraphs ( await findDependencyGraphFiles ( ) )
63
+ await findAndSubmitDependencyGraphs ( config )
64
64
return
65
65
case DependencyGraphOption . GenerateAndUpload :
66
- await uploadDependencyGraphs ( await findDependencyGraphFiles ( ) , config )
66
+ await findAndUploadDependencyGraphs ( config )
67
67
}
68
68
} catch ( e ) {
69
69
warnOrFail ( config , option , e )
70
70
}
71
71
}
72
72
73
- async function uploadDependencyGraphs ( dependencyGraphFiles : string [ ] , config : DependencyGraphConfig ) : Promise < void > {
74
- if ( dependencyGraphFiles . length === 0 ) {
75
- core . info ( 'No dependency graph files found to upload.' )
76
- return
77
- }
78
-
79
- if ( isRunningInActEnvironment ( ) ) {
80
- core . info ( 'Dependency graph upload not supported in the ACT environment.' )
81
- core . info ( `Would upload: ${ dependencyGraphFiles . join ( ', ' ) } ` )
82
- return
83
- }
84
-
85
- const workspaceDirectory = getWorkspaceDirectory ( )
86
-
87
- const artifactClient = new DefaultArtifactClient ( )
88
- for ( const dependencyGraphFile of dependencyGraphFiles ) {
89
- const relativePath = getRelativePathFromWorkspace ( dependencyGraphFile )
90
- core . info ( `Uploading dependency graph file: ${ relativePath } ` )
91
- const artifactName = `${ DEPENDENCY_GRAPH_PREFIX } ${ path . basename ( dependencyGraphFile ) } `
92
- await artifactClient . uploadArtifact ( artifactName , [ dependencyGraphFile ] , workspaceDirectory , {
93
- retentionDays : config . getArtifactRetentionDays ( )
94
- } )
95
- }
96
- }
97
-
98
73
async function downloadAndSubmitDependencyGraphs ( config : DependencyGraphConfig ) : Promise < void > {
99
74
if ( isRunningInActEnvironment ( ) ) {
100
- core . info ( 'Dependency graph download and submit not supported in the ACT environment.' )
75
+ core . info ( 'Dependency graph not supported in the ACT environment.' )
101
76
return
102
77
}
103
78
@@ -108,53 +83,32 @@ async function downloadAndSubmitDependencyGraphs(config: DependencyGraphConfig):
108
83
}
109
84
}
110
85
111
- async function submitDependencyGraphs ( dependencyGraphFiles : string [ ] ) : Promise < void > {
112
- if ( dependencyGraphFiles . length === 0 ) {
113
- core . info ( 'No dependency graph files found to submit.' )
114
- return
115
- }
116
-
86
+ async function findAndSubmitDependencyGraphs ( config : DependencyGraphConfig ) : Promise < void > {
117
87
if ( isRunningInActEnvironment ( ) ) {
118
- core . info ( 'Dependency graph submit not supported in the ACT environment.' )
119
- core . info ( `Would submit: ${ dependencyGraphFiles . join ( ', ' ) } ` )
88
+ core . info ( 'Dependency graph not supported in the ACT environment.' )
120
89
return
121
90
}
122
91
123
- for ( const dependencyGraphFile of dependencyGraphFiles ) {
92
+ const dependencyGraphFiles = await findDependencyGraphFiles ( )
93
+ try {
94
+ await submitDependencyGraphs ( dependencyGraphFiles )
95
+ } catch ( e ) {
124
96
try {
125
- await submitDependencyGraphFile ( dependencyGraphFile )
126
- } catch ( error ) {
127
- if ( error instanceof RequestError ) {
128
- error . message = translateErrorMessage ( dependencyGraphFile , error )
129
- }
130
- throw error
97
+ await uploadDependencyGraphs ( dependencyGraphFiles , config )
98
+ } catch ( uploadError ) {
99
+ core . info ( String ( uploadError ) )
131
100
}
101
+ throw e
132
102
}
133
103
}
134
104
135
- function translateErrorMessage ( jsonFile : string , error : RequestError ) : string {
136
- const relativeJsonFile = getRelativePathFromWorkspace ( jsonFile )
137
- const mainWarning = `Dependency submission failed for ${ relativeJsonFile } .\n${ error . message } `
138
- if ( error . message === 'Resource not accessible by integration' ) {
139
- return `${ mainWarning }
140
- Please ensure that the 'contents: write' permission is available for the workflow job.
141
- Note that this permission is never available for a 'pull_request' trigger from a repository fork.
142
- `
105
+ async function findAndUploadDependencyGraphs ( config : DependencyGraphConfig ) : Promise < void > {
106
+ if ( isRunningInActEnvironment ( ) ) {
107
+ core . info ( 'Dependency graph not supported in the ACT environment.' )
108
+ return
143
109
}
144
- return mainWarning
145
- }
146
-
147
- async function submitDependencyGraphFile ( jsonFile : string ) : Promise < void > {
148
- const octokit = getOctokit ( )
149
- const jsonContent = fs . readFileSync ( jsonFile , 'utf8' )
150
110
151
- const jsonObject = JSON . parse ( jsonContent )
152
- jsonObject . owner = github . context . repo . owner
153
- jsonObject . repo = github . context . repo . repo
154
- const response = await octokit . request ( 'POST /repos/{owner}/{repo}/dependency-graph/snapshots' , jsonObject )
155
-
156
- const relativeJsonFile = getRelativePathFromWorkspace ( jsonFile )
157
- core . notice ( `Submitted ${ relativeJsonFile } : ${ response . data . message } ` )
111
+ await uploadDependencyGraphs ( await findDependencyGraphFiles ( ) , config )
158
112
}
159
113
160
114
async function downloadDependencyGraphs ( ) : Promise < string [ ] > {
@@ -195,6 +149,67 @@ async function findDependencyGraphFiles(): Promise<string[]> {
195
149
return unprocessedFiles
196
150
}
197
151
152
+ async function uploadDependencyGraphs ( dependencyGraphFiles : string [ ] , config : DependencyGraphConfig ) : Promise < void > {
153
+ if ( dependencyGraphFiles . length === 0 ) {
154
+ core . info ( 'No dependency graph files found to upload.' )
155
+ return
156
+ }
157
+
158
+ const workspaceDirectory = getWorkspaceDirectory ( )
159
+
160
+ const artifactClient = new DefaultArtifactClient ( )
161
+ for ( const dependencyGraphFile of dependencyGraphFiles ) {
162
+ const relativePath = getRelativePathFromWorkspace ( dependencyGraphFile )
163
+ core . info ( `Uploading dependency graph file: ${ relativePath } ` )
164
+ const artifactName = `${ DEPENDENCY_GRAPH_PREFIX } ${ path . basename ( dependencyGraphFile ) } `
165
+ await artifactClient . uploadArtifact ( artifactName , [ dependencyGraphFile ] , workspaceDirectory , {
166
+ retentionDays : config . getArtifactRetentionDays ( )
167
+ } )
168
+ }
169
+ }
170
+
171
+ async function submitDependencyGraphs ( dependencyGraphFiles : string [ ] ) : Promise < void > {
172
+ if ( dependencyGraphFiles . length === 0 ) {
173
+ core . info ( 'No dependency graph files found to submit.' )
174
+ return
175
+ }
176
+
177
+ for ( const dependencyGraphFile of dependencyGraphFiles ) {
178
+ try {
179
+ await submitDependencyGraphFile ( dependencyGraphFile )
180
+ } catch ( error ) {
181
+ if ( error instanceof RequestError ) {
182
+ error . message = translateErrorMessage ( dependencyGraphFile , error )
183
+ }
184
+ throw error
185
+ }
186
+ }
187
+ }
188
+
189
+ function translateErrorMessage ( jsonFile : string , error : RequestError ) : string {
190
+ const relativeJsonFile = getRelativePathFromWorkspace ( jsonFile )
191
+ const mainWarning = `Dependency submission failed for ${ relativeJsonFile } .\n${ error . message } `
192
+ if ( error . message === 'Resource not accessible by integration' ) {
193
+ return `${ mainWarning }
194
+ Please ensure that the 'contents: write' permission is available for the workflow job.
195
+ Note that this permission is never available for a 'pull_request' trigger from a repository fork.
196
+ `
197
+ }
198
+ return mainWarning
199
+ }
200
+
201
+ async function submitDependencyGraphFile ( jsonFile : string ) : Promise < void > {
202
+ const octokit = getOctokit ( )
203
+ const jsonContent = fs . readFileSync ( jsonFile , 'utf8' )
204
+
205
+ const jsonObject = JSON . parse ( jsonContent )
206
+ jsonObject . owner = github . context . repo . owner
207
+ jsonObject . repo = github . context . repo . repo
208
+ const response = await octokit . request ( 'POST /repos/{owner}/{repo}/dependency-graph/snapshots' , jsonObject )
209
+
210
+ const relativeJsonFile = getRelativePathFromWorkspace ( jsonFile )
211
+ core . notice ( `Submitted ${ relativeJsonFile } : ${ response . data . message } ` )
212
+ }
198
213
function getReportDirectory ( ) : string {
199
214
return process . env . DEPENDENCY_GRAPH_REPORT_DIR !
200
215
}
0 commit comments