Unverified Commit 3c11eee5 authored by daz's avatar daz
Browse files

Don't use full path when executing gradlew

Fixes #796
parent 4301451b
Loading
Loading
Loading
Loading
+22 −21
Changes for dist/main/index.js: 22 added lines, 21 removed lines.
Original line number Diff line number Diff line
@@ -73282,19 +73282,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
        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 }));
exports.executeGradleBuild = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const gradlew = __importStar(__nccwpck_require__(2335));
function executeGradleBuild(executable, root, args) {
    return __awaiter(this, void 0, void 0, function* () {
        const toExecute = executable !== null && executable !== void 0 ? executable : gradlew.locateGradleWrapperScript(root);
        verifyIsExecutableScript(toExecute);
        const toExecute = executable !== null && executable !== void 0 ? executable : gradlew.gradleWrapperScript(root);
        const status = yield exec.exec(toExecute, args, {
            cwd: root,
            ignoreReturnCode: true
@@ -73305,14 +73300,6 @@ function executeGradleBuild(executable, root, args) {
    });
}
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 };
};
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 fs_1 = __importDefault(__nccwpck_require__(7147));
const IS_WINDOWS = process.platform === 'win32';
function wrapperScriptFilename() {
    return IS_WINDOWS ? 'gradlew.bat' : 'gradlew';
    return IS_WINDOWS ? 'gradlew.bat' : './gradlew';
}
exports.wrapperScriptFilename = wrapperScriptFilename;
function installScriptFilename() {
    return IS_WINDOWS ? 'gradle.bat' : 'gradle';
}
exports.installScriptFilename = installScriptFilename;
function locateGradleWrapperScript(buildRootDirectory) {
function gradleWrapperScript(buildRootDirectory) {
    validateGradleWrapper(buildRootDirectory);
    return path.resolve(buildRootDirectory, wrapperScriptFilename());
    return wrapperScriptFilename();
}
exports.locateGradleWrapperScript = locateGradleWrapperScript;
exports.gradleWrapperScript = gradleWrapperScript;
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');
    if (!fs_1.default.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.`);
    verifyExists(wrapperProperties, 'Gradle wrapper properties file');
}
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.`);
    }
}
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+2 −11
Changes for src/execution.ts: 2 added lines, 11 removed lines.
Original line number Diff line number Diff line
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import fs from 'fs'
import * as gradlew from './gradlew'

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
    const toExecute = executable ?? gradlew.locateGradleWrapperScript(root)
    verifyIsExecutableScript(toExecute)
    const toExecute = executable ?? gradlew.gradleWrapperScript(root)

    const status: number = await exec.exec(toExecute, args, {
        cwd: root,
        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`)
    }
}

function verifyIsExecutableScript(toExecute: string): void {
    try {
        fs.accessSync(toExecute, fs.constants.X_OK)
    } catch (err) {
        throw new Error(`Gradle script '${toExecute}' is not executable.`)
    }
}
+21 −5
Changes for src/gradlew.ts: 21 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -4,23 +4,39 @@ import fs from 'fs'
const IS_WINDOWS = process.platform === 'win32'

export function wrapperScriptFilename(): string {
    return IS_WINDOWS ? 'gradlew.bat' : 'gradlew'
    return IS_WINDOWS ? 'gradlew.bat' : './gradlew'
}

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

export function locateGradleWrapperScript(buildRootDirectory: string): string {
export function gradleWrapperScript(buildRootDirectory: string): string {
    validateGradleWrapper(buildRootDirectory)
    return path.resolve(buildRootDirectory, wrapperScriptFilename())
    return wrapperScriptFilename()
}

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')
    if (!fs.existsSync(wrapperProperties)) {
    verifyExists(wrapperProperties, 'Gradle wrapper properties file')
}

function verifyExists(file: string, description: string): void {
    if (!fs.existsSync(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.`
            `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.`)
    }
}