Skip to content

Commit

Permalink
Don't use full path when executing gradlew
Browse files Browse the repository at this point in the history
Fixes #796
  • Loading branch information
bigdaz committed Jul 13, 2023
1 parent 4301451 commit 3c11eee
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 38 deletions.
43 changes: 22 additions & 21 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.`);
}
}


/***/ }),
Expand Down Expand Up @@ -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.`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

13 changes: 2 additions & 11 deletions src/execution.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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
Expand All @@ -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.`)
}
}
26 changes: 21 additions & 5 deletions src/gradlew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`)
}
}

0 comments on commit 3c11eee

Please sign in to comment.