mirror of
https://github.com/gradle/actions.git
synced 2025-11-26 17:09:10 +08:00
Configure --info and --stacktrace when GitHub ACTIONS_RUNNER_DEBUG is true
Fixes #6
This commit is contained in:
@@ -192,6 +192,10 @@ export class GradleStateCache {
|
||||
|
||||
// Copy the default toolchain definitions to `~/.m2/toolchains.xml`
|
||||
this.registerToolchains()
|
||||
|
||||
if (core.isDebug()) {
|
||||
this.configureInfoLogLevel()
|
||||
}
|
||||
}
|
||||
|
||||
private copyInitScripts(): void {
|
||||
@@ -240,6 +244,23 @@ export class GradleStateCache {
|
||||
return fs.readFileSync(absolutePath, 'utf8')
|
||||
}
|
||||
|
||||
/**
|
||||
* When the GitHub environment ACTIONS_RUNNER_DEBUG is true, run Gradle with --info and --stacktrace.
|
||||
* see https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging
|
||||
*/
|
||||
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, this method will give a detailed report
|
||||
* of the Gradle User Home contents.
|
||||
|
||||
30
sources/test/jest/cache-debug.test.ts
Normal file
30
sources/test/jest/cache-debug.test.ts
Normal 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")
|
||||
})
|
||||
})
|
||||
})
|
||||
1
sources/test/jest/resources/gradle-home/empty/.gitignore
vendored
Normal file
1
sources/test/jest/resources/gradle-home/empty/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
gradle.properties
|
||||
@@ -0,0 +1 @@
|
||||
org.gradle.logging.level=debug
|
||||
Reference in New Issue
Block a user