From 4168d52f15a70ee3a16d7326f462d7b9696276ec Mon Sep 17 00:00:00 2001 From: Ivan Milisavljevic Date: Tue, 21 Jun 2022 15:05:25 +0200 Subject: [PATCH] Configurable post action cleanup Signed-off-by: Ivan Milisavljevic --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ action.yml | 5 +++++ src/setup-gradle.ts | 9 +++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eeab134..c134c34 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,44 @@ 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. diff --git a/action.yml b/action.yml index 2626a9b..f06e415 100644 --- a/action.yml +++ b/action.yml @@ -53,6 +53,11 @@ 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/setup-gradle.ts b/src/setup-gradle.ts index cf25430..388ec27 100644 --- a/src/setup-gradle.ts +++ b/src/setup-gradle.ts @@ -13,6 +13,7 @@ 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 @@ -53,8 +54,12 @@ export async function complete(): Promise { const buildResults = loadBuildResults() - core.info('Stopping all Gradle daemons') - await stopAllDaemons(getUniqueGradleHomes(buildResults)) + // Stop gradle daemons + const shouldStopDaemons = core.getBooleanInput(STOP_DAEMON_PARAMETER) + if (shouldStopDaemons){ + core.info('Stopping all Gradle daemons') + await stopAllDaemons(getUniqueGradleHomes(buildResults)) + } core.info('In final post-action step, saving state and writing summary') const cacheListener: CacheListener = CacheListener.rehydrate(core.getState(CACHE_LISTENER))