Don't use full path when executing gradlew

Fixes #796
This commit is contained in:
daz 2023-07-13 13:30:34 -06:00
parent 4301451b53
commit 3c11eee5f9
No known key found for this signature in database
4 changed files with 46 additions and 38 deletions

43
dist/main/index.js vendored
View file

@ -73282,19 +73282,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.executeGradleBuild = void 0; exports.executeGradleBuild = void 0;
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514)); const exec = __importStar(__nccwpck_require__(1514));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const gradlew = __importStar(__nccwpck_require__(2335)); const gradlew = __importStar(__nccwpck_require__(2335));
function executeGradleBuild(executable, root, args) { function executeGradleBuild(executable, root, args) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const toExecute = executable !== null && executable !== void 0 ? executable : gradlew.locateGradleWrapperScript(root); const toExecute = executable !== null && executable !== void 0 ? executable : gradlew.gradleWrapperScript(root);
verifyIsExecutableScript(toExecute);
const status = yield exec.exec(toExecute, args, { const status = yield exec.exec(toExecute, args, {
cwd: root, cwd: root,
ignoreReturnCode: true ignoreReturnCode: true
@ -73305,14 +73300,6 @@ function executeGradleBuild(executable, root, args) {
}); });
} }
exports.executeGradleBuild = executeGradleBuild; exports.executeGradleBuild = executeGradleBuild;
function verifyIsExecutableScript(toExecute) {
try {
fs_1.default.accessSync(toExecute, fs_1.default.constants.X_OK);
}
catch (err) {
throw new Error(`Gradle script '${toExecute}' is not executable.`);
}
}
/***/ }), /***/ }),
@ -73349,27 +73336,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.locateGradleWrapperScript = exports.installScriptFilename = exports.wrapperScriptFilename = void 0; exports.gradleWrapperScript = exports.installScriptFilename = exports.wrapperScriptFilename = void 0;
const path = __importStar(__nccwpck_require__(1017)); const path = __importStar(__nccwpck_require__(1017));
const fs_1 = __importDefault(__nccwpck_require__(7147)); const fs_1 = __importDefault(__nccwpck_require__(7147));
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
function wrapperScriptFilename() { function wrapperScriptFilename() {
return IS_WINDOWS ? 'gradlew.bat' : 'gradlew'; return IS_WINDOWS ? 'gradlew.bat' : './gradlew';
} }
exports.wrapperScriptFilename = wrapperScriptFilename; exports.wrapperScriptFilename = wrapperScriptFilename;
function installScriptFilename() { function installScriptFilename() {
return IS_WINDOWS ? 'gradle.bat' : 'gradle'; return IS_WINDOWS ? 'gradle.bat' : 'gradle';
} }
exports.installScriptFilename = installScriptFilename; exports.installScriptFilename = installScriptFilename;
function locateGradleWrapperScript(buildRootDirectory) { function gradleWrapperScript(buildRootDirectory) {
validateGradleWrapper(buildRootDirectory); validateGradleWrapper(buildRootDirectory);
return path.resolve(buildRootDirectory, wrapperScriptFilename()); return wrapperScriptFilename();
} }
exports.locateGradleWrapperScript = locateGradleWrapperScript; exports.gradleWrapperScript = gradleWrapperScript;
function validateGradleWrapper(buildRootDirectory) { function validateGradleWrapper(buildRootDirectory) {
const wrapperScript = path.resolve(buildRootDirectory, wrapperScriptFilename());
verifyExists(wrapperScript, 'Gradle Wrapper script');
verifyIsExecutableScript(wrapperScript);
const wrapperProperties = path.resolve(buildRootDirectory, 'gradle/wrapper/gradle-wrapper.properties'); const wrapperProperties = path.resolve(buildRootDirectory, 'gradle/wrapper/gradle-wrapper.properties');
if (!fs_1.default.existsSync(wrapperProperties)) { verifyExists(wrapperProperties, 'Gradle wrapper properties file');
throw new Error(`Cannot locate a Gradle wrapper properties file at '${wrapperProperties}'. Specify 'gradle-version' or 'gradle-executable' for projects without Gradle wrapper configured.`); }
function verifyExists(file, description) {
if (!fs_1.default.existsSync(file)) {
throw new Error(`Cannot locate ${description} at '${file}'. Specify 'gradle-version' or 'gradle-executable' for projects without Gradle wrapper configured.`);
}
}
function verifyIsExecutableScript(toExecute) {
try {
fs_1.default.accessSync(toExecute, fs_1.default.constants.X_OK);
}
catch (err) {
throw new Error(`Gradle script '${toExecute}' is not executable.`);
} }
} }

File diff suppressed because one or more lines are too long

View file

@ -1,12 +1,11 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import * as exec from '@actions/exec' import * as exec from '@actions/exec'
import fs from 'fs'
import * as gradlew from './gradlew' import * as gradlew from './gradlew'
export async function executeGradleBuild(executable: string | undefined, root: string, args: string[]): Promise<void> { export async function executeGradleBuild(executable: string | undefined, root: string, args: string[]): Promise<void> {
// Use the provided executable, or look for a Gradle wrapper script to run // Use the provided executable, or look for a Gradle wrapper script to run
const toExecute = executable ?? gradlew.locateGradleWrapperScript(root) const toExecute = executable ?? gradlew.gradleWrapperScript(root)
verifyIsExecutableScript(toExecute)
const status: number = await exec.exec(toExecute, args, { const status: number = await exec.exec(toExecute, args, {
cwd: root, cwd: root,
ignoreReturnCode: true ignoreReturnCode: true
@ -16,11 +15,3 @@ export async function executeGradleBuild(executable: string | undefined, root: s
core.setFailed(`Gradle build failed: see console output for details`) core.setFailed(`Gradle build failed: see console output for details`)
} }
} }
function verifyIsExecutableScript(toExecute: string): void {
try {
fs.accessSync(toExecute, fs.constants.X_OK)
} catch (err) {
throw new Error(`Gradle script '${toExecute}' is not executable.`)
}
}

View file

@ -4,23 +4,39 @@ import fs from 'fs'
const IS_WINDOWS = process.platform === 'win32' const IS_WINDOWS = process.platform === 'win32'
export function wrapperScriptFilename(): string { export function wrapperScriptFilename(): string {
return IS_WINDOWS ? 'gradlew.bat' : 'gradlew' return IS_WINDOWS ? 'gradlew.bat' : './gradlew'
} }
export function installScriptFilename(): string { export function installScriptFilename(): string {
return IS_WINDOWS ? 'gradle.bat' : 'gradle' return IS_WINDOWS ? 'gradle.bat' : 'gradle'
} }
export function locateGradleWrapperScript(buildRootDirectory: string): string { export function gradleWrapperScript(buildRootDirectory: string): string {
validateGradleWrapper(buildRootDirectory) validateGradleWrapper(buildRootDirectory)
return path.resolve(buildRootDirectory, wrapperScriptFilename()) return wrapperScriptFilename()
} }
function validateGradleWrapper(buildRootDirectory: string): void { function validateGradleWrapper(buildRootDirectory: string): void {
const wrapperScript = path.resolve(buildRootDirectory, wrapperScriptFilename())
verifyExists(wrapperScript, 'Gradle Wrapper script')
verifyIsExecutableScript(wrapperScript)
const wrapperProperties = path.resolve(buildRootDirectory, 'gradle/wrapper/gradle-wrapper.properties') const wrapperProperties = path.resolve(buildRootDirectory, 'gradle/wrapper/gradle-wrapper.properties')
if (!fs.existsSync(wrapperProperties)) { verifyExists(wrapperProperties, 'Gradle wrapper properties file')
}
function verifyExists(file: string, description: string): void {
if (!fs.existsSync(file)) {
throw new Error( throw new Error(
`Cannot locate a Gradle wrapper properties file at '${wrapperProperties}'. Specify 'gradle-version' or 'gradle-executable' for projects without Gradle wrapper configured.` `Cannot locate ${description} at '${file}'. Specify 'gradle-version' or 'gradle-executable' for projects without Gradle wrapper configured.`
) )
} }
} }
function verifyIsExecutableScript(toExecute: string): void {
try {
fs.accessSync(toExecute, fs.constants.X_OK)
} catch (err) {
throw new Error(`Gradle script '${toExecute}' is not executable.`)
}
}