Skip to content

Commit f64284c

Browse files
authored
Mute license warning when terms are accepted (#911)
With licensing changes in v6, a license warning was added to the logs and job summary. Now, accepting the Build Scan Terms of Use or providing a Develocity Access Key will mute this warning.
1 parent c2457a7 commit f64284c

File tree

11 files changed

+91
-29
lines changed

11 files changed

+91
-29
lines changed

.github/workflows/demo-job-summary.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,38 @@ jobs:
131131
- name: Build kotlin-dsl project
132132
working-directory: .github/workflow-samples/kotlin-dsl
133133
run: ./gradlew assemble
134+
135+
terms-of-use-accepted:
136+
needs: build-distribution
137+
runs-on: ubuntu-latest
138+
steps:
139+
- name: Checkout sources
140+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
141+
- name: Initialize integ-test
142+
uses: ./.github/actions/init-integ-test
143+
144+
- name: Setup Gradle
145+
uses: ./setup-gradle
146+
with:
147+
build-scan-terms-of-use-url: https://gradle.com/help/legal-terms-of-use
148+
build-scan-terms-of-use-agree: yes
149+
- name: Build kotlin-dsl project
150+
working-directory: .github/workflow-samples/kotlin-dsl
151+
run: ./gradlew assemble
152+
153+
develocity-access-key-set:
154+
needs: build-distribution
155+
runs-on: ubuntu-latest
156+
steps:
157+
- name: Checkout sources
158+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
159+
- name: Initialize integ-test
160+
uses: ./.github/actions/init-integ-test
161+
162+
- name: Setup Gradle
163+
uses: ./setup-gradle
164+
with:
165+
develocity-access-key: ${{ secrets.DV_SOLUTIONS_ACCESS_KEY }}
166+
- name: Build kotlin-dsl project
167+
working-directory: .github/workflow-samples/kotlin-dsl
168+
run: ./gradlew assemble

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ This repository contains a set of GitHub Actions that are useful for building Gr
1515
> Use of the `gradle-actions-caching` component is subject to a separate license, available at https://gradle.com/legal/terms-of-use/.
1616
> If you do not agree to these license terms, do not use the `gradle-actions-caching` component.
1717
18+
This license notice will be displayed in workflow logs and each job summary. To suppress this message,
19+
either [accept the terms of use](docs/setup-gradle.md#publishing-to-scansgradlecom) in your workflow, or [provide a Develocity access key](docs/setup-gradle.md#managing-develocity-access-keys).
20+
1821
## The `setup-gradle` action
1922

2023
The `setup-gradle` action can be used to configure Gradle for optimal execution on any platform supported by GitHub Actions.

docs/dependency-submission.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ If you're confused by the behaviour you're seeing or have specific questions, pl
2828
> Use of the `gradle-actions-caching` component is subject to a separate license, available at https://gradle.com/legal/terms-of-use/.
2929
> If you do not agree to these license terms, do not use the `gradle-actions-caching` component.
3030
31+
This license notice will be displayed in workflow logs and each job summary. To suppress this message,
32+
either [accept the terms of use](setup-gradle.md#publishing-to-scansgradlecom) in your workflow, or [provide a Develocity access key](setup-gradle.md#managing-develocity-access-keys).
33+
3134
## General usage
3235

3336
The following workflow will generate a dependency graph for a Gradle project and submit it immediately to the repository via the

docs/setup-gradle.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ This GitHub Action can be used to configure Gradle for optimal execution on any
1515
> Use of the `gradle-actions-caching` component is subject to a separate license, available at https://gradle.com/legal/terms-of-use/.
1616
> If you do not agree to these license terms, do not use the `gradle-actions-caching` component.
1717
18+
This license notice will be displayed in workflow logs and each job summary. To suppress this message,
19+
either [accept the terms of use](#publishing-to-scansgradlecom) in your workflow, or [provide a Develocity access key](#managing-develocity-access-keys).
20+
1821
## Why use the `setup-gradle` action?
1922

2023
It is possible to directly invoke Gradle in your workflow, and the `actions/setup-java@v5` action provides a simple way to cache Gradle dependencies.

sources/src/actions/dependency-submission/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as dependencyGraph from '../../dependency-graph'
55

66
import {parseArgsStringToArgv} from 'string-argv'
77
import {
8-
BuildScanConfig,
8+
DevelocityConfig,
99
CacheConfig,
1010
DependencyGraphConfig,
1111
DependencyGraphOption,
@@ -25,7 +25,7 @@ export async function run(): Promise<void> {
2525
setActionId('gradle/actions/dependency-submission')
2626

2727
// Configure Gradle environment (Gradle User Home)
28-
await setupGradle.setup(new CacheConfig(), new BuildScanConfig(), new WrapperValidationConfig())
28+
await setupGradle.setup(new CacheConfig(), new DevelocityConfig(), new WrapperValidationConfig())
2929

3030
// Capture the enabled state of dependency-graph
3131
const originallyEnabled = process.env['GITHUB_DEPENDENCY_GRAPH_ENABLED']

sources/src/actions/setup-gradle/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as setupGradle from '../../setup-gradle'
22
import * as provisioner from '../../execution/provision'
33
import * as dependencyGraph from '../../dependency-graph'
44
import {
5-
BuildScanConfig,
5+
DevelocityConfig,
66
CacheConfig,
77
DependencyGraphConfig,
88
GradleExecutionConfig,
@@ -28,7 +28,7 @@ export async function run(): Promise<void> {
2828
setActionId('gradle/actions/setup-gradle')
2929

3030
// Configure Gradle environment (Gradle User Home)
31-
await setupGradle.setup(new CacheConfig(), new BuildScanConfig(), new WrapperValidationConfig())
31+
await setupGradle.setup(new CacheConfig(), new DevelocityConfig(), new WrapperValidationConfig())
3232

3333
// Configure the dependency graph submission
3434
await dependencyGraph.setup(new DependencyGraphConfig())

sources/src/cache-service-loader.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,14 @@ export async function getCacheService(cacheConfig: CacheConfig): Promise<CacheSe
6868
if (cacheConfig.isCacheDisabled()) {
6969
return new NoOpCacheService()
7070
}
71+
72+
const cacheService = await loadVendoredCacheService()
73+
if (cacheConfig.isCacheLicenseAccepted()) {
74+
return cacheService
75+
}
76+
7177
await logCacheLicenseWarning()
72-
return new LicenseWarningCacheService(await loadVendoredCacheService())
78+
return new LicenseWarningCacheService(cacheService)
7379
}
7480

7581
export async function loadVendoredCacheService(): Promise<CacheService> {
@@ -90,5 +96,5 @@ function findVendoredLibraryPath(): string {
9096
}
9197

9298
export async function logCacheLicenseWarning(): Promise<void> {
93-
console.warn(CACHE_LICENSE_WARNING)
99+
console.info(CACHE_LICENSE_WARNING)
94100
}

sources/src/configuration.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ export class CacheConfig {
166166
getCacheExcludes(): string[] {
167167
return core.getMultilineInput('gradle-home-cache-excludes')
168168
}
169+
170+
isCacheLicenseAccepted(): boolean {
171+
const dvConfig = new DevelocityConfig()
172+
return dvConfig.getDevelocityAccessKey() !== '' || dvConfig.hasTermsOfUseAgreement()
173+
}
169174
}
170175

171176
export enum CacheCleanupOption {
@@ -229,27 +234,27 @@ export enum JobSummaryOption {
229234
OnFailure = 'on-failure'
230235
}
231236

232-
export class BuildScanConfig {
237+
export class DevelocityConfig {
233238
static DevelocityAccessKeyEnvVar = 'DEVELOCITY_ACCESS_KEY'
234239
static GradleEnterpriseAccessKeyEnvVar = 'GRADLE_ENTERPRISE_ACCESS_KEY'
235240

236241
getBuildScanPublishEnabled(): boolean {
237242
return getBooleanInput('build-scan-publish') && this.verifyTermsOfUseAgreement()
238243
}
239244

240-
getBuildScanTermsOfUseUrl(): string {
245+
getTermsOfUseUrl(): string {
241246
return core.getInput('build-scan-terms-of-use-url')
242247
}
243248

244-
getBuildScanTermsOfUseAgree(): string {
249+
getTermsOfUseAgree(): string {
245250
return core.getInput('build-scan-terms-of-use-agree')
246251
}
247252

248253
getDevelocityAccessKey(): string {
249254
return (
250255
core.getInput('develocity-access-key') ||
251-
process.env[BuildScanConfig.DevelocityAccessKeyEnvVar] ||
252-
process.env[BuildScanConfig.GradleEnterpriseAccessKeyEnvVar] ||
256+
process.env[DevelocityConfig.DevelocityAccessKeyEnvVar] ||
257+
process.env[DevelocityConfig.GradleEnterpriseAccessKeyEnvVar] ||
253258
''
254259
)
255260
}
@@ -290,12 +295,17 @@ export class BuildScanConfig {
290295
return new PluginRepositoryConfig()
291296
}
292297

298+
hasTermsOfUseAgreement(): boolean {
299+
const develocityAccessKeySet = this.getDevelocityAccessKey() !== ''
300+
const termsUrlSet =
301+
this.getTermsOfUseUrl() === 'https://gradle.com/terms-of-service' ||
302+
this.getTermsOfUseUrl() === 'https://gradle.com/help/legal-terms-of-use'
303+
const termsAgreed = this.getTermsOfUseAgree() === 'yes'
304+
return develocityAccessKeySet || (termsUrlSet && termsAgreed)
305+
}
306+
293307
private verifyTermsOfUseAgreement(): boolean {
294-
if (
295-
(this.getBuildScanTermsOfUseUrl() !== 'https://gradle.com/terms-of-service' &&
296-
this.getBuildScanTermsOfUseUrl() !== 'https://gradle.com/help/legal-terms-of-use') ||
297-
this.getBuildScanTermsOfUseAgree() !== 'yes'
298-
) {
308+
if (!this.hasTermsOfUseAgreement()) {
299309
core.warning(
300310
`Terms of use at 'https://gradle.com/help/legal-terms-of-use' must be agreed in order to publish build scans.`
301311
)

sources/src/develocity/build-scan.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as core from '@actions/core'
2-
import {BuildScanConfig} from '../configuration'
2+
import {DevelocityConfig} from '../configuration'
33
import {setupToken} from './short-lived-token'
44

5-
export async function setup(config: BuildScanConfig): Promise<void> {
5+
export async function setup(config: DevelocityConfig): Promise<void> {
66
maybeExportVariable('DEVELOCITY_INJECTION_INIT_SCRIPT_NAME', 'gradle-actions.inject-develocity.init.gradle')
77
maybeExportVariable('DEVELOCITY_INJECTION_CUSTOM_VALUE', 'gradle-actions')
88

@@ -36,8 +36,8 @@ export async function setup(config: BuildScanConfig): Promise<void> {
3636
maybeExportVariable('DEVELOCITY_INJECTION_ENABLED', 'true')
3737
maybeExportVariable('DEVELOCITY_INJECTION_DEVELOCITY_PLUGIN_VERSION', '4.3.2')
3838
maybeExportVariable('DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION', '2.1')
39-
maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_URL', config.getBuildScanTermsOfUseUrl())
40-
maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_AGREE', config.getBuildScanTermsOfUseAgree())
39+
maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_URL', config.getTermsOfUseUrl())
40+
maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_AGREE', config.getTermsOfUseAgree())
4141
}
4242

4343
return setupToken(

sources/src/develocity/short-lived-token.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as core from '@actions/core'
22
import * as httpm from '@actions/http-client'
3-
import {BuildScanConfig} from '../configuration'
3+
import {DevelocityConfig} from '../configuration'
44
import {recordDeprecation} from '../deprecation-collector'
55

66
export async function setupToken(
@@ -28,20 +28,22 @@ export async function setupToken(
2828
}
2929

3030
function exportAccessKeyEnvVars(value: string): void {
31-
;[BuildScanConfig.DevelocityAccessKeyEnvVar, BuildScanConfig.GradleEnterpriseAccessKeyEnvVar].forEach(key =>
31+
;[DevelocityConfig.DevelocityAccessKeyEnvVar, DevelocityConfig.GradleEnterpriseAccessKeyEnvVar].forEach(key =>
3232
core.exportVariable(key, value)
3333
)
3434
}
3535

3636
function handleMissingAccessToken(): void {
3737
core.warning(`Failed to fetch short-lived token for Develocity`)
3838

39-
if (process.env[BuildScanConfig.GradleEnterpriseAccessKeyEnvVar]) {
39+
if (process.env[DevelocityConfig.GradleEnterpriseAccessKeyEnvVar]) {
4040
// We do not clear the GRADLE_ENTERPRISE_ACCESS_KEY env var in v3, to let the users upgrade to DV 2024.1
41-
recordDeprecation(`The ${BuildScanConfig.GradleEnterpriseAccessKeyEnvVar} env var is deprecated`)
41+
recordDeprecation(`The ${DevelocityConfig.GradleEnterpriseAccessKeyEnvVar} env var is deprecated`)
4242
}
43-
if (process.env[BuildScanConfig.DevelocityAccessKeyEnvVar]) {
44-
core.warning(`The ${BuildScanConfig.DevelocityAccessKeyEnvVar} env var should be mapped to a short-lived token`)
43+
if (process.env[DevelocityConfig.DevelocityAccessKeyEnvVar]) {
44+
core.warning(
45+
`The ${DevelocityConfig.DevelocityAccessKeyEnvVar} env var should be mapped to a short-lived token`
46+
)
4547
}
4648
}
4749

0 commit comments

Comments
 (0)