Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.

Commit 3c11eee

Browse files
committed
Don't use full path when executing gradlew
Fixes #796
1 parent 4301451 commit 3c11eee

File tree

4 files changed

+46
-38
lines changed

4 files changed

+46
-38
lines changed

dist/main/index.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73282,19 +73282,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7328273282
step((generator = generator.apply(thisArg, _arguments || [])).next());
7328373283
});
7328473284
};
73285-
var __importDefault = (this && this.__importDefault) || function (mod) {
73286-
return (mod && mod.__esModule) ? mod : { "default": mod };
73287-
};
7328873285
Object.defineProperty(exports, "__esModule", ({ value: true }));
7328973286
exports.executeGradleBuild = void 0;
7329073287
const core = __importStar(__nccwpck_require__(2186));
7329173288
const exec = __importStar(__nccwpck_require__(1514));
73292-
const fs_1 = __importDefault(__nccwpck_require__(7147));
7329373289
const gradlew = __importStar(__nccwpck_require__(2335));
7329473290
function executeGradleBuild(executable, root, args) {
7329573291
return __awaiter(this, void 0, void 0, function* () {
73296-
const toExecute = executable !== null && executable !== void 0 ? executable : gradlew.locateGradleWrapperScript(root);
73297-
verifyIsExecutableScript(toExecute);
73292+
const toExecute = executable !== null && executable !== void 0 ? executable : gradlew.gradleWrapperScript(root);
7329873293
const status = yield exec.exec(toExecute, args, {
7329973294
cwd: root,
7330073295
ignoreReturnCode: true
@@ -73305,14 +73300,6 @@ function executeGradleBuild(executable, root, args) {
7330573300
});
7330673301
}
7330773302
exports.executeGradleBuild = executeGradleBuild;
73308-
function verifyIsExecutableScript(toExecute) {
73309-
try {
73310-
fs_1.default.accessSync(toExecute, fs_1.default.constants.X_OK);
73311-
}
73312-
catch (err) {
73313-
throw new Error(`Gradle script '${toExecute}' is not executable.`);
73314-
}
73315-
}
7331673303

7331773304

7331873305
/***/ }),
@@ -73349,27 +73336,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7334973336
return (mod && mod.__esModule) ? mod : { "default": mod };
7335073337
};
7335173338
Object.defineProperty(exports, "__esModule", ({ value: true }));
73352-
exports.locateGradleWrapperScript = exports.installScriptFilename = exports.wrapperScriptFilename = void 0;
73339+
exports.gradleWrapperScript = exports.installScriptFilename = exports.wrapperScriptFilename = void 0;
7335373340
const path = __importStar(__nccwpck_require__(1017));
7335473341
const fs_1 = __importDefault(__nccwpck_require__(7147));
7335573342
const IS_WINDOWS = process.platform === 'win32';
7335673343
function wrapperScriptFilename() {
73357-
return IS_WINDOWS ? 'gradlew.bat' : 'gradlew';
73344+
return IS_WINDOWS ? 'gradlew.bat' : './gradlew';
7335873345
}
7335973346
exports.wrapperScriptFilename = wrapperScriptFilename;
7336073347
function installScriptFilename() {
7336173348
return IS_WINDOWS ? 'gradle.bat' : 'gradle';
7336273349
}
7336373350
exports.installScriptFilename = installScriptFilename;
73364-
function locateGradleWrapperScript(buildRootDirectory) {
73351+
function gradleWrapperScript(buildRootDirectory) {
7336573352
validateGradleWrapper(buildRootDirectory);
73366-
return path.resolve(buildRootDirectory, wrapperScriptFilename());
73353+
return wrapperScriptFilename();
7336773354
}
73368-
exports.locateGradleWrapperScript = locateGradleWrapperScript;
73355+
exports.gradleWrapperScript = gradleWrapperScript;
7336973356
function validateGradleWrapper(buildRootDirectory) {
73357+
const wrapperScript = path.resolve(buildRootDirectory, wrapperScriptFilename());
73358+
verifyExists(wrapperScript, 'Gradle Wrapper script');
73359+
verifyIsExecutableScript(wrapperScript);
7337073360
const wrapperProperties = path.resolve(buildRootDirectory, 'gradle/wrapper/gradle-wrapper.properties');
73371-
if (!fs_1.default.existsSync(wrapperProperties)) {
73372-
throw new Error(`Cannot locate a Gradle wrapper properties file at '${wrapperProperties}'. Specify 'gradle-version' or 'gradle-executable' for projects without Gradle wrapper configured.`);
73361+
verifyExists(wrapperProperties, 'Gradle wrapper properties file');
73362+
}
73363+
function verifyExists(file, description) {
73364+
if (!fs_1.default.existsSync(file)) {
73365+
throw new Error(`Cannot locate ${description} at '${file}'. Specify 'gradle-version' or 'gradle-executable' for projects without Gradle wrapper configured.`);
73366+
}
73367+
}
73368+
function verifyIsExecutableScript(toExecute) {
73369+
try {
73370+
fs_1.default.accessSync(toExecute, fs_1.default.constants.X_OK);
73371+
}
73372+
catch (err) {
73373+
throw new Error(`Gradle script '${toExecute}' is not executable.`);
7337373374
}
7337473375
}
7337573376

dist/main/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/execution.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import * as core from '@actions/core'
22
import * as exec from '@actions/exec'
3-
import fs from 'fs'
43
import * as gradlew from './gradlew'
54

65
export async function executeGradleBuild(executable: string | undefined, root: string, args: string[]): Promise<void> {
76
// Use the provided executable, or look for a Gradle wrapper script to run
8-
const toExecute = executable ?? gradlew.locateGradleWrapperScript(root)
9-
verifyIsExecutableScript(toExecute)
7+
const toExecute = executable ?? gradlew.gradleWrapperScript(root)
8+
109
const status: number = await exec.exec(toExecute, args, {
1110
cwd: root,
1211
ignoreReturnCode: true
@@ -16,11 +15,3 @@ export async function executeGradleBuild(executable: string | undefined, root: s
1615
core.setFailed(`Gradle build failed: see console output for details`)
1716
}
1817
}
19-
20-
function verifyIsExecutableScript(toExecute: string): void {
21-
try {
22-
fs.accessSync(toExecute, fs.constants.X_OK)
23-
} catch (err) {
24-
throw new Error(`Gradle script '${toExecute}' is not executable.`)
25-
}
26-
}

src/gradlew.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,39 @@ import fs from 'fs'
44
const IS_WINDOWS = process.platform === 'win32'
55

66
export function wrapperScriptFilename(): string {
7-
return IS_WINDOWS ? 'gradlew.bat' : 'gradlew'
7+
return IS_WINDOWS ? 'gradlew.bat' : './gradlew'
88
}
99

1010
export function installScriptFilename(): string {
1111
return IS_WINDOWS ? 'gradle.bat' : 'gradle'
1212
}
1313

14-
export function locateGradleWrapperScript(buildRootDirectory: string): string {
14+
export function gradleWrapperScript(buildRootDirectory: string): string {
1515
validateGradleWrapper(buildRootDirectory)
16-
return path.resolve(buildRootDirectory, wrapperScriptFilename())
16+
return wrapperScriptFilename()
1717
}
1818

1919
function validateGradleWrapper(buildRootDirectory: string): void {
20+
const wrapperScript = path.resolve(buildRootDirectory, wrapperScriptFilename())
21+
verifyExists(wrapperScript, 'Gradle Wrapper script')
22+
verifyIsExecutableScript(wrapperScript)
23+
2024
const wrapperProperties = path.resolve(buildRootDirectory, 'gradle/wrapper/gradle-wrapper.properties')
21-
if (!fs.existsSync(wrapperProperties)) {
25+
verifyExists(wrapperProperties, 'Gradle wrapper properties file')
26+
}
27+
28+
function verifyExists(file: string, description: string): void {
29+
if (!fs.existsSync(file)) {
2230
throw new Error(
23-
`Cannot locate a Gradle wrapper properties file at '${wrapperProperties}'. Specify 'gradle-version' or 'gradle-executable' for projects without Gradle wrapper configured.`
31+
`Cannot locate ${description} at '${file}'. Specify 'gradle-version' or 'gradle-executable' for projects without Gradle wrapper configured.`
2432
)
2533
}
2634
}
35+
36+
function verifyIsExecutableScript(toExecute: string): void {
37+
try {
38+
fs.accessSync(toExecute, fs.constants.X_OK)
39+
} catch (err) {
40+
throw new Error(`Gradle script '${toExecute}' is not executable.`)
41+
}
42+
}

0 commit comments

Comments
 (0)