Skip to content

Commit c198d84

Browse files
authored
Support custom report dir for dependency-submission (#189)
If the `DEPENDENCY_GRAPH_REPORT_DIR` var is set, use this value when locating dependency-graph files to upload/submit. Fixes #188
1 parent d211a39 commit c198d84

File tree

4 files changed

+104
-21
lines changed

4 files changed

+104
-21
lines changed

.github/workflows/integ-test-dependency-submission-failures.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test dependency graph
1+
name: Test dependency submission failures
22

33
on:
44
workflow_call:

.github/workflows/integ-test-dependency-submission.yml

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test dependency graph
1+
name: Test dependency submission
22

33
on:
44
workflow_call:
@@ -245,3 +245,79 @@ jobs:
245245
uses: ./dependency-submission
246246
with:
247247
build-root-directory: .github/workflow-samples/groovy-dsl
248+
249+
custom-report-dir-submit:
250+
strategy:
251+
fail-fast: false
252+
matrix:
253+
os: ${{fromJSON(inputs.runner-os)}}
254+
runs-on: ${{ matrix.os }}
255+
steps:
256+
- name: Checkout sources
257+
uses: actions/checkout@v4
258+
- name: Initialize integ-test
259+
uses: ./.github/actions/init-integ-test
260+
261+
- name: Generate dependency graph
262+
id: dependency-graph
263+
uses: ./dependency-submission
264+
with:
265+
dependency-graph: generate-and-submit
266+
build-root-directory: .github/workflow-samples/groovy-dsl
267+
env:
268+
DEPENDENCY_GRAPH_REPORT_DIR: '${{ github.workspace }}/custom/report-dir'
269+
- name: Check generated dependency graphs
270+
shell: bash
271+
run: |
272+
echo "report file: ${{ steps.dependency-graph.outputs.dependency-graph-file }}"
273+
274+
if [ ! -e "${{ steps.dependency-graph.outputs.dependency-graph-file }}" ]; then
275+
echo "Did not find dependency graph file"
276+
exit 1
277+
fi
278+
279+
if [ -z "$(ls -A "${{ github.workspace }}/custom/report-dir")" ]; then
280+
echo "No dependency graph files found in custom directory"
281+
exit 1
282+
fi
283+
284+
custom-report-dir-upload:
285+
runs-on: ubuntu-latest
286+
steps:
287+
- name: Checkout sources
288+
uses: actions/checkout@v4
289+
- name: Initialize integ-test
290+
uses: ./.github/actions/init-integ-test
291+
292+
- name: Generate and upload dependency graph
293+
id: dependency-graph
294+
uses: ./dependency-submission
295+
with:
296+
dependency-graph: generate-and-upload
297+
build-root-directory: .github/workflow-samples/groovy-dsl
298+
env:
299+
DEPENDENCY_GRAPH_REPORT_DIR: '${{ github.workspace }}/custom/report-dir'
300+
301+
custom-report-dir-download-and-submit:
302+
needs: custom-report-dir-upload
303+
runs-on: ubuntu-latest
304+
steps:
305+
- name: Checkout sources
306+
uses: actions/checkout@v4
307+
- name: Initialize integ-test
308+
uses: ./.github/actions/init-integ-test
309+
310+
- name: Download and submit dependency graph
311+
uses: ./dependency-submission
312+
with:
313+
dependency-graph: download-and-submit
314+
build-root-directory: .github/workflow-samples/groovy-dsl
315+
env:
316+
DEPENDENCY_GRAPH_REPORT_DIR: '${{ github.workspace }}/custom/report-dir'
317+
- name: Check downloaded dependency graph
318+
shell: bash
319+
run: |
320+
if [ -z "$(ls -A "${{ github.workspace }}/custom/report-dir")" ]; then
321+
echo "No dependency graph files found in custom directory"
322+
exit 1
323+
fi

sources/src/configuration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export class DependencyGraphConfig {
4545
return DependencyGraphConfig.constructJobCorrelator(github.context.workflow, github.context.job, getJobMatrix())
4646
}
4747

48+
getReportDirectory(): string {
49+
return path.resolve(getWorkspaceDirectory(), 'dependency-graph-reports')
50+
}
51+
4852
static constructJobCorrelator(workflow: string, jobId: string, matrixJson: string): string {
4953
const matrixString = this.describeMatrix(matrixJson)
5054
const label = matrixString ? `${workflow}-${jobId}-${matrixString}` : `${workflow}-${jobId}`

sources/src/dependency-graph.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ export async function setup(config: DependencyGraphConfig): Promise<void> {
3434
maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_REF', github.context.ref)
3535
maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_SHA', getShaFromContext())
3636
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())
4138

4239
// To clear the dependency graph, we generate an empty graph by excluding all projects and configurations
4340
if (option === DependencyGraphOption.Clear) {
@@ -62,22 +59,22 @@ export async function complete(config: DependencyGraphConfig): Promise<void> {
6259
return
6360
case DependencyGraphOption.GenerateAndSubmit:
6461
case DependencyGraphOption.Clear: // Submit the empty dependency graph
65-
await submitDependencyGraphs(await findGeneratedDependencyGraphFiles())
62+
await submitDependencyGraphs(await findDependencyGraphFiles())
6663
return
6764
case DependencyGraphOption.GenerateAndUpload:
68-
await uploadDependencyGraphs(await findGeneratedDependencyGraphFiles(), config)
65+
await uploadDependencyGraphs(await findDependencyGraphFiles(), config)
6966
}
7067
} catch (e) {
7168
warnOrFail(config, option, e)
7269
}
7370
}
7471

75-
async function findGeneratedDependencyGraphFiles(): Promise<string[]> {
76-
const workspaceDirectory = getWorkspaceDirectory()
77-
return await findDependencyGraphFiles(workspaceDirectory)
78-
}
79-
8072
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+
8178
if (isRunningInActEnvironment()) {
8279
core.info('Dependency graph upload not supported in the ACT environment.')
8380
core.info(`Would upload: ${dependencyGraphFiles.join(', ')}`)
@@ -111,6 +108,11 @@ async function downloadAndSubmitDependencyGraphs(config: DependencyGraphConfig):
111108
}
112109

113110
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+
114116
if (isRunningInActEnvironment()) {
115117
core.info('Dependency graph submit not supported in the ACT environment.')
116118
core.info(`Would submit: ${dependencyGraphFiles.join(', ')}`)
@@ -156,8 +158,6 @@ async function submitDependencyGraphFile(jsonFile: string): Promise<void> {
156158
}
157159

158160
async function downloadDependencyGraphs(): Promise<string[]> {
159-
const workspaceDirectory = getWorkspaceDirectory()
160-
161161
const findBy = github.context.payload.workflow_run
162162
? {
163163
token: getGithubToken(),
@@ -168,34 +168,37 @@ async function downloadDependencyGraphs(): Promise<string[]> {
168168
: undefined
169169

170170
const artifactClient = new DefaultArtifactClient()
171-
const downloadPath = path.resolve(workspaceDirectory, 'dependency-graph')
172171

173172
const dependencyGraphArtifacts = (
174173
await artifactClient.listArtifacts({
175174
latest: true,
176175
findBy
177176
})
178-
).artifacts.filter(candidate => candidate.name.startsWith(DEPENDENCY_GRAPH_PREFIX))
177+
).artifacts.filter(artifact => artifact.name.startsWith(DEPENDENCY_GRAPH_PREFIX))
179178

180179
for (const artifact of dependencyGraphArtifacts) {
181180
const downloadedArtifact = await artifactClient.downloadArtifact(artifact.id, {
182-
path: downloadPath,
183181
findBy
184182
})
185183
core.info(`Downloading dependency-graph artifact ${artifact.name} to ${downloadedArtifact.downloadPath}`)
186184
}
187185

188-
return findDependencyGraphFiles(downloadPath)
186+
return findDependencyGraphFiles()
189187
}
190188

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`)
193191
const allFiles = await globber.glob()
194192
const unprocessedFiles = allFiles.filter(file => !isProcessed(file))
195193
unprocessedFiles.forEach(markProcessed)
194+
core.info(`Found dependency graph files: ${unprocessedFiles.join(', ')}`)
196195
return unprocessedFiles
197196
}
198197

198+
function getReportDirectory(): string {
199+
return process.env.DEPENDENCY_GRAPH_REPORT_DIR!
200+
}
201+
199202
function isProcessed(dependencyGraphFile: string): boolean {
200203
const markerFile = `${dependencyGraphFile}.processed`
201204
return fs.existsSync(markerFile)

0 commit comments

Comments
 (0)