Do not generate dependency graph in cache-cleanup

- Allow environment variables to be overridden by system properties in dependency-graph initscript
- Set `GITHUB_DEPENDENCY_GRAPH_ENABLED=false` when executing Gradle for cache cleanup
This commit is contained in:
daz 2023-09-29 14:43:03 -06:00 committed by Daz DeBoer
parent 6fcc109efa
commit d1b726d8c1
6 changed files with 18 additions and 8 deletions

3
dist/main/index.js vendored
View File

@ -69620,7 +69620,8 @@ class CacheCleaner {
fs_1.default.mkdirSync(cleanupProjectDir, { recursive: true });
fs_1.default.writeFileSync(path_1.default.resolve(cleanupProjectDir, 'settings.gradle'), 'rootProject.name = "dummy-cleanup-project"');
fs_1.default.writeFileSync(path_1.default.resolve(cleanupProjectDir, 'build.gradle'), 'task("noop") {}');
yield exec.exec(`gradle -g ${this.gradleUserHome} --no-daemon --build-cache --no-scan --quiet noop`, [], {
const gradleCommand = `gradle -g ${this.gradleUserHome} --no-daemon --build-cache --no-scan --quiet -DGITHUB_DEPENDENCY_GRAPH_ENABLED=false noop`;
yield exec.exec(gradleCommand, [], {
cwd: cleanupProjectDir
});
});

File diff suppressed because one or more lines are too long

3
dist/post/index.js vendored
View File

@ -69620,7 +69620,8 @@ class CacheCleaner {
fs_1.default.mkdirSync(cleanupProjectDir, { recursive: true });
fs_1.default.writeFileSync(path_1.default.resolve(cleanupProjectDir, 'settings.gradle'), 'rootProject.name = "dummy-cleanup-project"');
fs_1.default.writeFileSync(path_1.default.resolve(cleanupProjectDir, 'build.gradle'), 'task("noop") {}');
yield exec.exec(`gradle -g ${this.gradleUserHome} --no-daemon --build-cache --no-scan --quiet noop`, [], {
const gradleCommand = `gradle -g ${this.gradleUserHome} --no-daemon --build-cache --no-scan --quiet -DGITHUB_DEPENDENCY_GRAPH_ENABLED=false noop`;
yield exec.exec(gradleCommand, [], {
cwd: cleanupProjectDir
});
});

File diff suppressed because one or more lines are too long

View File

@ -42,7 +42,8 @@ export class CacheCleaner {
)
fs.writeFileSync(path.resolve(cleanupProjectDir, 'build.gradle'), 'task("noop") {}')
await exec.exec(`gradle -g ${this.gradleUserHome} --no-daemon --build-cache --no-scan --quiet noop`, [], {
const gradleCommand = `gradle -g ${this.gradleUserHome} --no-daemon --build-cache --no-scan --quiet -DGITHUB_DEPENDENCY_GRAPH_ENABLED=false noop`
await exec.exec(gradleCommand, [], {
cwd: cleanupProjectDir
})
}

View File

@ -1,7 +1,7 @@
import org.gradle.util.GradleVersion
// Only run when dependency graph is explicitly enabled
if (System.env.GITHUB_DEPENDENCY_GRAPH_ENABLED != "true") {
if (getVariable('GITHUB_DEPENDENCY_GRAPH_ENABLED') != "true") {
return
}
@ -15,7 +15,7 @@ if (GradleVersion.current().baseVersion < GradleVersion.version("5.0")) {
// This is only required for top-level builds
def isTopLevelBuild = gradle.getParent() == null
if (isTopLevelBuild) {
def reportFile = getUniqueReportFile(System.env.GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR)
def reportFile = getUniqueReportFile(getVariable('GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR'))
if (reportFile == null) {
println "::warning::No dependency snapshot generated for step. Could not determine unique job correlator - specify GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR var for this step."
@ -40,7 +40,7 @@ apply from: 'gradle-build-action.github-dependency-graph-gradle-plugin-apply.gro
* - When found, this value is set as a System property override.
*/
File getUniqueReportFile(String jobCorrelator) {
def reportDir = System.env.DEPENDENCY_GRAPH_REPORT_DIR
def reportDir = getVariable('DEPENDENCY_GRAPH_REPORT_DIR')
def reportFile = new File(reportDir, jobCorrelator + ".json")
if (!reportFile.exists()) return reportFile
@ -57,3 +57,10 @@ File getUniqueReportFile(String jobCorrelator) {
// Could not determine unique job correlator
return null
}
/**
* Return the environment variable value, or equivalent system property (if set)
*/
String getVariable(String name) {
return System.properties[name] ?: System.getenv(name)
}