Skip to content

Commit d0a116f

Browse files
authored
Adding Develocity input actions (#244)
Adding Develocity input actions. If an input is configured in the action, it will generate the environment variable, example: ```yaml - name: Setup Gradle uses: gradle/actions/setup-gradle@v3 with: develocity-injection-enabled: true develocity-url: https://develocity.your-server.com develocity-plugin-version: 3.17.4 - name: Run a Gradle build with Develocity injection enabled from input actions run: ./gradlew build ``` This configuration will create the environment variables: ``` DEVELOCITY_INJECTION_ENABLED=true DEVELOCITY_URL=https://develocity.your-server.com DEVELOCITY_PLUGIN_VERSION=3.17.4 ``` Relation variable-input available: | Variable | Input | |--------------------------------------|--------------------------------------| | DEVELOCITY_INJECTION_ENABLED | develocity-injection-enabled | | DEVELOCITY_URL | develocity-url | | DEVELOCITY_ALLOW_UNTRUSTED_SERVER | develocity-allow-untrusted-server | | DEVELOCITY_CAPTURE_FILE_FINGERPRINTS | develocity-capture-file-fingerprints | | DEVELOCITY_ENFORCE_URL | develocity-enforce-url | | DEVELOCITY_PLUGIN_VERSION | develocity-plugin-version | | DEVELOCITY_CCUD_PLUGIN_VERSION | develocity-ccud-plugin-version | | GRADLE_PLUGIN_REPOSITORY_URL | gradle-plugin-repository-url | | GRADLE_PLUGIN_REPOSITORY_USERNAME | gradle-plugin-repository-username | | GRADLE_PLUGIN_REPOSITORY_PASSWORD | gradle-plugin-repository-password |
1 parent e238a7a commit d0a116f

File tree

5 files changed

+194
-15
lines changed

5 files changed

+194
-15
lines changed

.github/workflows/integ-test-inject-develocity.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,43 @@ jobs:
159159
run: "[ \"${DEVELOCITY_ACCESS_KEY}\" == \"\" ] || (echo 'DEVELOCITY_ACCESS_KEY has leaked!'; exit 1)"
160160
- name: Check access key is not blank (GRADLE_ENTERPRISE_ACCESS_KEY)
161161
run: "[ \"${GRADLE_ENTERPRISE_ACCESS_KEY}\" != \"\" ] || (echo 'GRADLE_ENTERPRISE_ACCESS_KEY is still supported in v3!'; exit 1)"
162+
163+
inject-develocity-with-access-key-from-input-actions:
164+
env:
165+
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
166+
strategy:
167+
fail-fast: false
168+
matrix:
169+
gradle: [ current, 7.6.2, 6.9.4, 5.6.4 ]
170+
os: ${{fromJSON(inputs.runner-os)}}
171+
plugin-version: [ 3.16.2, 3.17.4 ]
172+
runs-on: ${{ matrix.os }}
173+
steps:
174+
- name: Checkout sources
175+
uses: actions/checkout@v4
176+
- name: Initialize integ-test
177+
uses: ./.github/actions/init-integ-test
178+
- name: Setup Java
179+
uses: actions/setup-java@v4
180+
with:
181+
distribution: temurin
182+
java-version: 8
183+
- name: Setup Gradle
184+
id: setup-gradle
185+
uses: ./setup-gradle
186+
with:
187+
cache-read-only: false # For testing, allow writing cache entries on non-default branches
188+
gradle-version: ${{ matrix.gradle }}
189+
develocity-injection-enabled: true
190+
develocity-url: 'https://ge.solutions-team.gradle.com'
191+
develocity-plugin-version: ${{ matrix.plugin-version }}
192+
- name: Run Gradle build
193+
id: gradle
194+
working-directory: .github/workflow-samples/no-ge
195+
run: gradle help
196+
- name: Check Build Scan url
197+
if: ${{ !steps.gradle.outputs.build-scan-url }}
198+
uses: actions/github-script@v7
199+
with:
200+
script: |
201+
core.setFailed('No Build Scan detected')

docs/setup-gradle.md

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -708,20 +708,20 @@ The same auto-injection behavior is available for the Common Custom User Data Gr
708708

709709
## Enabling Develocity injection
710710

711-
To enable Develocity injection for your build, you must provide the required configuration via environment variables.
711+
To enable Develocity injection for your build, you must provide the required configuration via inputs.
712712

713713
Here's a minimal example:
714714

715715
```yaml
716716
- name: Setup Gradle
717717
uses: gradle/actions/setup-gradle@v3
718+
with:
719+
develocity-injection-enabled: true
720+
develocity-url: https://develocity.your-server.com
721+
develocity-plugin-version: 3.17.5
718722
719723
- name: Run a Gradle build with Develocity injection enabled
720724
run: ./gradlew build
721-
env:
722-
DEVELOCITY_INJECTION_ENABLED: true
723-
DEVELOCITY_URL: https://develocity.your-server.com
724-
DEVELOCITY_PLUGIN_VERSION: 3.17.5
725725
```
726726

727727
This configuration will automatically apply `v3.17.5` of the [Develocity Gradle plugin](https://docs.gradle.com/develocity/gradle-plugin/), and publish build scans to https://develocity.your-server.com.
@@ -758,16 +758,46 @@ The `init-script` supports several additional configuration parameters that you
758758

759759
| Variable | Required | Description |
760760
|--------------------------------------| --- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
761-
| DEVELOCITY_INJECTION_ENABLED | :white_check_mark: | enables Develocity injection |
762-
| DEVELOCITY_URL | :white_check_mark: | the URL of the Develocity server |
763-
| DEVELOCITY_ALLOW_UNTRUSTED_SERVER | | allow communication with an untrusted server; set to _true_ if your Develocity instance is using a self-signed certificate |
764-
| DEVELOCITY_CAPTURE_FILE_FINGERPRINTS | | enables capturing the paths and content hashes of each individual input file |
765-
| DEVELOCITY_ENFORCE_URL | | enforce the configured Develocity URL over a URL configured in the project's build; set to _true_ to enforce publication of build scans to the configured Develocity URL |
766-
| DEVELOCITY_PLUGIN_VERSION | :white_check_mark: | the version of the [Develocity Gradle plugin](https://docs.gradle.com/develocity/gradle-plugin/) to apply |
767-
| DEVELOCITY_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 |
768-
| GRADLE_PLUGIN_REPOSITORY_URL | | the URL of the repository to use when resolving the Develocity and CCUD plugins; the Gradle Plugin Portal is used by default |
769-
| GRADLE_PLUGIN_REPOSITORY_USERNAME | | the username for the repository URL to use when resolving the Develocity and CCUD plugins |
770-
| GRADLE_PLUGIN_REPOSITORY_PASSWORD | | the password for the repository URL to use when resolving the Develocity and CCUD plugins; Consider using secrets to pass the value to this variable |
761+
| develocity-injection-enabled | :white_check_mark: | enables Develocity injection |
762+
| develocity-url | :white_check_mark: | the URL of the Develocity server |
763+
| develocity-allow-untrusted-server | | allow communication with an untrusted server; set to _true_ if your Develocity instance is using a self-signed certificate |
764+
| develocity-capture-file-fingerprints | | enables capturing the paths and content hashes of each individual input file |
765+
| develocity-enforce-url | | enforce the configured Develocity URL over a URL configured in the project's build; set to _true_ to enforce publication of build scans to the configured Develocity URL |
766+
| develocity-plugin-version | :white_check_mark: | the version of the [Develocity Gradle plugin](https://docs.gradle.com/develocity/gradle-plugin/) to apply |
767+
| develocity-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 |
768+
| gradle-plugin-repository-url | | the URL of the repository to use when resolving the Develocity and CCUD plugins; the Gradle Plugin Portal is used by default |
769+
| gradle-plugin-repository-username | | the username for the repository URL to use when resolving the Develocity and CCUD plugins |
770+
| gradle-plugin-repository-password | | the password for the repository URL to use when resolving the Develocity and CCUD plugins; Consider using secrets to pass the value to this variable |
771+
772+
The input parameters can be expressed as environment variables following the relationships outlined in the table below:
773+
774+
| Input | Environment Variable |
775+
|--------------------------------------|--------------------------------------|
776+
| develocity-injection-enabled | DEVELOCITY_INJECTION_ENABLED |
777+
| develocity-url | DEVELOCITY_URL |
778+
| develocity-allow-untrusted-server | DEVELOCITY_ALLOW_UNTRUSTED_SERVER |
779+
| develocity-capture-file-fingerprints | DEVELOCITY_CAPTURE_FILE_FINGERPRINTS |
780+
| develocity-enforce-url | DEVELOCITY_ENFORCE_URL |
781+
| develocity-plugin-version | DEVELOCITY_PLUGIN_VERSION |
782+
| develocity-ccud-plugin-version | DEVELOCITY_CCUD_PLUGIN_VERSION |
783+
| gradle-plugin-repository-url | GRADLE_PLUGIN_REPOSITORY_URL |
784+
| gradle-plugin-repository-username | GRADLE_PLUGIN_REPOSITORY_USERNAME |
785+
| gradle-plugin-repository-password | GRADLE_PLUGIN_REPOSITORY_PASSWORD |
786+
787+
788+
Here's an example using the env vars:
789+
790+
```yaml
791+
- name: Setup Gradle
792+
uses: gradle/actions/setup-gradle@v3
793+
794+
- name: Run a Gradle build with Develocity injection enabled with environment variables
795+
run: ./gradlew build
796+
env:
797+
DEVELOCITY_INJECTION_ENABLED: true
798+
DEVELOCITY_URL: https://develocity.your-server.com
799+
DEVELOCITY_PLUGIN_VERSION: 3.17.5
800+
```
771801

772802
## Publishing to scans.gradle.com
773803

setup-gradle/action.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,46 @@ inputs:
108108
description: The Develocity short-lived access tokens expiry in hours. Default is 2 hours.
109109
required: false
110110

111+
develocity-injection-enabled:
112+
description: Enables Develocity injection.
113+
required: false
114+
115+
develocity-url:
116+
description: The URL for the Develocity server.
117+
required: false
118+
119+
develocity-allow-untrusted-server:
120+
description: Allow communication with an untrusted server; set to _true_ if your Develocity instance is using a self-signed.
121+
required: false
122+
123+
develocity-capture-file-fingerprints:
124+
description: Enables capturing the paths and content hashes of each individual input file.
125+
required: false
126+
127+
develocity-enforce-url:
128+
description: Enforce the configured Develocity URL over a URL configured in the project's build; set to _true_ to enforce publication of build scans to the configured Develocity URL.
129+
required: false
130+
131+
develocity-plugin-version:
132+
description: The version of the Develocity Gradle plugin to apply.
133+
required: false
134+
135+
develocity-ccud-plugin-version:
136+
description: The version of the Common Custom User Data Gradle plugin to apply, if any.
137+
required: false
138+
139+
gradle-plugin-repository-url:
140+
description: The URL of the repository to use when resolving the Develocity and CCUD plugins; the Gradle Plugin Portal is used by default.
141+
required: false
142+
143+
gradle-plugin-repository-username:
144+
description: The username for the repository URL to use when resolving the Develocity and CCUD.
145+
required: false
146+
147+
gradle-plugin-repository-password:
148+
description: The password for the repository URL to use when resolving the Develocity and CCUD plugins; Consider using secrets to pass the value to this variable.
149+
required: false
150+
111151
# Wrapper validation configuration
112152
validate-wrappers:
113153
description: |

sources/src/configuration.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,46 @@ export class BuildScanConfig {
216216
return core.getInput('develocity-token-expiry')
217217
}
218218

219+
getDevelocityInjectionEnabled(): boolean | undefined {
220+
return getMaybeBooleanInput('develocity-injection-enabled')
221+
}
222+
223+
getDevelocityUrl(): string {
224+
return core.getInput('develocity-url')
225+
}
226+
227+
getDevelocityAllowUntrustedServer(): boolean | undefined {
228+
return getMaybeBooleanInput('develocity-allow-untrusted-server')
229+
}
230+
231+
getDevelocityCaptureFileFingerprints(): boolean | undefined {
232+
return getMaybeBooleanInput('develocity-capture-file-fingerprints')
233+
}
234+
235+
getDevelocityEnforceUrl(): boolean | undefined {
236+
return getMaybeBooleanInput('develocity-enforce-url')
237+
}
238+
239+
getDevelocityPluginVersion(): string {
240+
return core.getInput('develocity-plugin-version')
241+
}
242+
243+
getDevelocityCcudPluginVersion(): string {
244+
return core.getInput('develocity-ccud-plugin-version')
245+
}
246+
247+
getGradlePluginRepositoryUrl(): string {
248+
return core.getInput('gradle-plugin-repository-url')
249+
}
250+
251+
getGradlePluginRepositoryUsername(): string {
252+
return core.getInput('gradle-plugin-repository-username')
253+
}
254+
255+
getGradlePluginRepositoryPassword(): string {
256+
return core.getInput('gradle-plugin-repository-password')
257+
}
258+
219259
private verifyTermsOfUseAgreement(): boolean {
220260
if (
221261
(this.getBuildScanTermsOfUseUrl() !== 'https://gradle.com/terms-of-service' &&
@@ -329,3 +369,15 @@ function getBooleanInput(paramName: string, paramDefault = false): boolean {
329369
}
330370
throw TypeError(`The value '${paramValue} is not valid for '${paramName}. Valid values are: [true, false]`)
331371
}
372+
373+
function getMaybeBooleanInput(paramName: string): boolean | undefined {
374+
const paramValue = core.getInput(paramName)
375+
switch (paramValue?.toLowerCase().trim()) {
376+
case 'false':
377+
return false
378+
case 'true':
379+
return true
380+
default:
381+
return undefined
382+
}
383+
}

sources/src/develocity/build-scan.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ export async function setup(config: BuildScanConfig): Promise<void> {
1212
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_URL', config.getBuildScanTermsOfUseUrl())
1313
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_AGREE', config.getBuildScanTermsOfUseAgree())
1414
}
15+
16+
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION_ENABLED', config.getDevelocityInjectionEnabled())
17+
maybeExportVariableNotEmpty('DEVELOCITY_URL', config.getDevelocityUrl())
18+
maybeExportVariableNotEmpty('DEVELOCITY_ALLOW_UNTRUSTED_SERVER', config.getDevelocityAllowUntrustedServer())
19+
maybeExportVariableNotEmpty('DEVELOCITY_CAPTURE_FILE_FINGERPRINTS', config.getDevelocityCaptureFileFingerprints())
20+
maybeExportVariableNotEmpty('DEVELOCITY_ENFORCE_URL', config.getDevelocityEnforceUrl())
21+
maybeExportVariableNotEmpty('DEVELOCITY_PLUGIN_VERSION', config.getDevelocityPluginVersion())
22+
maybeExportVariableNotEmpty('GRADLE_PLUGIN_REPOSITORY_URL', config.getGradlePluginRepositoryUrl())
23+
maybeExportVariableNotEmpty('GRADLE_PLUGIN_REPOSITORY_USERNAME', config.getGradlePluginRepositoryUsername())
24+
maybeExportVariableNotEmpty('GRADLE_PLUGIN_REPOSITORY_PASSWORD', config.getGradlePluginRepositoryPassword())
25+
1526
setupToken(
1627
config.getDevelocityAccessKey(),
1728
config.getDevelocityTokenExpiry(),
@@ -29,3 +40,9 @@ function maybeExportVariable(variableName: string, value: unknown): void {
2940
core.exportVariable(variableName, value)
3041
}
3142
}
43+
44+
function maybeExportVariableNotEmpty(variableName: string, value: unknown): void {
45+
if (value !== null && value !== undefined && value !== '') {
46+
maybeExportVariable(variableName, value)
47+
}
48+
}

0 commit comments

Comments
 (0)