mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-07-17 12:45:48 +02:00
Validate presense of gradle wrapper to provide better feedback
- Provide a more useful error message when no Gradle wrapper can be located, and 'gradle-version' or 'gradle-executable' is not used. - Add test for case where wrapper is missing. This isn't really a "test" per-se, but this failing build invocation makes it easy to verify the GitHub action behaviour when the build is misconfigured.
This commit is contained in:
parent
14f7fb173f
commit
76a33e31af
4 changed files with 33 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
|||
import * as path from 'path'
|
||||
import fs from 'fs'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
const IS_WINDOWS = process.platform === 'win32'
|
||||
|
||||
export function wrapperFilename(): string {
|
||||
|
@ -7,3 +11,18 @@ export function wrapperFilename(): string {
|
|||
export function installScriptFilename(): string {
|
||||
return IS_WINDOWS ? 'gradle.bat' : 'gradle'
|
||||
}
|
||||
|
||||
export function validateGradleWrapper(gradlewDirectory: string): void {
|
||||
const wrapperProperties = path.resolve(
|
||||
gradlewDirectory,
|
||||
'gradle/wrapper/gradle-wrapper.properties'
|
||||
)
|
||||
if (!fs.existsSync(wrapperProperties)) {
|
||||
core.warning(
|
||||
`Cannot locate a Gradle wrapper properties file at '${wrapperProperties}'. Specify 'gradle-version' or 'gradle-executable' for projects without Gradle wrapper configured.`
|
||||
)
|
||||
throw new Error(
|
||||
`Cannot locate a Gradle wrapper within '${gradlewDirectory}'`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ async function resolveGradleExecutable(
|
|||
? path.resolve(workspaceDirectory, wrapperDirectory)
|
||||
: buildRootDirectory
|
||||
|
||||
gradlew.validateGradleWrapper(gradlewDirectory)
|
||||
await cacheWrapper.restoreCachedWrapperDist(gradlewDirectory)
|
||||
|
||||
return path.resolve(gradlewDirectory, gradlew.wrapperFilename())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue