Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.

Commit e3426b1

Browse files
authored
Merge pull request #857 from gradle/dd/inject-ge
Add support for Gradle Enterprise injection into Gradle Builds
2 parents a617adb + d79398d commit e3426b1

20 files changed

+760
-31
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Required to keep dependabot happy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'no-ge'

.github/workflows/ci-full-check.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ jobs:
4444
with:
4545
cache-key-prefix: ${{github.run_number}}-
4646

47+
gradle-enterprise-injection:
48+
uses: ./github/workflows/integ-test-inject-gradle-enterprise.yml
49+
with:
50+
cache-key-prefix: ${{github.run_number}}-
51+
4752
provision-gradle-versions:
4853
uses: ./.github/workflows/integ-test-provision-gradle-versions.yml
4954
with:

.github/workflows/ci-quick-check.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ jobs:
7171
runner-os: '["ubuntu-latest"]'
7272
download-dist: true
7373

74+
gradle-enterprise-injection:
75+
needs: build-distribution
76+
uses: ./github/workflows/integ-test-inject-gradle-enterprise.yml
77+
with:
78+
runner-os: '["ubuntu-latest"]'
79+
download-dist: true
80+
7481
provision-gradle-versions:
7582
needs: build-distribution
7683
uses: ./.github/workflows/integ-test-provision-gradle-versions.yml
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Test gradle enterprise injection
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
cache-key-prefix:
7+
type: string
8+
runner-os:
9+
type: string
10+
default: '["ubuntu-latest", "windows-latest", "macos-latest"]'
11+
download-dist:
12+
type: boolean
13+
default: false
14+
15+
env:
16+
DOWNLOAD_DIST: ${{ inputs.download-dist }}
17+
GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: provision-gradle-versions-${{ inputs.cache-key-prefix }}
18+
GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED: true
19+
GRADLE_ENTERPRISE_INJECTION_ENABLED: true
20+
GRADLE_ENTERPRISE_INJECTION_SERVER_URL: https://ge.solutions-team.gradle.com
21+
GRADLE_ENTERPRISE_INJECTION_GE_PLUGIN_VERSION: 3.14.1
22+
GRADLE_ENTERPRISE_INJECTION_CCUD_PLUGIN_VERSION: 1.11.1
23+
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GE_SOLUTIONS_ACCESS_TOKEN }}
24+
25+
jobs:
26+
inject-gradle-enterprise:
27+
strategy:
28+
matrix:
29+
gradle: [current, 7.6.2, 6.9.4, 5.6.4]
30+
os: ${{fromJSON(inputs.runner-os)}}
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout sources
34+
uses: actions/checkout@v3
35+
- name: Download distribution if required
36+
uses: ./.github/actions/download-dist
37+
- name: Setup Java
38+
uses: actions/setup-java@v3
39+
with:
40+
distribution: temurin
41+
java-version: 8
42+
- name: Setup Gradle
43+
id: setup-gradle
44+
uses: ./
45+
with:
46+
cache-read-only: false # For testing, allow writing cache entries on non-default branches
47+
gradle-version: ${{ matrix.gradle }}
48+
- name: Run Gradle build
49+
id: gradle
50+
working-directory: .github/workflow-samples/no-ge
51+
run: gradle help
52+
- name: Check Build Scan url
53+
if: ${{ !steps.gradle.outputs.build-scan-url }}
54+
uses: actions/github-script@v6
55+
with:
56+
script: |
57+
core.setFailed('No Build Scan detected')

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,3 +725,55 @@ limited to Gradle "8.1.0" and later:
725725

726726
To use this plugin with versions of Gradle older than "8.1.0", you'll need to invoke Gradle with the
727727
configuration-cache disabled.
728+
729+
# Gradle Enterprise plugin injection
730+
731+
The `gradle-build-action` provides support for injecting and configuring the Gradle Enterprise Gradle plugin into any Gradle build, without any modification to the project sources.
732+
This is achieved via an init-script installed into Gradle User Home, which is enabled and parameterized via environment variables.
733+
734+
The same auto-injection behavior is available for the Common Custom User Data Gradle plugin, which enriches any build scans published with additional useful information.
735+
736+
## Enabling Gradle Enterprise injection
737+
738+
In order to enable Gradle Enterprise for your build, you must provide the required configuration via environment variables.
739+
740+
Here's a minimal example:
741+
742+
```yaml
743+
name: Run build with Gradle Enterprise injection
744+
745+
env:
746+
GRADLE_ENTERPRISE_INJECTION_ENABLED: true
747+
GRADLE_ENTERPRISE_INJECTION_SERVER_URL: https://ge.gradle.org
748+
GRADLE_ENTERPRISE_INJECTION_GE_PLUGIN_VERSION: 3.14.1
749+
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GE_ACCESS_KEY }} # Required to publish scans to ge.gradle.org
750+
751+
jobs:
752+
build:
753+
runs-on: ubuntu-latest
754+
steps:
755+
- uses: actions/checkout@v3
756+
- name: Setup Gradle
757+
uses: gradle/gradle-build-action@v2
758+
- name: Run a Gradle build with Gradle Enterprise injection enabled
759+
run: ./gradlew build
760+
```
761+
762+
This configuration will automatically apply `v3.14.1` of the [Gradle Enterprise Gradle plugin](https://docs.gradle.com/enterprise/gradle-plugin/), and publish build scans to https://ge.gradle.org.
763+
764+
Note that the `ge.gradle.org` server requires authentication in order to publish scans. The provided `GRADLE_ENTERPRISE_ACCESS_KEY` isn't required by the Gradle Enterprise injection script,
765+
but will be used by the GE plugin in order to authenticate with the server.
766+
767+
## Configuring Gradle Enterprise injection
768+
769+
The `init-script` supports a number of additional configuration parameters that you may fine useful. All configuration options (required and optional) are detailed below:
770+
771+
| Variable | Required | Description |
772+
| --- | --- | --- |
773+
| GRADLE_ENTERPRISE_INJECTION_ENABLED | :white_check_mark: | enables Gradle Enterprise injection |
774+
| GRADLE_ENTERPRISE_INJECTION_SERVER_URL | :white_check_mark: | the URL of the Gradle Enterprise server |
775+
| GRADLE_ENTERPRISE_INJECTION_ALLOW_UNTRUSTED_SERVER | | allow communication with an untrusted server; set to _true_ if your Gradle Enterprise instance is using a self-signed certificate |
776+
| GRADLE_ENTERPRISE_INJECTION_ENFORCE_SERVER_URL | | enforce the configured Gradle Enterprise URL over a URL configured in the project's build; set to _true_ to enforce publication of build scans to the configured Gradle Enterprise URL |
777+
| GRADLE_ENTERPRISE_INJECTION_GE_PLUGIN_VERSION | :white_check_mark: | the version of the [Gradle Enterprise Gradle plugin](https://docs.gradle.com/enterprise/gradle-plugin/) to apply |
778+
| GRADLE_ENTERPRISE_INJECTION_CCUD_PLUGIN_VERSION | | the version of the [Common Custom User Data Gradle plugin](https://github.com/gradle/common-custom-user-data-gradle-plugin) to apply, if any |
779+
| GRADLE_ENTERPRISE_INJECTION_PLUGIN_REPOSITORY_URL | | the URL of the repository to use when resolving the GE and CCUD plugins; the Gradle Plugin Portal is used by default |

dist/main/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72982,10 +72982,11 @@ org.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME
7298272982
`);
7298372983
}
7298472984
const initScriptFilenames = [
72985-
'build-result-capture.init.gradle',
72986-
'build-result-capture-service.plugin.groovy',
72987-
'github-dependency-graph.init.gradle',
72988-
'github-dependency-graph-gradle-plugin-apply.groovy'
72985+
'gradle-build-action.build-result-capture.init.gradle',
72986+
'gradle-build-action.build-result-capture-service.plugin.groovy',
72987+
'gradle-build-action.github-dependency-graph.init.gradle',
72988+
'gradle-build-action.github-dependency-graph-gradle-plugin-apply.groovy',
72989+
'gradle-build-action.inject-gradle-enterprise.init.gradle'
7298972990
];
7299072991
for (const initScriptFilename of initScriptFilenames) {
7299172992
const initScriptContent = this.readInitScriptAsString(initScriptFilename);

dist/main/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/post/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72982,10 +72982,11 @@ org.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME
7298272982
`);
7298372983
}
7298472984
const initScriptFilenames = [
72985-
'build-result-capture.init.gradle',
72986-
'build-result-capture-service.plugin.groovy',
72987-
'github-dependency-graph.init.gradle',
72988-
'github-dependency-graph-gradle-plugin-apply.groovy'
72985+
'gradle-build-action.build-result-capture.init.gradle',
72986+
'gradle-build-action.build-result-capture-service.plugin.groovy',
72987+
'gradle-build-action.github-dependency-graph.init.gradle',
72988+
'gradle-build-action.github-dependency-graph-gradle-plugin-apply.groovy',
72989+
'gradle-build-action.inject-gradle-enterprise.init.gradle'
7298972990
];
7299072991
for (const initScriptFilename of initScriptFilenames) {
7299172992
const initScriptContent = this.readInitScriptAsString(initScriptFilename);

dist/post/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cache-base.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,11 @@ org.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME
189189

190190
// Copy init scripts from src/resources
191191
const initScriptFilenames = [
192-
'build-result-capture.init.gradle',
193-
'build-result-capture-service.plugin.groovy',
194-
'github-dependency-graph.init.gradle',
195-
'github-dependency-graph-gradle-plugin-apply.groovy'
192+
'gradle-build-action.build-result-capture.init.gradle',
193+
'gradle-build-action.build-result-capture-service.plugin.groovy',
194+
'gradle-build-action.github-dependency-graph.init.gradle',
195+
'gradle-build-action.github-dependency-graph-gradle-plugin-apply.groovy',
196+
'gradle-build-action.inject-gradle-enterprise.init.gradle'
196197
]
197198
for (const initScriptFilename of initScriptFilenames) {
198199
const initScriptContent = this.readInitScriptAsString(initScriptFilename)

src/resources/init-scripts/build-result-capture.init.gradle renamed to src/resources/init-scripts/gradle-build-action.build-result-capture.init.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def captureUsingBuildFinished(gradle, invocationId) {
8282

8383
def captureUsingBuildService(settings, invocationId) {
8484
gradle.ext.invocationId = invocationId
85-
apply from: 'build-result-capture-service.plugin.groovy'
85+
apply from: 'gradle-build-action.build-result-capture-service.plugin.groovy'
8686
}
8787

8888
class BuildResults {

src/resources/init-scripts/github-dependency-graph.init.gradle renamed to src/resources/init-scripts/gradle-build-action.github-dependency-graph.init.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if (isTopLevelBuild) {
3131
println "Generating dependency graph into '${reportFile}'"
3232
}
3333

34-
apply from: 'github-dependency-graph-gradle-plugin-apply.groovy'
34+
apply from: 'gradle-build-action.github-dependency-graph-gradle-plugin-apply.groovy'
3535

3636
/**
3737
* Using the supplied jobCorrelator value:

0 commit comments

Comments
 (0)