Skip to content

Commit

Permalink
Merge pull request #857 from gradle/dd/inject-ge
Browse files Browse the repository at this point in the history
Add support for Gradle Enterprise injection into Gradle Builds
  • Loading branch information
bigdaz committed Aug 20, 2023
2 parents a617adb + d79398d commit e3426b1
Show file tree
Hide file tree
Showing 20 changed files with 760 additions and 31 deletions.
1 change: 1 addition & 0 deletions .github/workflow-samples/no-ge/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Required to keep dependabot happy
1 change: 1 addition & 0 deletions .github/workflow-samples/no-ge/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'no-ge'
5 changes: 5 additions & 0 deletions .github/workflows/ci-full-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ jobs:
with:
cache-key-prefix: ${{github.run_number}}-

gradle-enterprise-injection:
uses: ./github/workflows/integ-test-inject-gradle-enterprise.yml
with:
cache-key-prefix: ${{github.run_number}}-

provision-gradle-versions:
uses: ./.github/workflows/integ-test-provision-gradle-versions.yml
with:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/ci-quick-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ jobs:
runner-os: '["ubuntu-latest"]'
download-dist: true

gradle-enterprise-injection:
needs: build-distribution
uses: ./github/workflows/integ-test-inject-gradle-enterprise.yml
with:
runner-os: '["ubuntu-latest"]'
download-dist: true

provision-gradle-versions:
needs: build-distribution
uses: ./.github/workflows/integ-test-provision-gradle-versions.yml
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/integ-test-inject-gradle-enterprise.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Test gradle enterprise injection

on:
workflow_call:
inputs:
cache-key-prefix:
type: string
runner-os:
type: string
default: '["ubuntu-latest", "windows-latest", "macos-latest"]'
download-dist:
type: boolean
default: false

env:
DOWNLOAD_DIST: ${{ inputs.download-dist }}
GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: provision-gradle-versions-${{ inputs.cache-key-prefix }}
GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED: true
GRADLE_ENTERPRISE_INJECTION_ENABLED: true
GRADLE_ENTERPRISE_INJECTION_SERVER_URL: https://ge.solutions-team.gradle.com
GRADLE_ENTERPRISE_INJECTION_GE_PLUGIN_VERSION: 3.14.1
GRADLE_ENTERPRISE_INJECTION_CCUD_PLUGIN_VERSION: 1.11.1
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GE_SOLUTIONS_ACCESS_TOKEN }}

jobs:
inject-gradle-enterprise:
strategy:
matrix:
gradle: [current, 7.6.2, 6.9.4, 5.6.4]
os: ${{fromJSON(inputs.runner-os)}}
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Download distribution if required
uses: ./.github/actions/download-dist
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
- name: Setup Gradle
id: setup-gradle
uses: ./
with:
cache-read-only: false # For testing, allow writing cache entries on non-default branches
gradle-version: ${{ matrix.gradle }}
- name: Run Gradle build
id: gradle
working-directory: .github/workflow-samples/no-ge
run: gradle help
- name: Check Build Scan url
if: ${{ !steps.gradle.outputs.build-scan-url }}
uses: actions/github-script@v6
with:
script: |
core.setFailed('No Build Scan detected')
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -725,3 +725,55 @@ limited to Gradle "8.1.0" and later:

To use this plugin with versions of Gradle older than "8.1.0", you'll need to invoke Gradle with the
configuration-cache disabled.

# Gradle Enterprise plugin injection

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.
This is achieved via an init-script installed into Gradle User Home, which is enabled and parameterized via environment variables.

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.

## Enabling Gradle Enterprise injection

In order to enable Gradle Enterprise for your build, you must provide the required configuration via environment variables.

Here's a minimal example:

```yaml
name: Run build with Gradle Enterprise injection

env:
GRADLE_ENTERPRISE_INJECTION_ENABLED: true
GRADLE_ENTERPRISE_INJECTION_SERVER_URL: https://ge.gradle.org
GRADLE_ENTERPRISE_INJECTION_GE_PLUGIN_VERSION: 3.14.1
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GE_ACCESS_KEY }} # Required to publish scans to ge.gradle.org

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Run a Gradle build with Gradle Enterprise injection enabled
run: ./gradlew build
```

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.

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,
but will be used by the GE plugin in order to authenticate with the server.

## Configuring Gradle Enterprise injection

The `init-script` supports a number of additional configuration parameters that you may fine useful. All configuration options (required and optional) are detailed below:

| Variable | Required | Description |
| --- | --- | --- |
| GRADLE_ENTERPRISE_INJECTION_ENABLED | :white_check_mark: | enables Gradle Enterprise injection |
| GRADLE_ENTERPRISE_INJECTION_SERVER_URL | :white_check_mark: | the URL of the Gradle Enterprise server |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
9 changes: 5 additions & 4 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72982,10 +72982,11 @@ org.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME
`);
}
const initScriptFilenames = [
'build-result-capture.init.gradle',
'build-result-capture-service.plugin.groovy',
'github-dependency-graph.init.gradle',
'github-dependency-graph-gradle-plugin-apply.groovy'
'gradle-build-action.build-result-capture.init.gradle',
'gradle-build-action.build-result-capture-service.plugin.groovy',
'gradle-build-action.github-dependency-graph.init.gradle',
'gradle-build-action.github-dependency-graph-gradle-plugin-apply.groovy',
'gradle-build-action.inject-gradle-enterprise.init.gradle'
];
for (const initScriptFilename of initScriptFilenames) {
const initScriptContent = this.readInitScriptAsString(initScriptFilename);
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72982,10 +72982,11 @@ org.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME
`);
}
const initScriptFilenames = [
'build-result-capture.init.gradle',
'build-result-capture-service.plugin.groovy',
'github-dependency-graph.init.gradle',
'github-dependency-graph-gradle-plugin-apply.groovy'
'gradle-build-action.build-result-capture.init.gradle',
'gradle-build-action.build-result-capture-service.plugin.groovy',
'gradle-build-action.github-dependency-graph.init.gradle',
'gradle-build-action.github-dependency-graph-gradle-plugin-apply.groovy',
'gradle-build-action.inject-gradle-enterprise.init.gradle'
];
for (const initScriptFilename of initScriptFilenames) {
const initScriptContent = this.readInitScriptAsString(initScriptFilename);
Expand Down
2 changes: 1 addition & 1 deletion dist/post/index.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/cache-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,11 @@ org.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME

// Copy init scripts from src/resources
const initScriptFilenames = [
'build-result-capture.init.gradle',
'build-result-capture-service.plugin.groovy',
'github-dependency-graph.init.gradle',
'github-dependency-graph-gradle-plugin-apply.groovy'
'gradle-build-action.build-result-capture.init.gradle',
'gradle-build-action.build-result-capture-service.plugin.groovy',
'gradle-build-action.github-dependency-graph.init.gradle',
'gradle-build-action.github-dependency-graph-gradle-plugin-apply.groovy',
'gradle-build-action.inject-gradle-enterprise.init.gradle'
]
for (const initScriptFilename of initScriptFilenames) {
const initScriptContent = this.readInitScriptAsString(initScriptFilename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def captureUsingBuildFinished(gradle, invocationId) {

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

class BuildResults {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (isTopLevelBuild) {
println "Generating dependency graph into '${reportFile}'"
}

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

/**
* Using the supplied jobCorrelator value:
Expand Down

0 comments on commit e3426b1

Please sign in to comment.