Skip to content

GitHub Detector can be customized with env vars #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,25 @@ This causes 2 separate plugins to be applied, that can be used independently:
- `GitHubDependencyExtractorPlugin` collects all dependencies that are resolved during a build execution and writes these to a file. The output file can be found at `<root>/build/reports/github-depenency-graph-snapshots/<job-correlator>.json`.
- `ForceDependencyResolutionPlugin` creates a `ForceDependencyResolutionPlugin_resolveAllDependencies` task that will attempt to resolve all dependencies for a Gradle build, by simply invoking `dependencies` on all projects.

### Required environment variables
### Environment variables

The following environment variables configure the snapshot generated by the `GitHubDependencyExtractorPlugin`. See the [GitHub Dependency Submission API docs](https://docs.github.com/en/rest/dependency-graph/dependency-submission?apiVersion=2022-11-28) for details:

#### Required environment variables

- `GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR`: Sets the `job.correlator` value for the dependency submission
- `GITHUB_DEPENDENCY_GRAPH_JOB_ID`: Sets the `job.id` value for the dependency submission
- `GITHUB_DEPENDENCY_GRAPH_REF`: Sets the `ref` value for the commit that generated the dependency graph
- `GITHUB_DEPENDENCY_GRAPH_SHA`: Sets the `sha` value for the commit that generated the dependency graph
- `GITHUB_DEPENDENCY_GRAPH_WORKSPACE`: Sets the root directory of the github repository. Must be an absolute path.
- `DEPENDENCY_GRAPH_REPORT_DIR` (optional): Specifies where the dependency graph report will be generated. Must be an absolute path.

#### Optional environment variables

- `GITHUB_DEPENDENCY_GRAPH_DETECTOR_NAME`: Sets the `detector.name` value for the dependency submission. Defaults to `GitHub Dependency Graph Gradle Plugin`
- `GITHUB_DEPENDENCY_GRAPH_DETECTOR_VERSION`: Sets the `detector.version` value for the dependency submission. Defaults to current version of the plugin.
- `GITHUB_DEPENDENCY_GRAPH_DETECTOR_URL`: Sets the `detector.url` value for the dependency submission. Defaults to `https://github.com/gradle/github-dependency-graph-gradle-plugin`

Each of these values can also be provided via a system property.
eg: Env var `DEPENDENCY_GRAPH_REPORT_DIR` can be set with `-DDEPENDENCY_GRAPH_REPORT_DIR=...` on the command-line.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ class GitHubRepositorySnapshotBuilder(
private val snapshotParams: GitHubSnapshotParams
) {

private val detector by lazy { GitHubDetector() }
private val detector by lazy {
GitHubDetector(
name = snapshotParams.githubDetectorName,
version = snapshotParams.githubDetectorVersion,
url = snapshotParams.githubDetectorUrl
)
}

private val job by lazy {
GitHubJob(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const val PARAM_JOB_ID = "GITHUB_DEPENDENCY_GRAPH_JOB_ID"
const val PARAM_JOB_CORRELATOR = "GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR"
const val PARAM_GITHUB_REF = "GITHUB_DEPENDENCY_GRAPH_REF"
const val PARAM_GITHUB_SHA = "GITHUB_DEPENDENCY_GRAPH_SHA"
const val PARAM_GITHUB_DETECTOR_NAME = "GITHUB_DEPENDENCY_GRAPH_DETECTOR_NAME"
const val PARAM_GITHUB_DETECTOR_VERSION = "GITHUB_DEPENDENCY_GRAPH_DETECTOR_VERSION"
const val PARAM_GITHUB_DETECTOR_URL = "GITHUB_DEPENDENCY_GRAPH_DETECTOR_URL"
/**
* Environment variable should be set to the workspace directory that the Git repository is checked out in.
* This is used to determine relative path to build files referenced in the dependency graph.
Expand All @@ -16,9 +19,15 @@ const val PARAM_GITHUB_WORKSPACE = "GITHUB_DEPENDENCY_GRAPH_WORKSPACE"

class GitHubSnapshotParams(pluginParameters: PluginParameters) {
val dependencyGraphJobCorrelator: String = pluginParameters.load(PARAM_JOB_CORRELATOR)
val dependencyGraphJobId: String =pluginParameters.load(PARAM_JOB_ID)
val dependencyGraphJobId: String = pluginParameters.load(PARAM_JOB_ID)
val gitSha: String = pluginParameters.load(PARAM_GITHUB_SHA)
val gitRef: String = pluginParameters.load(PARAM_GITHUB_REF)
val gitHubWorkspace: Path = Paths.get(pluginParameters.load(PARAM_GITHUB_WORKSPACE))
val githubDetectorName: String = pluginParameters.loadOptional(PARAM_GITHUB_DETECTOR_NAME)
?: javaClass.`package`.implementationTitle
val githubDetectorVersion: String = pluginParameters.loadOptional(PARAM_GITHUB_DETECTOR_VERSION)
?: javaClass.`package`.implementationVersion
val githubDetectorUrl: String = pluginParameters.loadOptional(PARAM_GITHUB_DETECTOR_URL)
?: "https://github.com/gradle/github-dependency-graph-gradle-plugin"
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.gradle.github.dependencygraph.model

data class GitHubDetector(
val name: String = GitHubDetector::class.java.`package`.implementationTitle,
val version: String = GitHubDetector::class.java.`package`.implementationVersion,
val url: String = "https://github.com/gradle/github-dependency-graph-gradle-plugin"
val name: String,
val version: String,
val url: String
)