You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 21, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+7-340Lines changed: 7 additions & 340 deletions
Original file line number
Diff line number
Diff line change
@@ -479,348 +479,15 @@ You can use the `gradle-build-action` on GitHub Enterprise Server, and benefit f
479
479
480
480
# GitHub Dependency Graph support
481
481
482
-
The `gradle-build-action` has support for submitting a [GitHub Dependency Graph](https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-the-dependency-graph) snapshot via the [GitHub Dependency Submission API](https://docs.github.com/en/rest/dependency-graph/dependency-submission?apiVersion=2022-11-28).
483
-
484
-
The dependency graph snapshot is generated via integration with the [GitHub Dependency Graph Gradle Plugin](https://plugins.gradle.org/plugin/org.gradle.github-dependency-graph-gradle-plugin), and saved as a workflow artifact. The generated snapshot files can be submitted either in the same job, or in a subsequent job (in the same or a dependent workflow).
485
-
486
-
The generated dependency graph snapshot reports all of the dependencies that were resolved during a build execution, and is used by GitHub to generate [Dependabot Alerts](https://docs.github.com/en/code-security/dependabot/dependabot-alerts/about-dependabot-alerts) for vulnerable dependencies, as well as to populate the [Dependency Graph insights view](https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/exploring-the-dependencies-of-a-repository#viewing-the-dependency-graph).
487
-
488
-
## Enable Dependency Graph generation for a workflow
489
-
490
-
You enable GitHub Dependency Graph support by setting the `dependency-graph` action parameter. Valid values are:
491
-
492
-
| Option | Behaviour |
493
-
| --- | --- |
494
-
| `disabled` | Do not generate a dependency graph for any build invocations.<p>This is the default. |
495
-
| `generate` | Generate a dependency graph snapshot for each build invocation. |
496
-
| `generate-and-submit` | Generate a dependency graph snapshot for each build invocation, and submit these via the Dependency Submission API on completion of the job. |
497
-
| `generate-and-upload` | Generate a dependency graph snapshot for each build invocation, saving as a workflow artifact. |
498
-
| `download-and-submit` | Download any previously saved dependency graph snapshots, and submit them via the Dependency Submission API. This can be useful to submit [dependency graphs for pull requests submitted from a repository forks](#dependency-graphs-for-pull-request-workflows). |
499
-
500
-
Example of a CI workflow that generates and submits a dependency graph:
501
-
```yaml
502
-
name: CI build
503
-
on:
504
-
push:
505
-
506
-
permissions:
507
-
contents: write
508
-
509
-
jobs:
510
-
build:
511
-
runs-on: ubuntu-latest
512
-
steps:
513
-
- uses: actions/checkout@v4
514
-
- name: Setup Gradle to generate and submit dependency graphs
515
-
uses: gradle/gradle-build-action@v2
516
-
with:
517
-
dependency-graph: generate-and-submit
518
-
- name: Run the usual CI build (dependency-graph will be generated and submitted post-job)
519
-
run: ./gradlew build
520
-
```
521
-
522
-
The `contents: write` permission is required in order to submit (but not generate) the dependency graph file.
523
-
Depending on [repository settings](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token), this permission may be available by default or may need to be explicitly enabled in the workflow file (as above).
524
-
525
482
> [!IMPORTANT]
526
-
> The above configuration will work for workflows that run as a result of commits to a repository branch,
527
-
> but not when a workflow is triggered by a PR from a repository fork.
528
-
> This is because the `contents: write` permission is not available when executing a workflow
529
-
> for a PR submitted from a forked repository.
530
-
> For a configuration that supports this setup, see [Dependency Graphs for pull request workflows](#dependency-graphs-for-pull-request-workflows).
531
-
532
-
### Making dependency graph failures cause Job failures
533
-
534
-
By default, if a failure is encountered when generating or submitting the dependency graph, the action will log the failure as a warning and continue.
535
-
This allows your workflow to be resilient to dependency graph failures, in case dependency graph production is a side-effect rather than the primary purpose of a workflow.
536
-
537
-
If instead you have a workflow that has a primary purpose to generate and submit a dependency graph, then it makes sense for this workflow to fail if the dependency
538
-
graph cannot be generated or submitted. You can enable this behaviour with the `dependency-graph-continue-on-failure` parameter, which defaults to `true`.
539
-
540
-
```yaml
541
-
# Ensure that the workflow Job will fail if the dependency graph cannot be submitted
542
-
- uses: gradle/gradle-build-action@v3
543
-
with:
544
-
dependency-graph: generate-and-submit
545
-
dependency-graph-continue-on-failure: false
546
-
```
547
-
548
-
### Using a custom plugin repository
549
-
550
-
By default, the action downloads the `github-dependency-graph-gradle-plugin` from the Gradle Plugin Portal (https://plugins.gradle.org). If your GitHub Actions environment does not have access to this URL, you can specify a custom plugin repository to use.
551
-
Do so by setting the `GRADLE_PLUGIN_REPOSITORY_URL` environment variable with your Gradle invocation.
552
-
553
-
```yaml
554
-
jobs:
555
-
build:
556
-
runs-on: ubuntu-latest
557
-
steps:
558
-
- uses: actions/checkout@v4
559
-
- name: Setup Gradle to generate and submit dependency graphs
560
-
uses: gradle/gradle-build-action@v2
561
-
with:
562
-
dependency-graph: generate-and-submit
563
-
- name: Run a build, resolving the 'dependency-graph' plugin from the plugin portal proxy
The GitHub [dependency-review-action](https://github.com/actions/dependency-review-action) helps you
572
-
understand dependency changes (and the security impact of these changes) for a pull request.
573
-
For the `dependency-review-action` to succeed, it must run _after_ the dependency graph has been submitted for a PR.
574
-
575
-
When using `generate-and-submit`, dependency graph files are submitted at the end of the job, after all steps have been
576
-
executed. For this reason, the `dependency-review-action` must be executed in a dependent job,
577
-
and not as a subsequent step in the job that generates the dependency graph.
578
-
579
-
Example of a pull request workflow that executes a build for a pull request and runs the `dependency-review-action`:
580
-
581
-
```yaml
582
-
name: PR check
583
-
584
-
on:
585
-
pull_request:
586
-
587
-
permissions:
588
-
contents: write
589
-
# Note that this permission will not be available if the PR is from a forked repository
590
-
591
-
jobs:
592
-
build:
593
-
runs-on: ubuntu-latest
594
-
steps:
595
-
- uses: actions/checkout@v4
596
-
- name: Setup Gradle to generate and submit dependency graphs
597
-
uses: gradle/gradle-build-action@v2
598
-
with:
599
-
dependency-graph: generate-and-submit
600
-
- name: Run a build and generate the dependency graph which will be submitted post-job
601
-
run: ./gradlew build
602
-
603
-
dependency-review:
604
-
needs: build
605
-
runs-on: ubuntu-latest
606
-
- name: Perform dependency review
607
-
uses: actions/dependency-review-action@v4
608
-
```
609
-
610
-
See [Dependency Graphs for pull request workflows](#dependency-graphs-for-pull-request-workflows) for a more complex
611
-
(and less functional) example that will work for pull requests submitted from forked repositories.
612
-
613
-
## Limiting the scope of the dependency graph
614
-
615
-
At times it is helpful to limit the dependencies reported to GitHub, in order to security alerts for dependencies that don't form a critical part of your product.
616
-
For example, a vulnerability in the tool you use to generate documentation is unlikely to be as important as a vulnerability in one of your runtime dependencies.
617
-
618
-
There are a number of techniques you can employ to limit the scope of the generated dependency graph:
619
-
- [Don't generate a dependency graph for all Gradle executions](#choosing-which-gradle-invocations-will-generate-a-dependency-graph)
620
-
- [For a Gradle execution, filter which Gradle projects and configurations will contribute dependencies](#filtering-which-gradle-configurations-contribute-to-the-dependency-graph)
621
-
- [Use a separate workflow that only resolves the required dependencies](#use-a-dedicated-workflow-for-dependency-graph-generation)
622
-
623
-
> [!NOTE]
624
-
> Ideally, all dependencies involved in building and testing a project will be extracted and reported in a dependency graph.
625
-
> These dependencies would be assigned to different scopes (eg development, runtime, testing) and the GitHub UI would make it easy to opt-in to security alerts for different dependency scopes.
626
-
> However, this functionality does not yet exist.
627
-
628
-
### Choosing which Gradle invocations will generate a dependency graph
629
-
630
-
Once you enable the dependency graph support for a workflow job (via the `dependency-graph` parameter), dependencies will be collected and reported for all subsequent Gradle invocations.
631
-
If you have a Gradle build step that you want to exclude from dependency graph generation, you can set the `GITHUB_DEPENDENCY_GRAPH_ENABLED` environment variable to `false`.
632
-
633
-
```yaml
634
-
jobs:
635
-
build:
636
-
runs-on: ubuntu-latest
637
-
steps:
638
-
- uses: actions/checkout@v4
639
-
- name: Setup Gradle to generate and submit dependency graphs
640
-
uses: gradle/gradle-build-action@v2
641
-
with:
642
-
dependency-graph: generate-and-submit
643
-
- name: Build the app, generating a graph of dependencies required
644
-
run: ./gradlew :my-app:assemble
645
-
- name: Run all checks, disabling dependency graph generation
646
-
run: ./gradlew check
647
-
env:
648
-
GITHUB_DEPENDENCY_GRAPH_ENABLED: false
649
-
```
650
-
651
-
### Filtering which Gradle Configurations contribute to the dependency graph
652
-
653
-
If you do not want the dependency graph to include every dependency configuration in every project in your build, you can limit the
654
-
dependency extraction to a subset of these.
655
-
656
-
To restrict which Gradle subprojects contribute to the report, specify which projects to include via a regular expression.
657
-
You can provide this value via the `DEPENDENCY_GRAPH_INCLUDE_PROJECTS` environment variable or system property.
658
-
659
-
To restrict which Gradle configurations contribute to the report, you can filter configurations by name using a regular expression.
660
-
You can provide this value via the `DEPENDENCY_GRAPH_INCLUDE_CONFIGURATIONS` environment variable or system property.
661
-
662
-
For example, if you want to exclude dependencies in the `buildSrc` project, and only report on dependencies from the `runtimeClasspath` configuration,
663
-
you would use the following configuration:
664
-
665
-
```yaml
666
-
jobs:
667
-
build:
668
-
runs-on: ubuntu-latest
669
-
steps:
670
-
- uses: actions/checkout@v4
671
-
- name: Setup Gradle to generate and submit dependency graphs
672
-
uses: gradle/gradle-build-action@v2
673
-
with:
674
-
dependency-graph: generate-and-submit
675
-
- name: Run a build, generating the dependency graph from any resolved 'runtimeClasspath' configurations
### Use a dedicated workflow for dependency graph generation
683
-
684
-
Instead of generating a dependency graph from your existing CI workflow, it's possible to create a separate dedicated workflow (or Job) that is intended for generating a dependency graph.
685
-
Such a workflow will still need to execute Gradle, but can do so in a way that is targeted at resolving the specific dependencies required.
686
-
687
-
For example, the following workflow will report those dependencies that are resolved in order to build the `distributionZip` for the `my-app` project. Test dependencies and other dependencies not required by the `distributionZip` will not be included.
688
-
689
-
```yaml
690
-
jobs:
691
-
build:
692
-
runs-on: ubuntu-latest
693
-
steps:
694
-
- uses: actions/checkout@v4
695
-
- name: Setup Gradle to generate and submit dependency graphs
696
-
uses: gradle/gradle-build-action@v2
697
-
with:
698
-
dependency-graph: generate-and-submit
699
-
- name: Build the distribution Zip for `my-app`
700
-
run: ./gradlew :my-app:distributionZip
701
-
```
702
-
703
-
Note that the above example will also include any `buildSrc` dependencies, dependencies resolved when configuring your Gradle build or dependencies resolved while applying plugin. All of these dependencies are resolved in the process of running the `distributionZip` task, and thus will form part of the generated dependency graph.
704
-
705
-
If this isn't desirable, you will still need to use the filtering mechanism described above.
706
-
707
-
## Dependency Graphs for pull request workflows
708
-
709
-
This `contents: write` permission is not available for any workflow that is triggered by a pull request submitted from a forked repository, since it would permit a malicious pull request to make repository changes.
710
-
711
-
Because of this restriction, it is not possible to `generate-and-submit` a dependency graph generated for a pull-request that comes from a repository fork. In order to do so, 2 workflows will be required:
712
-
1. The first workflow runs directly against the pull request sources and will generate the dependency graph snapshot.
713
-
2. The second workflow is triggered on `workflow_run` of the first workflow, and will submit the previously saved dependency snapshots.
714
-
715
-
Note: when `download-and-submit` is used in a workflow triggered via [workflow_run](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run), the action will download snapshots saved in the triggering workflow.
716
-
717
-
***Main workflow file***
718
-
```yaml
719
-
name: run-build-and-generate-dependency-snapshot
720
-
721
-
on:
722
-
pull_request:
723
-
724
-
permissions:
725
-
contents: read
726
-
727
-
jobs:
728
-
build:
729
-
runs-on: ubuntu-latest
730
-
steps:
731
-
- uses: actions/checkout@v4
732
-
- name: Setup Gradle to generate and submit dependency graphs
733
-
uses: gradle/gradle-build-action@v2
734
-
with:
735
-
dependency-graph: generate-and-upload # Generate graphs and save as workflow artifacts
736
-
- name: Run a build, generating the dependency graph snapshot which will be submitted
- name: Retrieve dependency graph artifact and submit
757
-
uses: gradle/gradle-build-action@v2
758
-
with:
759
-
dependency-graph: download-and-submit # Download saved workflow artifacts and submit
760
-
```
761
-
762
-
### Integrating `dependency-review-action` for pull request workflows
763
-
764
-
The GitHub [dependency-review-action](https://github.com/actions/dependency-review-action) helps you
765
-
understand dependency changes (and the security impact of these changes) for a pull request.
766
-
767
-
To integrate the `dependency-review-action` into the pull request workflows above, a separate workflow should be added.
768
-
This workflow will be triggered directly on `pull_request`, but will need to wait until the dependency graph results are
769
-
submitted before the dependency review can complete. How long to wait is controlled by the `retry-on-snapshot-warnings` input parameters.
770
-
771
-
Here's an example of a separate "Dependency Review" workflow that will wait for 10 minutes for the PR check workflow to complete.
772
-
773
-
```yaml
774
-
name: dependency-review
775
-
on:
776
-
pull_request:
777
-
778
-
permissions:
779
-
contents: read
780
-
pull-requests: write
781
-
782
-
jobs:
783
-
dependency-review:
784
-
runs-on: ubuntu-latest
785
-
steps:
786
-
- name: 'Dependency Review'
787
-
uses: actions/dependency-review-action@v4
788
-
with:
789
-
retry-on-snapshot-warnings: true
790
-
retry-on-snapshot-warnings-timeout: 600
791
-
```
792
-
793
-
The `retry-on-snapshot-warnings-timeout` (in seconds) needs to be long enough to allow the entire `run-build-and-generate-dependency-snapshot` and `submit-dependency-snapshot` workflows (above) to complete.
794
-
795
-
## Gradle version compatibility
796
-
797
-
The GitHub Dependency Graph plugin should be compatible with all versions of Gradle >= 5.0, and has been tested against
798
-
Gradle versions "5.6.4", "6.9.4", "7.0.2", "7.6.2", "8.0.2" and the current Gradle release.
799
-
800
-
The plugin is compatible with running Gradle with the configuration-cache enabled. However, this support is
801
-
limited to Gradle "8.1.0" and later:
802
-
- With Gradle "8.0", the build should run successfully, but an empty dependency graph will be generated.
803
-
- With Gradle <= "7.6.4", the plugin will cause the build to fail with configuration-cache enabled.
804
-
805
-
To use this plugin with versions of Gradle older than "8.1.0", you'll need to invoke Gradle with the
806
-
configuration-cache disabled.
807
-
808
-
## Reducing storage costs for saved dependency graph artifacts
809
-
810
-
When `generate` or `generate-and-submit` is used with the action, the dependency graph that is generated is stored as a workflow artifact.
811
-
By default, these artifacts are retained for a period of 30 days (or as configured for the repository).
812
-
To reduce storage costs for these artifacts, you can set the `artifact-retention-days` value to a lower number.
813
-
814
-
```yaml
815
-
steps:
816
-
- name: Generate dependency graph, but only retain artifact for one day
817
-
uses: gradle/gradle-build-action@v2
818
-
with:
819
-
dependency-graph: generate
820
-
artifact-retention-days: 1
821
-
```
822
-
483
+
> The simplest (and recommended) way to generate a dependency graph is via a separate workflow
484
+
> using `gradle/actions/dependency-submission`. This action will attempt to detect all dependencies used by your build
485
+
> without building and testing the project itself.
486
+
>
487
+
> See the [dependency-submission documentation](https://github.com/gradle/actions/blob/main/dependency-submission/README.md) for up-to-date documentation.
823
488
489
+
For documentation on directly generating a dependency graph from a Gradle execution, see the
490
+
[setup-gradle docs](https://github.com/gradle/actions/blob/main/setup-gradle/README.md#github-dependency-graph-support) on this topic.
0 commit comments