diff --git a/.github/workflows/demo-job-summary.yml b/.github/workflows/demo-job-summary.yml index 5db91267..977d45c5 100644 --- a/.github/workflows/demo-job-summary.yml +++ b/.github/workflows/demo-job-summary.yml @@ -131,3 +131,38 @@ jobs: - name: Build kotlin-dsl project working-directory: .github/workflow-samples/kotlin-dsl run: ./gradlew assemble + + terms-of-use-accepted: + needs: build-distribution + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Initialize integ-test + uses: ./.github/actions/init-integ-test + + - name: Setup Gradle + uses: ./setup-gradle + with: + build-scan-terms-of-use-url: https://gradle.com/help/legal-terms-of-use + build-scan-terms-of-use-agree: yes + - name: Build kotlin-dsl project + working-directory: .github/workflow-samples/kotlin-dsl + run: ./gradlew assemble + + develocity-access-key-set: + needs: build-distribution + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Initialize integ-test + uses: ./.github/actions/init-integ-test + + - name: Setup Gradle + uses: ./setup-gradle + with: + develocity-access-key: ${{ secrets.DV_SOLUTIONS_ACCESS_KEY }} + - name: Build kotlin-dsl project + working-directory: .github/workflow-samples/kotlin-dsl + run: ./gradlew assemble diff --git a/README.md b/README.md index fa193b5b..11e898a6 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ This repository contains a set of GitHub Actions that are useful for building Gr > Use of the `gradle-actions-caching` component is subject to a separate license, available at https://gradle.com/legal/terms-of-use/. > If you do not agree to these license terms, do not use the `gradle-actions-caching` component. +This license notice will be displayed in workflow logs and each job summary. To suppress this message, +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). + ## The `setup-gradle` action The `setup-gradle` action can be used to configure Gradle for optimal execution on any platform supported by GitHub Actions. diff --git a/docs/dependency-submission.md b/docs/dependency-submission.md index 103df368..d16993e3 100644 --- a/docs/dependency-submission.md +++ b/docs/dependency-submission.md @@ -28,6 +28,9 @@ If you're confused by the behaviour you're seeing or have specific questions, pl > Use of the `gradle-actions-caching` component is subject to a separate license, available at https://gradle.com/legal/terms-of-use/. > If you do not agree to these license terms, do not use the `gradle-actions-caching` component. +This license notice will be displayed in workflow logs and each job summary. To suppress this message, +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). + ## General usage The following workflow will generate a dependency graph for a Gradle project and submit it immediately to the repository via the diff --git a/docs/setup-gradle.md b/docs/setup-gradle.md index fd0ae0d2..ee52a37d 100644 --- a/docs/setup-gradle.md +++ b/docs/setup-gradle.md @@ -15,6 +15,9 @@ This GitHub Action can be used to configure Gradle for optimal execution on any > Use of the `gradle-actions-caching` component is subject to a separate license, available at https://gradle.com/legal/terms-of-use/. > If you do not agree to these license terms, do not use the `gradle-actions-caching` component. +This license notice will be displayed in workflow logs and each job summary. To suppress this message, +either [accept the terms of use](#publishing-to-scansgradlecom) in your workflow, or [provide a Develocity access key](#managing-develocity-access-keys). + ## Why use the `setup-gradle` action? 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. diff --git a/sources/src/actions/dependency-submission/main.ts b/sources/src/actions/dependency-submission/main.ts index ca6f8754..c488dd33 100644 --- a/sources/src/actions/dependency-submission/main.ts +++ b/sources/src/actions/dependency-submission/main.ts @@ -5,7 +5,7 @@ import * as dependencyGraph from '../../dependency-graph' import {parseArgsStringToArgv} from 'string-argv' import { - BuildScanConfig, + DevelocityConfig, CacheConfig, DependencyGraphConfig, DependencyGraphOption, @@ -25,7 +25,7 @@ export async function run(): Promise { setActionId('gradle/actions/dependency-submission') // Configure Gradle environment (Gradle User Home) - await setupGradle.setup(new CacheConfig(), new BuildScanConfig(), new WrapperValidationConfig()) + await setupGradle.setup(new CacheConfig(), new DevelocityConfig(), new WrapperValidationConfig()) // Capture the enabled state of dependency-graph const originallyEnabled = process.env['GITHUB_DEPENDENCY_GRAPH_ENABLED'] diff --git a/sources/src/actions/setup-gradle/main.ts b/sources/src/actions/setup-gradle/main.ts index a15e89ea..c649fee1 100644 --- a/sources/src/actions/setup-gradle/main.ts +++ b/sources/src/actions/setup-gradle/main.ts @@ -2,7 +2,7 @@ import * as setupGradle from '../../setup-gradle' import * as provisioner from '../../execution/provision' import * as dependencyGraph from '../../dependency-graph' import { - BuildScanConfig, + DevelocityConfig, CacheConfig, DependencyGraphConfig, GradleExecutionConfig, @@ -28,7 +28,7 @@ export async function run(): Promise { setActionId('gradle/actions/setup-gradle') // Configure Gradle environment (Gradle User Home) - await setupGradle.setup(new CacheConfig(), new BuildScanConfig(), new WrapperValidationConfig()) + await setupGradle.setup(new CacheConfig(), new DevelocityConfig(), new WrapperValidationConfig()) // Configure the dependency graph submission await dependencyGraph.setup(new DependencyGraphConfig()) diff --git a/sources/src/cache-service-loader.ts b/sources/src/cache-service-loader.ts index f6eee309..d772c358 100644 --- a/sources/src/cache-service-loader.ts +++ b/sources/src/cache-service-loader.ts @@ -68,8 +68,14 @@ export async function getCacheService(cacheConfig: CacheConfig): Promise { @@ -90,5 +96,5 @@ function findVendoredLibraryPath(): string { } export async function logCacheLicenseWarning(): Promise { - console.warn(CACHE_LICENSE_WARNING) + console.info(CACHE_LICENSE_WARNING) } diff --git a/sources/src/configuration.ts b/sources/src/configuration.ts index dbcc6ad3..0d85199a 100644 --- a/sources/src/configuration.ts +++ b/sources/src/configuration.ts @@ -166,6 +166,11 @@ export class CacheConfig { getCacheExcludes(): string[] { return core.getMultilineInput('gradle-home-cache-excludes') } + + isCacheLicenseAccepted(): boolean { + const dvConfig = new DevelocityConfig() + return dvConfig.getDevelocityAccessKey() !== '' || dvConfig.hasTermsOfUseAgreement() + } } export enum CacheCleanupOption { @@ -229,7 +234,7 @@ export enum JobSummaryOption { OnFailure = 'on-failure' } -export class BuildScanConfig { +export class DevelocityConfig { static DevelocityAccessKeyEnvVar = 'DEVELOCITY_ACCESS_KEY' static GradleEnterpriseAccessKeyEnvVar = 'GRADLE_ENTERPRISE_ACCESS_KEY' @@ -237,19 +242,19 @@ export class BuildScanConfig { return getBooleanInput('build-scan-publish') && this.verifyTermsOfUseAgreement() } - getBuildScanTermsOfUseUrl(): string { + getTermsOfUseUrl(): string { return core.getInput('build-scan-terms-of-use-url') } - getBuildScanTermsOfUseAgree(): string { + getTermsOfUseAgree(): string { return core.getInput('build-scan-terms-of-use-agree') } getDevelocityAccessKey(): string { return ( core.getInput('develocity-access-key') || - process.env[BuildScanConfig.DevelocityAccessKeyEnvVar] || - process.env[BuildScanConfig.GradleEnterpriseAccessKeyEnvVar] || + process.env[DevelocityConfig.DevelocityAccessKeyEnvVar] || + process.env[DevelocityConfig.GradleEnterpriseAccessKeyEnvVar] || '' ) } @@ -290,12 +295,17 @@ export class BuildScanConfig { return new PluginRepositoryConfig() } + hasTermsOfUseAgreement(): boolean { + const develocityAccessKeySet = this.getDevelocityAccessKey() !== '' + const termsUrlSet = + this.getTermsOfUseUrl() === 'https://gradle.com/terms-of-service' || + this.getTermsOfUseUrl() === 'https://gradle.com/help/legal-terms-of-use' + const termsAgreed = this.getTermsOfUseAgree() === 'yes' + return develocityAccessKeySet || (termsUrlSet && termsAgreed) + } + private verifyTermsOfUseAgreement(): boolean { - if ( - (this.getBuildScanTermsOfUseUrl() !== 'https://gradle.com/terms-of-service' && - this.getBuildScanTermsOfUseUrl() !== 'https://gradle.com/help/legal-terms-of-use') || - this.getBuildScanTermsOfUseAgree() !== 'yes' - ) { + if (!this.hasTermsOfUseAgreement()) { core.warning( `Terms of use at 'https://gradle.com/help/legal-terms-of-use' must be agreed in order to publish build scans.` ) diff --git a/sources/src/develocity/build-scan.ts b/sources/src/develocity/build-scan.ts index a3b83462..2651689d 100644 --- a/sources/src/develocity/build-scan.ts +++ b/sources/src/develocity/build-scan.ts @@ -1,8 +1,8 @@ import * as core from '@actions/core' -import {BuildScanConfig} from '../configuration' +import {DevelocityConfig} from '../configuration' import {setupToken} from './short-lived-token' -export async function setup(config: BuildScanConfig): Promise { +export async function setup(config: DevelocityConfig): Promise { maybeExportVariable('DEVELOCITY_INJECTION_INIT_SCRIPT_NAME', 'gradle-actions.inject-develocity.init.gradle') maybeExportVariable('DEVELOCITY_INJECTION_CUSTOM_VALUE', 'gradle-actions') @@ -36,8 +36,8 @@ export async function setup(config: BuildScanConfig): Promise { maybeExportVariable('DEVELOCITY_INJECTION_ENABLED', 'true') maybeExportVariable('DEVELOCITY_INJECTION_DEVELOCITY_PLUGIN_VERSION', '4.3.2') maybeExportVariable('DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION', '2.1') - maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_URL', config.getBuildScanTermsOfUseUrl()) - maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_AGREE', config.getBuildScanTermsOfUseAgree()) + maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_URL', config.getTermsOfUseUrl()) + maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_AGREE', config.getTermsOfUseAgree()) } return setupToken( diff --git a/sources/src/develocity/short-lived-token.ts b/sources/src/develocity/short-lived-token.ts index 0e3668d6..3708887f 100644 --- a/sources/src/develocity/short-lived-token.ts +++ b/sources/src/develocity/short-lived-token.ts @@ -1,6 +1,6 @@ import * as core from '@actions/core' import * as httpm from '@actions/http-client' -import {BuildScanConfig} from '../configuration' +import {DevelocityConfig} from '../configuration' import {recordDeprecation} from '../deprecation-collector' export async function setupToken( @@ -28,7 +28,7 @@ export async function setupToken( } function exportAccessKeyEnvVars(value: string): void { - ;[BuildScanConfig.DevelocityAccessKeyEnvVar, BuildScanConfig.GradleEnterpriseAccessKeyEnvVar].forEach(key => + ;[DevelocityConfig.DevelocityAccessKeyEnvVar, DevelocityConfig.GradleEnterpriseAccessKeyEnvVar].forEach(key => core.exportVariable(key, value) ) } @@ -36,12 +36,14 @@ function exportAccessKeyEnvVars(value: string): void { function handleMissingAccessToken(): void { core.warning(`Failed to fetch short-lived token for Develocity`) - if (process.env[BuildScanConfig.GradleEnterpriseAccessKeyEnvVar]) { + if (process.env[DevelocityConfig.GradleEnterpriseAccessKeyEnvVar]) { // We do not clear the GRADLE_ENTERPRISE_ACCESS_KEY env var in v3, to let the users upgrade to DV 2024.1 - recordDeprecation(`The ${BuildScanConfig.GradleEnterpriseAccessKeyEnvVar} env var is deprecated`) + recordDeprecation(`The ${DevelocityConfig.GradleEnterpriseAccessKeyEnvVar} env var is deprecated`) } - if (process.env[BuildScanConfig.DevelocityAccessKeyEnvVar]) { - core.warning(`The ${BuildScanConfig.DevelocityAccessKeyEnvVar} env var should be mapped to a short-lived token`) + if (process.env[DevelocityConfig.DevelocityAccessKeyEnvVar]) { + core.warning( + `The ${DevelocityConfig.DevelocityAccessKeyEnvVar} env var should be mapped to a short-lived token` + ) } } diff --git a/sources/src/setup-gradle.ts b/sources/src/setup-gradle.ts index 8333c4ef..c7706418 100644 --- a/sources/src/setup-gradle.ts +++ b/sources/src/setup-gradle.ts @@ -10,7 +10,7 @@ import {loadBuildResults, markBuildResultsProcessed} from './build-results' import {getCacheService} from './cache-service-loader' import {CacheOptions} from './cache-service' import { - BuildScanConfig, + DevelocityConfig, CacheConfig, SummaryConfig, WrapperValidationConfig, @@ -24,7 +24,7 @@ const GRADLE_USER_HOME = 'GRADLE_USER_HOME' export async function setup( cacheConfig: CacheConfig, - buildScanConfig: BuildScanConfig, + develocityConfig: DevelocityConfig, wrapperValidationConfig: WrapperValidationConfig ): Promise { const userHome = await determineUserHome() @@ -49,7 +49,7 @@ export async function setup( await wrapperValidator.validateWrappers(wrapperValidationConfig, getWorkspaceDirectory(), gradleUserHome) - await buildScan.setup(buildScanConfig) + await buildScan.setup(develocityConfig) return true }