mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-22 08:11:07 -05: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
f0c6ac01d3
commit
15a8123fbc
4 changed files with 29 additions and 1 deletions
12
.github/workflows/prod.yml
vendored
12
.github/workflows/prod.yml
vendored
|
@ -46,3 +46,15 @@ jobs:
|
||||||
gradle-executable: __tests__/samples/basic/gradlew${{ matrix.script-suffix }}
|
gradle-executable: __tests__/samples/basic/gradlew${{ matrix.script-suffix }}
|
||||||
build-root-directory: __tests__/samples/no-wrapper
|
build-root-directory: __tests__/samples/no-wrapper
|
||||||
arguments: help
|
arguments: help
|
||||||
|
|
||||||
|
failures: # These build invocations are informational only, and are expected to fail
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout sources
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Test wrapper missing
|
||||||
|
uses: ./
|
||||||
|
continue-on-error: true
|
||||||
|
with:
|
||||||
|
build-root-directory: __tests__/samples/no-wrapper
|
||||||
|
arguments: help
|
||||||
|
|
2
dist/main/index.js
vendored
2
dist/main/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,3 +1,6 @@
|
||||||
|
import * as path from 'path'
|
||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32'
|
const IS_WINDOWS = process.platform === 'win32'
|
||||||
|
|
||||||
export function wrapperFilename(): string {
|
export function wrapperFilename(): string {
|
||||||
|
@ -7,3 +10,15 @@ export function wrapperFilename(): string {
|
||||||
export function installScriptFilename(): string {
|
export function installScriptFilename(): string {
|
||||||
return IS_WINDOWS ? 'gradle.bat' : 'gradle'
|
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)) {
|
||||||
|
throw new Error(
|
||||||
|
`Cannot locate a Gradle wrapper properties file at '${wrapperProperties}'. Specify 'gradle-version' or 'gradle-executable' for projects without Gradle wrapper configured.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ async function resolveGradleExecutable(
|
||||||
? path.resolve(workspaceDirectory, wrapperDirectory)
|
? path.resolve(workspaceDirectory, wrapperDirectory)
|
||||||
: buildRootDirectory
|
: buildRootDirectory
|
||||||
|
|
||||||
|
gradlew.validateGradleWrapper(gradlewDirectory)
|
||||||
await cacheWrapper.restoreCachedWrapperDist(gradlewDirectory)
|
await cacheWrapper.restoreCachedWrapperDist(gradlewDirectory)
|
||||||
|
|
||||||
return path.resolve(gradlewDirectory, gradlew.wrapperFilename())
|
return path.resolve(gradlewDirectory, gradlew.wrapperFilename())
|
||||||
|
|
Loading…
Reference in a new issue