Merge pull request #40 from gradle/dd/v3.1

Improvements in preparation for v3.1
This commit is contained in:
Daz DeBoer 2024-02-11 17:45:41 -07:00 committed by GitHub
commit 5e512f6e1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 119 additions and 16 deletions

View File

@ -10,7 +10,7 @@ dependencies {
api("org.apache.commons:commons-math3:3.6.1") api("org.apache.commons:commons-math3:3.6.1")
implementation("com.google.guava:guava:33.0.0-jre") implementation("com.google.guava:guava:33.0.0-jre")
testImplementation("org.junit.jupiter:junit-jupiter:5.10.1") testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
} }
tasks.test { tasks.test {

View File

@ -73,6 +73,7 @@ runs:
arguments: | arguments: |
-Dorg.gradle.configureondemand=false -Dorg.gradle.configureondemand=false
-Dorg.gradle.dependency.verification=off -Dorg.gradle.dependency.verification=off
-Dorg.gradle.unsafe.isolated-projects=false
:ForceDependencyResolutionPlugin_resolveAllDependencies :ForceDependencyResolutionPlugin_resolveAllDependencies
${{ inputs.additional-arguments }} ${{ inputs.additional-arguments }}
- name: Download and submit dependency graph - name: Download and submit dependency graph

View File

@ -139144,6 +139144,9 @@ class GradleStateCache {
fs_1.default.mkdirSync(actionCacheDir, { recursive: true }); fs_1.default.mkdirSync(actionCacheDir, { recursive: true });
this.copyInitScripts(); this.copyInitScripts();
this.registerToolchains(); this.registerToolchains();
if (core.isDebug()) {
this.configureInfoLogLevel();
}
} }
copyInitScripts() { copyInitScripts() {
const initScriptsDir = path_1.default.resolve(this.gradleUserHome, 'init.d'); const initScriptsDir = path_1.default.resolve(this.gradleUserHome, 'init.d');
@ -139182,9 +139185,22 @@ class GradleStateCache {
const absolutePath = path_1.default.resolve(__dirname, '..', '..', '..', 'sources', 'src', 'resources', ...paths); const absolutePath = path_1.default.resolve(__dirname, '..', '..', '..', 'sources', 'src', 'resources', ...paths);
return fs_1.default.readFileSync(absolutePath, 'utf8'); return fs_1.default.readFileSync(absolutePath, 'utf8');
} }
configureInfoLogLevel() {
const infoProperties = `org.gradle.logging.level=info\norg.gradle.logging.stacktrace=all\n`;
const propertiesFile = path_1.default.resolve(this.gradleUserHome, 'gradle.properties');
if (fs_1.default.existsSync(propertiesFile)) {
core.info(`Merged --info and --stacktrace into existing ${propertiesFile} file`);
const existingProperties = fs_1.default.readFileSync(propertiesFile, 'utf-8');
fs_1.default.writeFileSync(propertiesFile, `${infoProperties}\n${existingProperties}`);
}
else {
core.info(`Created a new ${propertiesFile} with --info and --stacktrace`);
fs_1.default.writeFileSync(propertiesFile, infoProperties);
}
}
debugReportGradleUserHomeSize(label) { debugReportGradleUserHomeSize(label) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (!(0, cache_utils_1.isCacheDebuggingEnabled)()) { if (!(0, cache_utils_1.isCacheDebuggingEnabled)() && !core.isDebug()) {
return; return;
} }
if (!fs_1.default.existsSync(this.gradleUserHome)) { if (!fs_1.default.existsSync(this.gradleUserHome)) {
@ -141041,7 +141057,9 @@ function addPRComment(jobSummary) {
const pull_request_number = context.payload.pull_request.number; const pull_request_number = context.payload.pull_request.number;
core.info(`Adding Job Summary as comment to PR #${pull_request_number}.`); core.info(`Adding Job Summary as comment to PR #${pull_request_number}.`);
const prComment = `<h3>Job Summary for Gradle</h3> const prComment = `<h3>Job Summary for Gradle</h3>
<h5>${github.context.workflow} :: <em>${github.context.job}</em></h5> <a href="${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}" target="_blank">
<h5>${context.workflow} :: <em>${context.job}</em></h5>
</a>
${jobSummary}`; ${jobSummary}`;
const github_token = params.getGithubToken(); const github_token = params.getGithubToken();
@ -141110,7 +141128,7 @@ function renderBuildScan(result) {
function renderBuildScanBadge(outcomeText, outcomeColor, targetUrl) { function renderBuildScanBadge(outcomeText, outcomeColor, targetUrl) {
const badgeUrl = `https://img.shields.io/badge/Build%20Scan%C2%AE-${outcomeText}-${outcomeColor}?logo=Gradle`; const badgeUrl = `https://img.shields.io/badge/Build%20Scan%C2%AE-${outcomeText}-${outcomeColor}?logo=Gradle`;
const badgeHtml = `<img src="${badgeUrl}" alt="Build Scan ${outcomeText}" />`; const badgeHtml = `<img src="${badgeUrl}" alt="Build Scan ${outcomeText}" />`;
return `<a href="${targetUrl}" rel="nofollow">${badgeHtml}</a>`; return `<a href="${targetUrl}" rel="nofollow" target="_blank">${badgeHtml}</a>`;
} }
function shouldGenerateJobSummary(buildResults) { function shouldGenerateJobSummary(buildResults) {
if (!process.env[summary_1.SUMMARY_ENV_VAR]) { if (!process.env[summary_1.SUMMARY_ENV_VAR]) {

File diff suppressed because one or more lines are too long

View File

@ -136597,6 +136597,9 @@ class GradleStateCache {
fs_1.default.mkdirSync(actionCacheDir, { recursive: true }); fs_1.default.mkdirSync(actionCacheDir, { recursive: true });
this.copyInitScripts(); this.copyInitScripts();
this.registerToolchains(); this.registerToolchains();
if (core.isDebug()) {
this.configureInfoLogLevel();
}
} }
copyInitScripts() { copyInitScripts() {
const initScriptsDir = path_1.default.resolve(this.gradleUserHome, 'init.d'); const initScriptsDir = path_1.default.resolve(this.gradleUserHome, 'init.d');
@ -136635,9 +136638,22 @@ class GradleStateCache {
const absolutePath = path_1.default.resolve(__dirname, '..', '..', '..', 'sources', 'src', 'resources', ...paths); const absolutePath = path_1.default.resolve(__dirname, '..', '..', '..', 'sources', 'src', 'resources', ...paths);
return fs_1.default.readFileSync(absolutePath, 'utf8'); return fs_1.default.readFileSync(absolutePath, 'utf8');
} }
configureInfoLogLevel() {
const infoProperties = `org.gradle.logging.level=info\norg.gradle.logging.stacktrace=all\n`;
const propertiesFile = path_1.default.resolve(this.gradleUserHome, 'gradle.properties');
if (fs_1.default.existsSync(propertiesFile)) {
core.info(`Merged --info and --stacktrace into existing ${propertiesFile} file`);
const existingProperties = fs_1.default.readFileSync(propertiesFile, 'utf-8');
fs_1.default.writeFileSync(propertiesFile, `${infoProperties}\n${existingProperties}`);
}
else {
core.info(`Created a new ${propertiesFile} with --info and --stacktrace`);
fs_1.default.writeFileSync(propertiesFile, infoProperties);
}
}
debugReportGradleUserHomeSize(label) { debugReportGradleUserHomeSize(label) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (!(0, cache_utils_1.isCacheDebuggingEnabled)()) { if (!(0, cache_utils_1.isCacheDebuggingEnabled)() && !core.isDebug()) {
return; return;
} }
if (!fs_1.default.existsSync(this.gradleUserHome)) { if (!fs_1.default.existsSync(this.gradleUserHome)) {
@ -138360,7 +138376,9 @@ function addPRComment(jobSummary) {
const pull_request_number = context.payload.pull_request.number; const pull_request_number = context.payload.pull_request.number;
core.info(`Adding Job Summary as comment to PR #${pull_request_number}.`); core.info(`Adding Job Summary as comment to PR #${pull_request_number}.`);
const prComment = `<h3>Job Summary for Gradle</h3> const prComment = `<h3>Job Summary for Gradle</h3>
<h5>${github.context.workflow} :: <em>${github.context.job}</em></h5> <a href="${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}" target="_blank">
<h5>${context.workflow} :: <em>${context.job}</em></h5>
</a>
${jobSummary}`; ${jobSummary}`;
const github_token = params.getGithubToken(); const github_token = params.getGithubToken();
@ -138429,7 +138447,7 @@ function renderBuildScan(result) {
function renderBuildScanBadge(outcomeText, outcomeColor, targetUrl) { function renderBuildScanBadge(outcomeText, outcomeColor, targetUrl) {
const badgeUrl = `https://img.shields.io/badge/Build%20Scan%C2%AE-${outcomeText}-${outcomeColor}?logo=Gradle`; const badgeUrl = `https://img.shields.io/badge/Build%20Scan%C2%AE-${outcomeText}-${outcomeColor}?logo=Gradle`;
const badgeHtml = `<img src="${badgeUrl}" alt="Build Scan ${outcomeText}" />`; const badgeHtml = `<img src="${badgeUrl}" alt="Build Scan ${outcomeText}" />`;
return `<a href="${targetUrl}" rel="nofollow">${badgeHtml}</a>`; return `<a href="${targetUrl}" rel="nofollow" target="_blank">${badgeHtml}</a>`;
} }
function shouldGenerateJobSummary(buildResults) { function shouldGenerateJobSummary(buildResults) {
if (!process.env[summary_1.SUMMARY_ENV_VAR]) { if (!process.env[summary_1.SUMMARY_ENV_VAR]) {

File diff suppressed because one or more lines are too long

View File

@ -193,6 +193,16 @@ Specifically:
Using either of these mechanisms may interfere with the caching provided by this action. If you choose to use a different mechanism to save and restore the Gradle User Home, you should disable the caching provided by this action, as described above. Using either of these mechanisms may interfere with the caching provided by this action. If you choose to use a different mechanism to save and restore the Gradle User Home, you should disable the caching provided by this action, as described above.
### GitHub Action Debug support
To debug a failed job, GitHub provides a [debug mode](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging).
If this debug mode is active, this action adds `--info` and `--stacktrace` by writing these [Gradle properties](https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties) into the `${GRADLE_USER_HOME}/gradle.properties` file at the top.
To opt-out of this behaviour you can override these properties manually and put them into your `gradle.properties` file:
```properties
# default lifecycle
org.gradle.logging.level=lifecycle
org.gradle.logging.stacktrace=internal
```
### Cache debugging and analysis ### Cache debugging and analysis
A report of all cache entries restored and saved is printed to the Job Summary when saving the cache entries. A report of all cache entries restored and saved is printed to the Job Summary when saving the cache entries.
@ -205,7 +215,7 @@ env:
GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED: true GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED: true
``` ```
Note that this setting will also prevent certain cache operations from running in parallel, further assisting with debugging. Note that when the workflow is run in debug mode (above), cache debugging is automatically enabled.
## How Gradle User Home caching works ## How Gradle User Home caching works
@ -688,4 +698,3 @@ jobs:
- name: Run a Gradle build - a build scan will be published automatically - name: Run a Gradle build - a build scan will be published automatically
run: ./gradlew build run: ./gradlew build
``` ```

View File

@ -192,6 +192,10 @@ export class GradleStateCache {
// Copy the default toolchain definitions to `~/.m2/toolchains.xml` // Copy the default toolchain definitions to `~/.m2/toolchains.xml`
this.registerToolchains() this.registerToolchains()
if (core.isDebug()) {
this.configureInfoLogLevel()
}
} }
private copyInitScripts(): void { private copyInitScripts(): void {
@ -241,11 +245,30 @@ export class GradleStateCache {
} }
/** /**
* When cache debugging is enabled, this method will give a detailed report * When the GitHub environment ACTIONS_RUNNER_DEBUG is true, run Gradle with --info and --stacktrace.
* of the Gradle User Home contents. * see https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging
*
* @VisibleForTesting
*/
configureInfoLogLevel(): void {
const infoProperties = `org.gradle.logging.level=info\norg.gradle.logging.stacktrace=all\n`
const propertiesFile = path.resolve(this.gradleUserHome, 'gradle.properties')
if (fs.existsSync(propertiesFile)) {
core.info(`Merged --info and --stacktrace into existing ${propertiesFile} file`)
const existingProperties = fs.readFileSync(propertiesFile, 'utf-8')
fs.writeFileSync(propertiesFile, `${infoProperties}\n${existingProperties}`)
} else {
core.info(`Created a new ${propertiesFile} with --info and --stacktrace`)
fs.writeFileSync(propertiesFile, infoProperties)
}
}
/**
* When cache debugging is enabled (or ACTIONS_STEP_DEBUG is on),
* this method will give a detailed report of the Gradle User Home contents.
*/ */
private async debugReportGradleUserHomeSize(label: string): Promise<void> { private async debugReportGradleUserHomeSize(label: string): Promise<void> {
if (!isCacheDebuggingEnabled()) { if (!isCacheDebuggingEnabled() && !core.isDebug()) {
return return
} }
if (!fs.existsSync(this.gradleUserHome)) { if (!fs.existsSync(this.gradleUserHome)) {

View File

@ -41,7 +41,9 @@ async function addPRComment(jobSummary: string): Promise<void> {
core.info(`Adding Job Summary as comment to PR #${pull_request_number}.`) core.info(`Adding Job Summary as comment to PR #${pull_request_number}.`)
const prComment = `<h3>Job Summary for Gradle</h3> const prComment = `<h3>Job Summary for Gradle</h3>
<h5>${github.context.workflow} :: <em>${github.context.job}</em></h5> <a href="${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}" target="_blank">
<h5>${context.workflow} :: <em>${context.job}</em></h5>
</a>
${jobSummary}` ${jobSummary}`
@ -123,7 +125,7 @@ function renderBuildScan(result: BuildResult): string {
function renderBuildScanBadge(outcomeText: string, outcomeColor: string, targetUrl: string): string { function renderBuildScanBadge(outcomeText: string, outcomeColor: string, targetUrl: string): string {
const badgeUrl = `https://img.shields.io/badge/Build%20Scan%C2%AE-${outcomeText}-${outcomeColor}?logo=Gradle` const badgeUrl = `https://img.shields.io/badge/Build%20Scan%C2%AE-${outcomeText}-${outcomeColor}?logo=Gradle`
const badgeHtml = `<img src="${badgeUrl}" alt="Build Scan ${outcomeText}" />` const badgeHtml = `<img src="${badgeUrl}" alt="Build Scan ${outcomeText}" />`
return `<a href="${targetUrl}" rel="nofollow">${badgeHtml}</a>` return `<a href="${targetUrl}" rel="nofollow" target="_blank">${badgeHtml}</a>`
} }
function shouldGenerateJobSummary(buildResults: BuildResult[]): boolean { function shouldGenerateJobSummary(buildResults: BuildResult[]): boolean {

View File

@ -0,0 +1,30 @@
import {GradleStateCache} from "../../src/cache-base"
import * as path from 'path'
import * as fs from 'fs'
describe("--info and --stacktrace", () => {
describe("will be created", () => {
it("when gradle.properties does not exists", async () => {
const emptyGradleHome = 'test/jest/resources/gradle-home/empty'
fs.rmSync(path.resolve(emptyGradleHome, "gradle.properties"), {force: true})
const stateCache = new GradleStateCache("ignored", emptyGradleHome)
stateCache.configureInfoLogLevel()
expect(fs.readFileSync(path.resolve(emptyGradleHome, "gradle.properties"), 'utf-8'))
.toBe("org.gradle.logging.level=info\norg.gradle.logging.stacktrace=all\n")
})
})
describe("will be added", () => {
it("and gradle.properties does exists", async () => {
const existingGradleHome = 'test/jest/resources/gradle-home/existing'
fs.writeFileSync(path.resolve(existingGradleHome, "gradle.properties"), "org.gradle.logging.level=debug\n")
const stateCache = new GradleStateCache("ignored", existingGradleHome)
stateCache.configureInfoLogLevel()
expect(fs.readFileSync(path.resolve(existingGradleHome, "gradle.properties"), 'utf-8'))
.toBe("org.gradle.logging.level=info\norg.gradle.logging.stacktrace=all\n\norg.gradle.logging.level=debug\n")
})
})
})

View File

@ -0,0 +1 @@
gradle.properties

View File

@ -0,0 +1 @@
org.gradle.logging.level=debug