gradle-build-action
gradle-build-action copied to clipboard
Cache cleanup fails with "Unable to locate executable file: gradle" when Gradle is not pre-installed on runner
Our gradle action config looks as the following
- name: Setup Gradle
uses: gradle/[email protected]
with:
gradle-version: wrapper
gradle-home-cache-cleanup: true
cache-read-only: false
so assumption is that in post-action gradle will clean up cache in home directory thanks to gradle-home-cache-cleanup: true
. Actually in Post Setup Gradle I see the following message
Post job cleanup.
In final post-action step, saving state and writing summary
Stopping all Gradle daemons before saving Gradle User Home state
Stopping Gradle daemons for /home/runner/.gradle/wrapper/dists/gradle-7.4.[2](https://github.com/pleo-io/triton/runs/8232662390?check_suite_focus=true#step:43:2)-bin/48ivgl02cpt2ed[3](https://github.com/pleo-io/triton/runs/8232662390?check_suite_focus=true#step:43:3)fh9dbalvx8/gradle-7.[4](https://github.com/pleo-io/triton/runs/8232662390?check_suite_focus=true#step:43:4).2
/home/runner/.gradle/wrapper/dists/gradle-7.4.2-bin/48ivgl02cpt2ed3fh9dbalvx8/gradle-7.4.2/bin/gradle --stop
Stopping Daemon(s)
1 Daemon stopped
Forcing cache cleanup.
Warning: Unhandled error in Gradle post-action - job will continue: Error: Unable to locate executable file: gradle. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
Error: Unable to locate executable file: gradle. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
at Object.<anonymous> (/home/runner/work/_actions/gradle/gradle-build-action/v2.3.0/dist/webpack:/gradle-build-action/node_modules/@actions/io/lib/io.js:213:1)
at Generator.next (<anonymous>)
at fulfilled (/home/runner/work/_actions/gradle/gradle-build-action/v2.3.0/dist/webpack:/gradle-build-action/node_modules/@actions/io/lib/io.js:24:1)
based on sources https://github.com/gradle/gradle-build-action/blob/main/src/cache-cleaner.ts I see as if dummy gradle project does actual clean up. But from where this project should get gradle to execute this
await exec.exec(`gradle -g ${this.gradleUserHome} --no-daemon --build-cache --no-scan --quiet noop`, [], {
cwd: cleanupProjectDir
})
?
Would you please clarify how to properly configure gradle-home-cache-cleanup
so it would get gradle
from somewhere. Thanks!
ok, for these who are having the same issue the workaround is the following
- name: Setup Gradle
uses: gradle/[email protected]
with:
gradle-version: 7.5
gradle-home-cache-cleanup: true
cache-read-only: false
so gradle-version
must be explicitly declared to be able to make gradle
available in PATH
. It allows to clean up cache in post step.
Having said that the issue is that gradle-home-cache-cleanup
feature does not work as expected if gradle-version: wrapper
is used. Not sure if that by design or this is a bug actually.
This seems like a bug to me. Isn't the whole point of using the Wrapper version that you don't have to worry about per-project Gradle versions? 🤔
Issue
Thanks for the report. I tested this feature on ubuntu-latest, windows-latest and macos-latest runners, all of which have a recent version of Gradle pre-installed. This pre-installed Gradle version is used for the cache-cleanup process.
However it appears that ubuntu-22.04 does not come preinstalled with Gradle on the PATH, so the cache-cleanup feature will indeed fail. This is a bug in the action: cache-cleanup should work even if the runner does not have a recent version of Gradle pre-installed.
Workaround
You can force the action to download and install a recent gradle version by specifying a gradle-version
parameter: the action will install the requested version and add it to the PATH. This isn't normally required if you use the Gradle wrapper, but allows you to ensure that Gradle is available on the runner for cache-cleanup to work.
Note that you can still use the Gradle wrapper to execute your project. Here's a working example:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: current ### This version will be installed and added to PATH, so used for cache-cleanup
gradle-home-cache-cleanup: true
- name: Execute build with Gradle wrapper
run: ./gradlew build
Thanks for the quick response @bigdaz!
That's exactly the conclusion we came to too 😄 The problem is that we use a central workflow for all our Gradle projects, so the Gradle version differs from project to project. We can work around this by getting the current gradlew
version and using that explicitly, but given that we use gradle-build-action
extensively across Pleo and would like to have as few workarounds as possible, I thought I'd fork the action and submit a PR handling the missing gradle
in $PATH
(by falling back to executing ./gradlew
if wrapper
is specified as the version).
WDYT?
@bigdaz
Or, alternatively: Would we just be able to use ./gradlew
as a parameter to this action's gradle-executable
parameter in order to ensure cleanup?
We have a PR up in #427. I'm unsure about the state handling here - we can probably clean that up with some guidance on the expected architecture 😄
Do we have an update on this?
Do we have an update on this?
Not really. The current PR is a bit problematic (assumes Gradle project is root of repository), and I'm not sure when we'll have time to address this.
There is a simple workaround:
- Use separate "Setup Gradle" and "Run Gradle" steps in your workflow (this is what we recommend anyway)
- Add
gradle-version: current
to the "Setup Gradle" step. (This will ensure that Gradle is available on the PATH) - Use
run: ./gradlew my-build-task
in the "Run Gradle" step to build your project with the Gradle wrapper
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: current
gradle-home-cache-cleanup: true
- name: Execute build with Gradle wrapper
run: ./gradlew build