Skip to content

Commit 16bf8bc

Browse files
authored
Rework docs for Develocity support
Fixes #339
1 parent faf4eea commit 16bf8bc

File tree

1 file changed

+84
-32
lines changed

1 file changed

+84
-32
lines changed

docs/setup-gradle.md

Lines changed: 84 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -724,14 +724,90 @@ To reduce storage costs for these artifacts, you can set the `artifact-retention
724724
artifact-retention-days: 1
725725
```
726726

727-
# Develocity plugin injection
727+
# Develocity Build Scan® integration
728728

729-
The `setup-gradle` action provides support for injecting and configuring the Develocity Gradle plugin into any Gradle build, without any modification to the project sources.
730-
This is achieved via an init-script installed into Gradle User Home, which is enabled and parameterized via environment variables.
729+
Publishing a Develocity Build Scan can be very helpful for Gradle builds run on GitHub Actions. Each Build Scan provides a
730+
detailed report of the execution of the build, including which tasks were executed and the results of any test execution.
731+
732+
The `setup-gradle` plugin provides a number of features to enable and enhance publishing Build Scans® to a Develocity instance.
733+
734+
## Publishing to scans.gradle.com
735+
736+
If you don't have a a private Develocity instance, you can easily publish Build Scans to the
737+
free, public Develocity instance (https://scans.gradle.com).
738+
739+
To publish to https://scans.gradle.com, you must specify in your workflow that you accept the [Gradle Terms of Use](https://gradle.com/help/legal-terms-of-use).
740+
741+
```yaml
742+
- name: Setup Gradle to publish build scans
743+
uses: gradle/actions/setup-gradle@v4
744+
with:
745+
build-scan-publish: true
746+
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
747+
build-scan-terms-of-use-agree: "yes"
748+
749+
- name: Run a Gradle build - a build scan will be published automatically
750+
run: ./gradlew build
751+
```
752+
753+
## Managing Develocity access keys
754+
755+
Develocity access keys are long-lived, creating risks if they are leaked. To mitigate this risk this,
756+
the `setup-gradle` action can automatically attempt to obtain a short-lived access token to authenticate with Develocity.
757+
The short-lived access token will then be used wherever a Develocity access key is required.
758+
759+
```yaml
760+
- name: Setup Gradle
761+
uses: gradle/actions/setup-gradle@v4
762+
with:
763+
develocity-access-key: ${{ secrets.MY_DEVELOCITY_ACCESS_KEY }} # Long-lived access key, visiblility is restricted to this step.
764+
765+
# Subsequent steps will automatically use a short-lived access token to authenticate with Develocity
766+
- name: Run a Gradle build that is configured to publish to Develocity.
767+
run: ./gradlew build
768+
```
769+
770+
### Develocity access key supplied as environment variable
771+
772+
The preferred mechanism is to supply the long-lived Develocity access key directly to `setup-gradle` via
773+
the `develocity-access-key` input variable. However, the action will also detect an access key configured as an environment variable,
774+
such as `DEVELOCITY_ACCESS_KEY` or `GRADLE_ENTERPRISE_ACCESS_KEY`. In this case, the environment variable value will be replaced by
775+
a short-lived access token, thus hiding the long-lived access key from subsequent steps.
776+
777+
```yaml
778+
env:
779+
DEVELOCITY_ACCESS_KEY: ${{ secrets.MY_DEVELOCITY_ACCESS_KEY }}
780+
781+
jobs:
782+
build-with-gradle:
783+
runs-on: ubuntu-latest
784+
steps:
785+
- name: Setup Gradle
786+
uses: gradle/actions/setup-gradle@v4
787+
788+
# The build will automatically use a short-lived access token to authenticate with Develocity
789+
- name: Run a Gradle build that is configured to publish to Develocity.
790+
run: ./gradlew build
791+
```
792+
793+
### Failure to obtain a short-lived access token
794+
795+
If a short-lived token cannot be retrieved (for example, if the Develocity server version is lower than `2024.1`):
796+
- If the access key is provided via `develocity-access-key`, then no access token is set and authentication with Develocity will not succeed.
797+
- If the access key is provided via an environment variable, a warning will be logged and the environment variable will be left as-is.
798+
This can result in long-lived access keys being unintentionally exposed to other workflow steps.
799+
For more information on short-lived tokens, see [Develocity API documentation](https://docs.gradle.com/develocity/api-manual/#short_lived_access_tokens).
800+
801+
## Develocity plugin injection
802+
803+
The `setup-gradle` action provides support for transparently injecting and configuring the Develocity Gradle plugin into any Gradle build,
804+
without any modification to the project sources. This allows Build Scans to be published for a repository without any changes to the project sources.
805+
806+
Develocity injection is achieved via an init-script installed into Gradle User Home, which is enabled and parameterized via environment variables.
731807

732808
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.
733809

734-
## Enabling Develocity injection
810+
### Enabling Develocity injection
735811

736812
To enable Develocity injection for your build, you must provide the required configuration via inputs.
737813

@@ -770,14 +846,7 @@ In the likely scenario that your Develocity server requires authentication, you
770846

771847
This access key will be used during the action execution to get a short-lived token and set it to the DEVELOCITY_ACCESS_KEY environment variable.
772848

773-
### Short-lived access tokens
774-
Develocity access keys are long-lived, creating risks if they are leaked. To avoid this, users can use short-lived access tokens to authenticate with Develocity. Access tokens can be used wherever an access key would be used. Access tokens are only valid for the Develocity instance that created them.
775-
If a short-lived token fails to be retrieved (for example, if the Develocity server version is lower than `2024.1`):
776-
- if a `GRADLE_ENTERPRISE_ACCESS_KEY` env var has been set, we're falling back to it with a deprecation warning
777-
- otherwise no access key env var will be set. In that case Develocity authenticated operations like build cache read/write and build scan publication will fail without failing the build.
778-
For more information on short-lived tokens, see [Develocity API documentation](https://docs.gradle.com/develocity/api-manual/#short_lived_access_tokens).
779-
780-
## Configuring Develocity injection
849+
### Configuring Develocity injection
781850

782851
The `init-script` supports several additional configuration parameters that you may find useful. All configuration options (required and optional) are detailed below:
783852

@@ -821,26 +890,9 @@ Here's an example using the env vars:
821890
env:
822891
DEVELOCITY_INJECTION_ENABLED: true
823892
DEVELOCITY_URL: https://develocity.your-server.com
824-
DEVELOCITY_PLUGIN_VERSION: 3.18
825-
```
826-
827-
## Publishing to scans.gradle.com
828-
829-
Develocity injection is designed to enable the publishing of build scans to a Develocity instance,
830-
but is also useful for publishing to the public Build Scans instance (https://scans.gradle.com).
831-
832-
To publish to https://scans.gradle.com, you must specify in your workflow that you accept the [Gradle Terms of Use](https://gradle.com/help/legal-terms-of-use).
833-
834-
```yaml
835-
- name: Setup Gradle to publish build scans
836-
uses: gradle/actions/setup-gradle@v4
837-
with:
838-
build-scan-publish: true
839-
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
840-
build-scan-terms-of-use-agree: "yes"
841-
842-
- name: Run a Gradle build - a build scan will be published automatically
843-
run: ./gradlew build
893+
DEVELOCITY_ENFORCE_URL: true
894+
DEVELOCITY_PLUGIN_VERSION: "3.18"
895+
DEVELOCITY_CCUD_PLUGIN_VERSION: "2.0.2"
844896
```
845897

846898
# Dependency verification

0 commit comments

Comments
 (0)