From 22818445b39b52b85c48e2255e87e43d35be3a4b Mon Sep 17 00:00:00 2001 From: daz Date: Tue, 16 Jul 2024 13:45:14 -0600 Subject: [PATCH 1/3] Restrict download-and-submit to selected file --- .github/workflows/integ-test-dependency-graph.yml | 6 ++++-- .../workflows/integ-test-dependency-submission.yml | 4 ++++ sources/src/configuration.ts | 4 ++++ sources/src/dependency-graph.ts | 12 +++++++++--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.github/workflows/integ-test-dependency-graph.yml b/.github/workflows/integ-test-dependency-graph.yml index 28cc0fa..3363b24 100644 --- a/.github/workflows/integ-test-dependency-graph.yml +++ b/.github/workflows/integ-test-dependency-graph.yml @@ -21,7 +21,7 @@ env: GITHUB_DEPENDENCY_GRAPH_REF: 'refs/tags/v0.0.1' # Use a different ref to avoid updating the real dependency graph for the repository jobs: - groovy-generate: + groovy-upload: strategy: fail-fast: false matrix: @@ -42,7 +42,7 @@ jobs: working-directory: .github/workflow-samples/groovy-dsl groovy-submit: - needs: [groovy-generate] + needs: [groovy-upload] runs-on: "ubuntu-latest" steps: - name: Checkout sources @@ -54,6 +54,8 @@ jobs: uses: ./setup-gradle with: dependency-graph: download-and-submit + env: + DEPENDENCY_GRAPH_DOWNLOAD_ARTIFACT_NAME: groovy-upload kotlin-generate-and-submit: strategy: diff --git a/.github/workflows/integ-test-dependency-submission.yml b/.github/workflows/integ-test-dependency-submission.yml index 88cc58d..3b8c160 100644 --- a/.github/workflows/integ-test-dependency-submission.yml +++ b/.github/workflows/integ-test-dependency-submission.yml @@ -80,6 +80,8 @@ jobs: uses: ./dependency-submission with: dependency-graph: download-and-submit + env: + DEPENDENCY_GRAPH_DOWNLOAD_ARTIFACT_NAME: groovy-generate-and-upload-${{ matrix.os }} kotlin-generate-and-submit: strategy: @@ -313,6 +315,8 @@ jobs: build-root-directory: .github/workflow-samples/groovy-dsl env: DEPENDENCY_GRAPH_REPORT_DIR: '${{ github.workspace }}/custom/report-dir' + DEPENDENCY_GRAPH_DOWNLOAD_ARTIFACT_NAME: custom-report-dir-upload + - name: Check downloaded dependency graph shell: bash run: | diff --git a/sources/src/configuration.ts b/sources/src/configuration.ts index 9282308..df3161b 100644 --- a/sources/src/configuration.ts +++ b/sources/src/configuration.ts @@ -49,6 +49,10 @@ export class DependencyGraphConfig { return path.resolve(getWorkspaceDirectory(), 'dependency-graph-reports') } + getDownloadArtifactName(): string | undefined { + return process.env['DEPENDENCY_GRAPH_DOWNLOAD_ARTIFACT_NAME'] + } + static constructJobCorrelator(workflow: string, jobId: string, matrixJson: string): string { const matrixString = this.describeMatrix(matrixJson) const label = matrixString ? `${workflow}-${jobId}-${matrixString}` : `${workflow}-${jobId}` diff --git a/sources/src/dependency-graph.ts b/sources/src/dependency-graph.ts index a06d2cb..5650158 100644 --- a/sources/src/dependency-graph.ts +++ b/sources/src/dependency-graph.ts @@ -77,7 +77,7 @@ async function downloadAndSubmitDependencyGraphs(config: DependencyGraphConfig): } try { - await submitDependencyGraphs(await downloadDependencyGraphs()) + await submitDependencyGraphs(await downloadDependencyGraphs(config)) } catch (e) { warnOrFail(config, DependencyGraphOption.DownloadAndSubmit, e) } @@ -111,7 +111,7 @@ async function findAndUploadDependencyGraphs(config: DependencyGraphConfig): Pro await uploadDependencyGraphs(await findDependencyGraphFiles(), config) } -async function downloadDependencyGraphs(): Promise { +async function downloadDependencyGraphs(config: DependencyGraphConfig): Promise { const findBy = github.context.payload.workflow_run ? { token: getGithubToken(), @@ -123,13 +123,19 @@ async function downloadDependencyGraphs(): Promise { const artifactClient = new DefaultArtifactClient() - const dependencyGraphArtifacts = ( + let dependencyGraphArtifacts = ( await artifactClient.listArtifacts({ latest: true, findBy }) ).artifacts.filter(artifact => artifact.name.startsWith(DEPENDENCY_GRAPH_PREFIX)) + const artifactName = config.getDownloadArtifactName() + if (artifactName) { + core.info(`Filtering for artifacts ending with ${artifactName}`) + dependencyGraphArtifacts = dependencyGraphArtifacts.filter(artifact => artifact.name.includes(artifactName)) + } + for (const artifact of dependencyGraphArtifacts) { const downloadedArtifact = await artifactClient.downloadArtifact(artifact.id, { findBy From 9a57bcca968f9adb139d5bd3454c5bedeb568d89 Mon Sep 17 00:00:00 2001 From: daz Date: Tue, 16 Jul 2024 14:34:28 -0600 Subject: [PATCH 2/3] Add test for combining setup-gradle and dependency-submission --- .../integ-test-dependency-submission.yml | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integ-test-dependency-submission.yml b/.github/workflows/integ-test-dependency-submission.yml index 3b8c160..32948a4 100644 --- a/.github/workflows/integ-test-dependency-submission.yml +++ b/.github/workflows/integ-test-dependency-submission.yml @@ -227,7 +227,7 @@ jobs: gradle-version: ${{ matrix.gradle }} build-root-directory: .github/workflow-samples/no-wrapper${{ matrix.build-root-suffix }} - after-setup-gradle: + with-setup-gradle: strategy: fail-fast: false matrix: @@ -246,6 +246,25 @@ jobs: uses: ./dependency-submission with: build-root-directory: .github/workflow-samples/groovy-dsl + - name: Check and delete generated dependency graph + shell: bash + run: | + if [ ! -e "${{ steps.dependency-submission.outputs.dependency-graph-file }}" ]; then + echo "Did not find generated dependency graph files" + exit 1 + fi + rm ${{ steps.dependency-submission.outputs.dependency-graph-file }}* + - name: Run Gradle build + run: ./gradlew build + working-directory: .github/workflow-samples/groovy-dsl + - name: Check no dependency graph is generated + shell: bash + run: | + if [ ! -z "$(ls -A dependency-graph-reports)" ]; then + echo "Expected no dependency graph files to be generated" + ls -l dependency-graph-reports + exit 1 + fi custom-report-dir-submit: strategy: From bb7a843511648bc4a28cfbd53bdc25a68544433e Mon Sep 17 00:00:00 2001 From: daz Date: Tue, 16 Jul 2024 21:03:12 -0600 Subject: [PATCH 3/3] Reset dependency-graph after submission Fixes #204 --- sources/src/dependency-submission/main.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sources/src/dependency-submission/main.ts b/sources/src/dependency-submission/main.ts index 0e560db..75c4668 100644 --- a/sources/src/dependency-submission/main.ts +++ b/sources/src/dependency-submission/main.ts @@ -1,3 +1,4 @@ +import * as core from '@actions/core' import * as setupGradle from '../setup-gradle' import * as gradle from '../execution/gradle' import * as dependencyGraph from '../dependency-graph' @@ -24,6 +25,9 @@ export async function run(): Promise { // Configure Gradle environment (Gradle User Home) await setupGradle.setup(new CacheConfig(), new BuildScanConfig()) + // Capture the enabled state of dependency-graph + const originallyEnabled = process.env['GITHUB_DEPENDENCY_GRAPH_ENABLED'] + // Configure the dependency graph submission const config = new DependencyGraphConfig() await dependencyGraph.setup(config) @@ -53,6 +57,9 @@ export async function run(): Promise { await dependencyGraph.complete(config) + // Reset the enabled state of dependency graph + core.exportVariable('GITHUB_DEPENDENCY_GRAPH_ENABLED', originallyEnabled) + saveDeprecationState() } catch (error) { handleMainActionError(error)