Skip to content

Commit

Permalink
Do not generate dependency graph in cache-cleanup
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
bigdaz committed Sep 29, 2023
1 parent 6fcc109 commit d1b726d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
Expand Down
2 changes: 1 addition & 1 deletion dist/post/index.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/cache-cleaner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -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."
Expand All @@ -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

Expand All @@ -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)
}

0 comments on commit d1b726d

Please sign in to comment.