Skip to content

Commit

Permalink
Make it easy to publish to scans.gradle.com (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdaz authored Jan 25, 2024
2 parents 75b3db1 + 90d7c1a commit 1b6cac1
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 24 deletions.
47 changes: 42 additions & 5 deletions .github/workflows/integ-test-inject-develocity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ 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
DEVELOCITY_INJECTION_ENABLED: true
DEVELOCITY_URL: https://ge.solutions-team.gradle.com
DEVELOCITY_PLUGIN_VERSION: 3.16.1
DEVELOCITY_CCUD_PLUGIN_VERSION: 1.12.1
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }} # This env var has not (yet) been renamed/aliased in GE plugin 3.16.1

jobs:
inject-develocity:
env:
DEVELOCITY_INJECTION_ENABLED: true
DEVELOCITY_URL: https://ge.solutions-team.gradle.com
DEVELOCITY_PLUGIN_VERSION: 3.16.1
DEVELOCITY_CCUD_PLUGIN_VERSION: 1.12.1
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }} # This env var has not (yet) been renamed/aliased in GE plugin 3.16.1
strategy:
matrix:
gradle: [current, 7.6.2, 6.9.4, 5.6.4]
Expand Down Expand Up @@ -58,3 +59,39 @@ jobs:
with:
script: |
core.setFailed('No Build Scan detected')
build-scan-publish:
strategy:
matrix:
gradle: [current, 7.6.2, 6.9.4, 5.6.4]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Download distribution if required
uses: ./.github/actions/download-dist
- name: Setup Java
uses: actions/setup-java@v4
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 }}
build-scan-publish: true
build-scan-terms-of-service-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-service-agree: "yes"
- 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@v7
with:
script: |
core.setFailed('No Build Scan detected')
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,26 @@ The `init-script` supports a number of additional configuration parameters that
## Publishing to scans.gradle.com

Develocity injection is designed to enable publishing of build scans to a Develocity instance,
and is not suitable for publishing to the public Build Scans instance (https://scans.gradle.com).
but is also useful for publishing to the public Build Scans instance (https://scans.gradle.com).

In order to publish Build Scans to scans.gradle.com, you need to:
- Apply the Develocity plugin to your build configuration ([see docs](https://docs.gradle.com/enterprise/get-started/#applying_the_plugin))
- Programmatically accept the Terms of Service for scans.gradle.com ([see docs](https://docs.gradle.com/enterprise/gradle-plugin/#connecting_to_scans_gradle_com))
- Execute the build with `--scan` or configure your build with `publishAlways()` ([see docs](https://docs.gradle.com/enterprise/get-started/#always_publishing_a_build_scan))
To publish to https://scans.gradle.com, you must specify in your workflow that you accept the [Gradle Terms of Service](https://gradle.com/terms-of-service).

```yaml
name: Run build and publish Build Scan
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Gradle to publish build scans
uses: gradle/gradle-build-action@v2
with:
build-scan-publish: true
build-scan-terms-of-service-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-service-agree: "yes"
- name: Run a Gradle build - a build scan will be published automatically
run: ./gradlew build
```

15 changes: 15 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ inputs:
description: Specifies the number of days to retain any artifacts generated by the action. If not set, the default retention settings for the repository will apply.
required: false

build-scan-publish:
description: |
Set to 'true' to automatically publish build results as a Build Scan on scans.gradle.com.
For publication to succeed without user input, you must also provide values for `build-scan-terms-of-service-url` and 'build-scan-terms-of-service-agree'.
required: false
default: false

build-scan-terms-of-service-url:
description: The URL to the Build Scan® terms of service. This input must be set to 'https://gradle.com/terms-of-service'.
required: false

build-scan-terms-of-service-agree:
description: Indicate that you agree to the Build Scan® terms of service. This input value must be "yes".
required: false

# DEPRECATED ACTION INPUTS
arguments:
description: Gradle command line arguments (supports multi-line input)
Expand Down
75 changes: 74 additions & 1 deletion dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138544,6 +138544,65 @@ function loadBuildResults() {
exports.loadBuildResults = loadBuildResults;


/***/ }),

/***/ 85772:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.setup = void 0;
const core = __importStar(__nccwpck_require__(42186));
const input_params_1 = __nccwpck_require__(23885);
function setup() {
if ((0, input_params_1.getBuildScanPublishEnabled)() && verifyTermsOfServiceAgreement()) {
maybeExportVariable('DEVELOCITY_INJECTION_ENABLED', 'true');
maybeExportVariable('DEVELOCITY_PLUGIN_VERSION', '3.16.1');
maybeExportVariable('DEVELOCITY_CCUD_PLUGIN_VERSION', '1.12.1');
maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_URL', (0, input_params_1.getBuildScanTermsOfServiceUrl)());
maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_AGREE', (0, input_params_1.getBuildScanTermsOfServiceAgree)());
}
}
exports.setup = setup;
function verifyTermsOfServiceAgreement() {
if ((0, input_params_1.getBuildScanTermsOfServiceUrl)() !== 'https://gradle.com/terms-of-service' ||
(0, input_params_1.getBuildScanTermsOfServiceAgree)() !== 'yes') {
core.warning(`Terms of service must be agreed in order to publish build scans.`);
return false;
}
return true;
}
function maybeExportVariable(variableName, value) {
if (!process.env[variableName]) {
core.exportVariable(variableName, value);
}
}


/***/ }),

/***/ 47591:
Expand Down Expand Up @@ -140374,7 +140433,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.JobSummaryOption = exports.DependencyGraphOption = exports.parseNumericInput = exports.getArtifactRetentionDays = exports.getDependencyGraphContinueOnFailure = exports.getDependencyGraphOption = exports.getPRCommentOption = exports.getJobSummaryOption = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.getCacheEncryptionKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
exports.JobSummaryOption = exports.DependencyGraphOption = exports.parseNumericInput = exports.getArtifactRetentionDays = exports.getDependencyGraphContinueOnFailure = exports.getDependencyGraphOption = exports.getBuildScanTermsOfServiceAgree = exports.getBuildScanTermsOfServiceUrl = exports.getBuildScanPublishEnabled = exports.getPRCommentOption = exports.getJobSummaryOption = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.getCacheEncryptionKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
const core = __importStar(__nccwpck_require__(42186));
const string_argv_1 = __nccwpck_require__(19663);
function isCacheDisabled() {
Expand Down Expand Up @@ -140450,6 +140509,18 @@ function getPRCommentOption() {
return parseJobSummaryOption('add-job-summary-as-pr-comment');
}
exports.getPRCommentOption = getPRCommentOption;
function getBuildScanPublishEnabled() {
return getBooleanInput('build-scan-publish');
}
exports.getBuildScanPublishEnabled = getBuildScanPublishEnabled;
function getBuildScanTermsOfServiceUrl() {
return core.getInput('build-scan-terms-of-service-url');
}
exports.getBuildScanTermsOfServiceUrl = getBuildScanTermsOfServiceUrl;
function getBuildScanTermsOfServiceAgree() {
return core.getInput('build-scan-terms-of-service-agree');
}
exports.getBuildScanTermsOfServiceAgree = getBuildScanTermsOfServiceAgree;
function parseJobSummaryOption(paramName) {
const val = core.getInput(paramName);
switch (val.toLowerCase().trim()) {
Expand Down Expand Up @@ -141100,6 +141171,7 @@ const layout = __importStar(__nccwpck_require__(28182));
const params = __importStar(__nccwpck_require__(23885));
const dependencyGraph = __importStar(__nccwpck_require__(80));
const jobSummary = __importStar(__nccwpck_require__(87345));
const buildScan = __importStar(__nccwpck_require__(85772));
const build_results_1 = __nccwpck_require__(82107);
const cache_reporting_1 = __nccwpck_require__(66674);
const daemon_controller_1 = __nccwpck_require__(85146);
Expand All @@ -141123,6 +141195,7 @@ function setup() {
yield caches.restore(userHome, gradleUserHome, cacheListener);
core.saveState(CACHE_LISTENER, cacheListener.stringify());
yield dependencyGraph.setup(params.getDependencyGraphOption());
buildScan.setup();
});
}
exports.setup = setup;
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

75 changes: 74 additions & 1 deletion dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135997,6 +135997,65 @@ function loadBuildResults() {
exports.loadBuildResults = loadBuildResults;


/***/ }),

/***/ 85772:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.setup = void 0;
const core = __importStar(__nccwpck_require__(42186));
const input_params_1 = __nccwpck_require__(23885);
function setup() {
if ((0, input_params_1.getBuildScanPublishEnabled)() && verifyTermsOfServiceAgreement()) {
maybeExportVariable('DEVELOCITY_INJECTION_ENABLED', 'true');
maybeExportVariable('DEVELOCITY_PLUGIN_VERSION', '3.16.1');
maybeExportVariable('DEVELOCITY_CCUD_PLUGIN_VERSION', '1.12.1');
maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_URL', (0, input_params_1.getBuildScanTermsOfServiceUrl)());
maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_AGREE', (0, input_params_1.getBuildScanTermsOfServiceAgree)());
}
}
exports.setup = setup;
function verifyTermsOfServiceAgreement() {
if ((0, input_params_1.getBuildScanTermsOfServiceUrl)() !== 'https://gradle.com/terms-of-service' ||
(0, input_params_1.getBuildScanTermsOfServiceAgree)() !== 'yes') {
core.warning(`Terms of service must be agreed in order to publish build scans.`);
return false;
}
return true;
}
function maybeExportVariable(variableName, value) {
if (!process.env[variableName]) {
core.exportVariable(variableName, value);
}
}


/***/ }),

/***/ 47591:
Expand Down Expand Up @@ -137695,7 +137754,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.JobSummaryOption = exports.DependencyGraphOption = exports.parseNumericInput = exports.getArtifactRetentionDays = exports.getDependencyGraphContinueOnFailure = exports.getDependencyGraphOption = exports.getPRCommentOption = exports.getJobSummaryOption = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.getCacheEncryptionKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
exports.JobSummaryOption = exports.DependencyGraphOption = exports.parseNumericInput = exports.getArtifactRetentionDays = exports.getDependencyGraphContinueOnFailure = exports.getDependencyGraphOption = exports.getBuildScanTermsOfServiceAgree = exports.getBuildScanTermsOfServiceUrl = exports.getBuildScanPublishEnabled = exports.getPRCommentOption = exports.getJobSummaryOption = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.getCacheEncryptionKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
const core = __importStar(__nccwpck_require__(42186));
const string_argv_1 = __nccwpck_require__(19663);
function isCacheDisabled() {
Expand Down Expand Up @@ -137771,6 +137830,18 @@ function getPRCommentOption() {
return parseJobSummaryOption('add-job-summary-as-pr-comment');
}
exports.getPRCommentOption = getPRCommentOption;
function getBuildScanPublishEnabled() {
return getBooleanInput('build-scan-publish');
}
exports.getBuildScanPublishEnabled = getBuildScanPublishEnabled;
function getBuildScanTermsOfServiceUrl() {
return core.getInput('build-scan-terms-of-service-url');
}
exports.getBuildScanTermsOfServiceUrl = getBuildScanTermsOfServiceUrl;
function getBuildScanTermsOfServiceAgree() {
return core.getInput('build-scan-terms-of-service-agree');
}
exports.getBuildScanTermsOfServiceAgree = getBuildScanTermsOfServiceAgree;
function parseJobSummaryOption(paramName) {
const val = core.getInput(paramName);
switch (val.toLowerCase().trim()) {
Expand Down Expand Up @@ -138197,6 +138268,7 @@ const layout = __importStar(__nccwpck_require__(28182));
const params = __importStar(__nccwpck_require__(23885));
const dependencyGraph = __importStar(__nccwpck_require__(80));
const jobSummary = __importStar(__nccwpck_require__(87345));
const buildScan = __importStar(__nccwpck_require__(85772));
const build_results_1 = __nccwpck_require__(82107);
const cache_reporting_1 = __nccwpck_require__(66674);
const daemon_controller_1 = __nccwpck_require__(85146);
Expand All @@ -138220,6 +138292,7 @@ function setup() {
yield caches.restore(userHome, gradleUserHome, cacheListener);
core.saveState(CACHE_LISTENER, cacheListener.stringify());
yield dependencyGraph.setup(params.getDependencyGraphOption());
buildScan.setup();
});
}
exports.setup = setup;
Expand Down
2 changes: 1 addition & 1 deletion dist/post/index.js.map

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions src/build-scan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as core from '@actions/core'
import {
getBuildScanPublishEnabled,
getBuildScanTermsOfServiceUrl,
getBuildScanTermsOfServiceAgree
} from './input-params'

export function setup(): void {
if (getBuildScanPublishEnabled() && verifyTermsOfServiceAgreement()) {
maybeExportVariable('DEVELOCITY_INJECTION_ENABLED', 'true')
maybeExportVariable('DEVELOCITY_PLUGIN_VERSION', '3.16.1')
maybeExportVariable('DEVELOCITY_CCUD_PLUGIN_VERSION', '1.12.1')
maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_URL', getBuildScanTermsOfServiceUrl())
maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_AGREE', getBuildScanTermsOfServiceAgree())
}
}

function verifyTermsOfServiceAgreement(): boolean {
if (
getBuildScanTermsOfServiceUrl() !== 'https://gradle.com/terms-of-service' ||
getBuildScanTermsOfServiceAgree() !== 'yes'
) {
core.warning(`Terms of service must be agreed in order to publish build scans.`)
return false
}
return true
}

function maybeExportVariable(variableName: string, value: unknown): void {
if (!process.env[variableName]) {
core.exportVariable(variableName, value)
}
}
12 changes: 12 additions & 0 deletions src/input-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ export function getPRCommentOption(): JobSummaryOption {
return parseJobSummaryOption('add-job-summary-as-pr-comment')
}

export function getBuildScanPublishEnabled(): boolean {
return getBooleanInput('build-scan-publish')
}

export function getBuildScanTermsOfServiceUrl(): string {
return core.getInput('build-scan-terms-of-service-url')
}

export function getBuildScanTermsOfServiceAgree(): string {
return core.getInput('build-scan-terms-of-service-agree')
}

function parseJobSummaryOption(paramName: string): JobSummaryOption {
const val = core.getInput(paramName)
switch (val.toLowerCase().trim()) {
Expand Down
Loading

0 comments on commit 1b6cac1

Please sign in to comment.