Skip to content

Commit 3254b08

Browse files
committed
Decouple inputs from default GitHub env vars
Instead of reading built-in GitHub environment variables directly, the caller must map these to environment variables defined explicitly for this plugin. This will allow us to use modified input parameters in GitHub Actions without overriding these built-in environment variable.
1 parent 0688904 commit 3254b08

File tree

6 files changed

+29
-26
lines changed

6 files changed

+29
-26
lines changed

.github/workflows/gradle.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ jobs:
7272
run: ./plugin-self-test ForceDependencyResolutionPlugin_resolveAllDependencies
7373
env:
7474
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75-
GITHUB_JOB_ID: ${{ github.run_id }}
76-
GITHUB_JOB_CORRELATOR: "plugin-self-test"
75+
GITHUB_DEPENDENCY_GRAPH_JOB_ID: ${{ github.run_id }}
76+
GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR: "plugin-self-test"
77+
GITHUB_DEPENDENCY_GRAPH_REF: ${{ github.ref }}
78+
GITHUB_DEPENDENCY_GRAPH_SHA: ${{ github.sha }}
79+
GITHUB_DEPENDENCY_GRAPH_WORKSPACE: ${{ github.workspace }}
7780

7881
- name: Save plugin JSON report
7982
uses: actions/upload-artifact@v3

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ This causes 2 separate plugins to be applied, that can be used independently:
3030
### Required environment variables
3131

3232
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:
33-
- `GITHUB_JOB_CORRELATOR`: Sets the `job.correlator` value for the dependency submission
34-
- `GITHUB_JOB_ID`: Sets the `job.id` value for the dependency submission
35-
- `GITHUB_REF`: Sets the `ref` value for the dependency submission
36-
- `GITHUB_SHA`: Sets the `sha` value for the dependency submission
37-
- `GITHUB_WORKSPACE`: Sets the root directory of the github repository
33+
- `GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR`: Sets the `job.correlator` value for the dependency submission
34+
- `GITHUB_DEPENDENCY_GRAPH_JOB_ID`: Sets the `job.id` value for the dependency submission
35+
- `GITHUB_DEPENDENCY_GRAPH_REF`: Sets the `ref` value for the commit that generated the dependency graph
36+
- `GITHUB_DEPENDENCY_GRAPH_SHA`: Sets the `sha` value for the commit that generated the dependency graph
37+
- `GITHUB_DEPENDENCY_GRAPH_WORKSPACE`: Sets the root directory of the github repository
3838
- `DEPENDENCY_GRAPH_REPORT_DIR` (optional): Specifies where the dependency graph report will be generated
3939

4040
Each of these values can also be provided via a system property.

plugin-self-test-local

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/sh
22

3-
export GITHUB_JOB_ID="42"
4-
export GITHUB_JOB_CORRELATOR="plugin-self-test"
5-
export GITHUB_REF="refs/heads/main"
6-
export GITHUB_SHA=$( git rev-parse HEAD )
7-
export GITHUB_WORKSPACE=$( pwd )
3+
export GITHUB_DEPENDENCY_GRAPH_JOB_ID="42"
4+
export GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR="plugin-self-test"
5+
export GITHUB_DEPENDENCY_GRAPH_REF="refs/heads/main"
6+
export GITHUB_DEPENDENCY_GRAPH_SHA=$( git rev-parse HEAD )
7+
export GITHUB_DEPENDENCY_GRAPH_WORKSPACE=$( pwd )
88

99
./plugin-self-test $*

plugin-test/src/test/groovy/org/gradle/github/dependencygraph/BaseExtractorTest.groovy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,12 @@ abstract class BaseExtractorTest extends Specification {
289289

290290
Map<String, String> asEnvironmentMap() {
291291
return [
292-
"GITHUB_JOB_ID" : jobId,
293-
"GITHUB_JOB_CORRELATOR": jobCorrelator,
292+
"GITHUB_DEPENDENCY_GRAPH_JOB_ID" : jobId,
293+
"GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR": jobCorrelator,
294294
"DEPENDENCY_GRAPH_REPORT_DIR" : reportDir,
295-
"GITHUB_REF" : ref,
296-
"GITHUB_SHA" : sha,
297-
"GITHUB_WORKSPACE" : workspace,
295+
"GITHUB_DEPENDENCY_GRAPH_REF" : ref,
296+
"GITHUB_DEPENDENCY_GRAPH_SHA" : sha,
297+
"GITHUB_DEPENDENCY_GRAPH_WORKSPACE" : workspace,
298298
"GITHUB_TOKEN" : gitHubToken
299299
]
300300
}

plugin-test/src/test/groovy/org/gradle/github/dependencygraph/DependencyExtractorConfigTest.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class DependencyExtractorConfigTest extends BaseExtractorTest {
3838

3939
when:
4040
executer
41-
.withArgument("-DGITHUB_JOB_CORRELATOR=TEST_CORRELATOR")
42-
.withArgument("-DGITHUB_REF=refs/my-branch/foo")
41+
.withArgument("-DGITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR=TEST_CORRELATOR")
42+
.withArgument("-DGITHUB_DEPENDENCY_GRAPH_REF=refs/my-branch/foo")
4343
run()
4444

4545
then:
@@ -81,11 +81,11 @@ class DependencyExtractorConfigTest extends BaseExtractorTest {
8181
def "fails gracefully if configuration values not set"() {
8282
when:
8383
def envVars = environmentVars.asEnvironmentMap()
84-
envVars.remove("GITHUB_JOB_CORRELATOR")
84+
envVars.remove("GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR")
8585
executer.withEnvironmentVars(envVars)
8686
def result = executer.runWithFailure()
8787

8888
then:
89-
result.output.contains("'GITHUB_JOB_CORRELATOR' must be set")
89+
result.output.contains("'GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR' must be set")
9090
}
9191
}

plugin/src/main/kotlin/org/gradle/github/dependencygraph/GitHubSnapshotParams.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import org.gradle.dependencygraph.util.PluginParameters
44
import java.nio.file.Path
55
import java.nio.file.Paths
66

7-
const val PARAM_JOB_ID = "GITHUB_JOB_ID"
8-
const val PARAM_JOB_CORRELATOR = "GITHUB_JOB_CORRELATOR"
9-
const val PARAM_GITHUB_REF = "GITHUB_REF"
10-
const val PARAM_GITHUB_SHA = "GITHUB_SHA"
7+
const val PARAM_JOB_ID = "GITHUB_DEPENDENCY_GRAPH_JOB_ID"
8+
const val PARAM_JOB_CORRELATOR = "GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR"
9+
const val PARAM_GITHUB_REF = "GITHUB_DEPENDENCY_GRAPH_REF"
10+
const val PARAM_GITHUB_SHA = "GITHUB_DEPENDENCY_GRAPH_SHA"
1111
/**
1212
* Environment variable should be set to the workspace directory that the Git repository is checked out in.
1313
* This is used to determine relative path to build files referenced in the dependency graph.
1414
*/
15-
const val PARAM_GITHUB_WORKSPACE = "GITHUB_WORKSPACE"
15+
const val PARAM_GITHUB_WORKSPACE = "GITHUB_DEPENDENCY_GRAPH_WORKSPACE"
1616

1717
class GitHubSnapshotParams(private val pluginParameters: PluginParameters) {
1818
val dependencyGraphJobCorrelator: String = pluginParameters.load(PARAM_JOB_CORRELATOR)

0 commit comments

Comments
 (0)