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
+117Lines changed: 117 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -408,3 +408,120 @@ You can use the `gradle-build-action` on GitHub Enterprise Server, and benefit f
408
408
- Easily run your build with different versions of Gradle
409
409
- Save/restore of Gradle User Home (requires GHES v3.5+ : GitHub Actions cache was introduced in GHES 3.5)
410
410
- Support for GitHub Actions Job Summary (requires GHES 3.6+ : GitHub Actions Job Summary support was introduced in GHES 3.6). In earlier versions of GHES the build-results summary and caching report will be written to the workflow log, as part of the post-action step.
411
+
412
+
# GitHub Dependency Graph support (Experimental)
413
+
414
+
The `gradle-build-action` has experimental 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).
415
+
416
+
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).
417
+
418
+
You enable GitHub Dependency Graph support by setting the `dependency-graph` action parameter. Valid values are:
| `disabled` | Do not generate a dependency graph for any build invocations.<p>This is the default. |
423
+
| `generate` | Generate a dependency graph snapshot for each build invocation, saving as a workflow artifact. |
424
+
| `generate-and-submit` | As per `generate`, but any generated dependency graph snapshots will be submitted at the end of the job. |
425
+
| `download-and-submit` | Download any previously saved dependency graph snapshots, submitting them via the Dependency Submission API. This can be useful to collect all snapshots in a matrix of builds and submit them in one step. |
426
+
427
+
- 'disabled': Do not generate a dependency graph for any build invocations. This is the default.
428
+
- 'generate': Generate a dependency graph snapshot for each build invocation, saving as a workflow artifact.
429
+
- 'generate-and-submit': As per 'generate', but any generated dependency graph snapshots will be submitted at the end of the job.
430
+
- 'download-and-submit': Download any previously saved dependency graph snapshots, submitting them via the Dependency Submission API. This can be useful to collect all snapshots in a matrix of builds and submit them in one step.
431
+
432
+
Dependency Graph _submission_ (but not generation) requires the `contents: write` permission, which may need to be explicitly enabled in the workflow file.
433
+
434
+
Example of a simple workflow that generates and submits a dependency graph:
435
+
```yaml
436
+
name: Submit dependency graph
437
+
on:
438
+
push:
439
+
440
+
permissions:
441
+
contents: write
442
+
443
+
jobs:
444
+
build:
445
+
runs-on: ubuntu-latest
446
+
steps:
447
+
- uses: actions/checkout@v3
448
+
- name: Setup Gradle to generate and submit dependency graphs
449
+
uses: gradle/gradle-build-action@dependency-graph
450
+
with:
451
+
dependency-graph: generate-and-submit
452
+
- name: Run a build, generating the dependency graph snapshot which will be submitted
453
+
run: ./gradlew build
454
+
```
455
+
456
+
### Running multiple builds in a single Job
457
+
458
+
GitHub tracks dependency snapshots based on the `job.correlator` value that is embedded in the snapshot. When a newer snapshot for an existing correlator is submitted, the previous snapshot is replaced. Snapshots with different `job.correlator` values are additive to the overall dependency graph for the repository.
459
+
460
+
The `gradle-build-action` will generate a `job.correlator` value based on the workflow name, job id and matrix values. However, if your job steps contains multiple Gradle invocations, then a unique correlator value must be assigned to each. You assign a correlator by setting the `GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR` environment variable.
461
+
462
+
```yaml
463
+
name: dependency-graph
464
+
jobs:
465
+
build:
466
+
runs-on: ubuntu-latest
467
+
steps:
468
+
- uses: actions/checkout@v3
469
+
- name: Setup Gradle to generate and submit dependency graphs
470
+
uses: gradle/gradle-build-action@dependency-graph
471
+
with:
472
+
dependency-graph: generate-and-submit
473
+
- name: Run first build using the default job correlator 'dependency-graph-build'
474
+
run: ./gradlew build
475
+
- name: Run second build providing a unique job correlator
### Dependency snapshots generated for pull requests
483
+
484
+
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.
485
+
486
+
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:
487
+
1. The first workflow runs directly against the pull request sources and will generate the dependency graph snapshot.
488
+
2. The second workflow is triggered on `workflow_run` of the first workflow, and will submit the previously saved dependency snapshots.
489
+
490
+
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.
491
+
492
+
***Main workflow file***
493
+
```yaml
494
+
name: run-build-and-generate-dependency-snapshot
495
+
496
+
jobs:
497
+
build:
498
+
runs-on: ubuntu-latest
499
+
steps:
500
+
- uses: actions/checkout@v3
501
+
- name: Setup Gradle to generate and submit dependency graphs
502
+
uses: gradle/gradle-build-action@v2
503
+
with:
504
+
dependency-graph: generate # Only generate in this job
505
+
- name: Run a build, generating the dependency graph snapshot which will be submitted
0 commit comments