From 09bf8857de74ea74dcb291270255db927108e474 Mon Sep 17 00:00:00 2001 From: Ivan Milisavljevic Date: Thu, 23 Jun 2022 00:31:22 +0200 Subject: [PATCH] Remove stop-daemon configuration flag and stop gradle daemon only if GRADLE_HOME is going to be cached Signed-off-by: Ivan Milisavljevic --- README.md | 42 ++++-------------------------------------- action.yml | 5 ----- src/caches.ts | 2 +- src/setup-gradle.ts | 10 +++++----- 4 files changed, 10 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index c134c34..19f9cf4 100644 --- a/README.md +++ b/README.md @@ -135,44 +135,6 @@ The initial Action step will perform the Gradle setup. arguments: check ``` -### Stopping gradle daemon - -All Gradle daemons will be stopped by default in the post action step. -It is possible to keep daemons alive between jobs by setting `stop-daemons` to `false`. - -Note that this is not recommended and should be used only on non-ephemeral runners. - -```yaml -jobs: - test: - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - distribution: temurin - java-version: 11 - - - name: Setup and execute Gradle 'test' task - uses: gradle/gradle-build-action@v2 - with: - stop-daemons: false - arguments: test - - build: - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - distribution: temurin - java-version: 11 - - - name: Setup and execute Gradle 'build' task - uses: gradle/gradle-build-action@v2 - with: - stop-daemons: false - arguments: build -``` - ### Gradle command-line arguments The `arguments` input can be used to pass arbitrary arguments to the `gradle` command line. @@ -244,6 +206,10 @@ Caching is enabled by default. You can disable caching for the action as follows cache-disabled: true ``` +### Stopping gradle daemon +By default, the action will stop all Gradle daemons in the post-action step before the state of Gradle User Home is cached. + +If caching is unavailable or the cache is in read-only mode, the daemon will not be stopped and will continue running after the job is completed. ### Cache keys Distributions downloaded to satisfy a `gradle-version` parameter are stored outside of Gradle User Home and cached separately. The cache key is unique to the downloaded distribution and will not change over time. diff --git a/action.yml b/action.yml index f06e415..2626a9b 100644 --- a/action.yml +++ b/action.yml @@ -53,11 +53,6 @@ inputs: description: Path to the Gradle executable required: false - stop-daemons: - description: When 'true', Gradle daemon will be stopped after the build. - required: false - default: true - generate-job-summary: description: When 'false', no Job Summary will be generated for the Job. required: false diff --git a/src/caches.ts b/src/caches.ts index b77f8f0..4433d02 100644 --- a/src/caches.ts +++ b/src/caches.ts @@ -61,7 +61,7 @@ export async function save(gradleUserHome: string, cacheListener: CacheListener) }) } -function shouldSaveCaches(): boolean { +export function shouldSaveCaches(): boolean { if (isCacheDisabled()) { core.info('Cache is disabled: will not save state for later builds.') return false diff --git a/src/setup-gradle.ts b/src/setup-gradle.ts index e2d5f18..f6701d3 100644 --- a/src/setup-gradle.ts +++ b/src/setup-gradle.ts @@ -8,12 +8,13 @@ import * as caches from './caches' import {CacheListener} from './cache-reporting' import {BuildResult, loadBuildResults, logJobSummary, writeJobSummary} from './job-summary' +import {shouldSaveCaches} from "./caches"; +import {isCacheReadOnly} from "./cache-utils"; const GRADLE_SETUP_VAR = 'GRADLE_BUILD_ACTION_SETUP_COMPLETED' const GRADLE_USER_HOME = 'GRADLE_USER_HOME' const CACHE_LISTENER = 'CACHE_LISTENER' const JOB_SUMMARY_ENABLED_PARAMETER = 'generate-job-summary' -const STOP_DAEMON_PARAMETER = 'stop-daemons' function shouldGenerateJobSummary(): boolean { // Check if Job Summary is supported on this platform @@ -54,10 +55,9 @@ export async function complete(): Promise { const buildResults = loadBuildResults() - // Stop gradle daemons - const shouldStopDaemons = core.getBooleanInput(STOP_DAEMON_PARAMETER) - if (shouldStopDaemons) { - core.info('Stopping all Gradle daemons') + // Stop gradle daemons only if the state of GRADLE_HOME is going to be cached + if (shouldSaveCaches() && !isCacheReadOnly()) { + core.info('Cache is going to be saved - Stopping all Gradle daemons') await stopAllDaemons(getUniqueGradleHomes(buildResults)) }