Merge pull request #734 from gradle/dd/input-params

Refactor in preparation for dependency-graph support
This commit is contained in:
Daz DeBoer 2023-06-06 18:52:31 +02:00 committed by GitHub
commit 1b2daf5833
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 632 additions and 200 deletions

View File

@ -5,7 +5,15 @@ description: 'Configures Gradle for use in GitHub actions, caching useful state
inputs:
gradle-version:
description: Gradle version to use
description: Gradle version to use. If specified, this Gradle version will be downloaded, added to the PATH and used for invoking Gradle.
required: false
gradle-executable:
description: Path to the Gradle executable. If specified, this executable will be added to the PATH and used for invoking Gradle.
required: false
build-root-directory:
description: Path to the root directory of the build. Default is the root of the GitHub workspace.
required: false
cache-disabled:
@ -45,14 +53,6 @@ inputs:
description: Gradle command line arguments (supports multi-line input)
required: false
build-root-directory:
description: Path to the root directory of the build
required: false
gradle-executable:
description: Path to the Gradle executable
required: false
generate-job-summary:
description: When 'false', no Job Summary will be generated for the Job.
required: false

292
dist/main/index.js vendored
View File

@ -63559,12 +63559,11 @@ const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const path_1 = __importDefault(__nccwpck_require__(1017));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const params = __importStar(__nccwpck_require__(3885));
const cache_utils_1 = __nccwpck_require__(1678);
const cache_extract_entries_1 = __nccwpck_require__(6161);
const RESTORED_CACHE_KEY_KEY = 'restored-cache-key';
exports.META_FILE_DIR = '.gradle-build-action';
const INCLUDE_PATHS_PARAMETER = 'gradle-home-cache-includes';
const EXCLUDE_PATHS_PARAMETER = 'gradle-home-cache-excludes';
class GradleStateCache {
constructor(gradleUserHome) {
this.gradleUserHome = gradleUserHome;
@ -63656,7 +63655,7 @@ class GradleStateCache {
});
}
deleteExcludedPaths() {
const rawPaths = core.getMultilineInput(EXCLUDE_PATHS_PARAMETER);
const rawPaths = params.getCacheExcludes();
const resolvedPaths = rawPaths.map(x => path_1.default.resolve(this.gradleUserHome, x));
for (const p of resolvedPaths) {
(0, cache_utils_1.cacheDebug)(`Deleting excluded path: ${p}`);
@ -63664,7 +63663,7 @@ class GradleStateCache {
}
}
getCachePath() {
const rawPaths = core.getMultilineInput(INCLUDE_PATHS_PARAMETER);
const rawPaths = params.getCacheIncludes();
rawPaths.push(exports.META_FILE_DIR);
const resolvedPaths = rawPaths.map(x => this.resolveCachePath(x));
(0, cache_utils_1.cacheDebug)(`Using cache paths: ${resolvedPaths}`);
@ -63892,6 +63891,7 @@ const path_1 = __importDefault(__nccwpck_require__(1017));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const core = __importStar(__nccwpck_require__(2186));
const glob = __importStar(__nccwpck_require__(8090));
const params = __importStar(__nccwpck_require__(3885));
const cache_base_1 = __nccwpck_require__(6948);
const cache_utils_1 = __nccwpck_require__(1678);
const build_results_1 = __nccwpck_require__(2107);
@ -64024,7 +64024,7 @@ class AbstractEntryExtractor {
}
awaitForDebugging(p) {
return __awaiter(this, void 0, void 0, function* () {
if ((0, cache_utils_1.isCacheDebuggingEnabled)()) {
if (params.isCacheDebuggingEnabled()) {
yield p;
}
return p;
@ -64395,14 +64395,8 @@ const exec = __importStar(__nccwpck_require__(1514));
const crypto = __importStar(__nccwpck_require__(6113));
const path = __importStar(__nccwpck_require__(1017));
const fs = __importStar(__nccwpck_require__(7147));
const params = __importStar(__nccwpck_require__(3885));
const CACHE_PROTOCOL_VERSION = 'v8-';
const JOB_CONTEXT_PARAMETER = 'workflow-job-context';
const CACHE_DISABLED_PARAMETER = 'cache-disabled';
const CACHE_READONLY_PARAMETER = 'cache-read-only';
const CACHE_WRITEONLY_PARAMETER = 'cache-write-only';
const STRICT_CACHE_MATCH_PARAMETER = 'gradle-home-cache-strict-match';
const CACHE_CLEANUP_ENABLED_PARAMETER = 'gradle-home-cache-cleanup';
const CACHE_DEBUG_VAR = 'GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED';
const CACHE_KEY_PREFIX_VAR = 'GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX';
const CACHE_KEY_OS_VAR = 'GRADLE_BUILD_ACTION_CACHE_KEY_ENVIRONMENT';
const CACHE_KEY_JOB_VAR = 'GRADLE_BUILD_ACTION_CACHE_KEY_JOB';
@ -64414,23 +64408,23 @@ function isCacheDisabled() {
if (!cache.isFeatureAvailable()) {
return true;
}
return core.getBooleanInput(CACHE_DISABLED_PARAMETER);
return params.isCacheDisabled();
}
exports.isCacheDisabled = isCacheDisabled;
function isCacheReadOnly() {
return !isCacheWriteOnly() && core.getBooleanInput(CACHE_READONLY_PARAMETER);
return !isCacheWriteOnly() && params.isCacheReadOnly();
}
exports.isCacheReadOnly = isCacheReadOnly;
function isCacheWriteOnly() {
return core.getBooleanInput(CACHE_WRITEONLY_PARAMETER);
return params.isCacheWriteOnly();
}
exports.isCacheWriteOnly = isCacheWriteOnly;
function isCacheDebuggingEnabled() {
return process.env[CACHE_DEBUG_VAR] ? true : false;
return params.isCacheDebuggingEnabled();
}
exports.isCacheDebuggingEnabled = isCacheDebuggingEnabled;
function isCacheCleanupEnabled() {
return core.getBooleanInput(CACHE_CLEANUP_ENABLED_PARAMETER);
return params.isCacheCleanupEnabled();
}
exports.isCacheCleanupEnabled = isCacheCleanupEnabled;
class CacheKey {
@ -64446,7 +64440,7 @@ function generateCacheKey(cacheName) {
const cacheKeyForJob = `${cacheKeyForEnvironment}|${getCacheKeyJob()}`;
const cacheKeyForJobContext = `${cacheKeyForJob}[${getCacheKeyJobInstance()}]`;
const cacheKey = `${cacheKeyForJobContext}-${getCacheKeyJobExecution()}`;
if (core.getBooleanInput(STRICT_CACHE_MATCH_PARAMETER)) {
if (params.isCacheStrictMatch()) {
return new CacheKey(cacheKey, [cacheKeyForJobContext]);
}
return new CacheKey(cacheKey, [cacheKeyForJobContext, cacheKeyForJob, cacheKeyForEnvironment]);
@ -64468,7 +64462,7 @@ function getCacheKeyJobInstance() {
if (override) {
return override;
}
const workflowJobContext = core.getInput(JOB_CONTEXT_PARAMETER);
const workflowJobContext = params.getJobContext();
return hashStrings([workflowJobContext]);
}
function getCacheKeyJobExecution() {
@ -64911,6 +64905,115 @@ function validateGradleWrapper(buildRootDirectory) {
}
/***/ }),
/***/ 3885:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobContext = exports.getArguments = exports.getGradleExecutable = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
const core = __importStar(__nccwpck_require__(2186));
const string_argv_1 = __nccwpck_require__(9663);
function isCacheDisabled() {
return getBooleanInput('cache-disabled');
}
exports.isCacheDisabled = isCacheDisabled;
function isCacheReadOnly() {
return getBooleanInput('cache-read-only');
}
exports.isCacheReadOnly = isCacheReadOnly;
function isCacheWriteOnly() {
return getBooleanInput('cache-write-only');
}
exports.isCacheWriteOnly = isCacheWriteOnly;
function isCacheStrictMatch() {
return getBooleanInput('gradle-home-cache-strict-match');
}
exports.isCacheStrictMatch = isCacheStrictMatch;
function isCacheDebuggingEnabled() {
return process.env['GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED'] ? true : false;
}
exports.isCacheDebuggingEnabled = isCacheDebuggingEnabled;
function isCacheCleanupEnabled() {
return getBooleanInput('gradle-home-cache-cleanup');
}
exports.isCacheCleanupEnabled = isCacheCleanupEnabled;
function getCacheIncludes() {
return core.getMultilineInput('gradle-home-cache-includes');
}
exports.getCacheIncludes = getCacheIncludes;
function getCacheExcludes() {
return core.getMultilineInput('gradle-home-cache-excludes');
}
exports.getCacheExcludes = getCacheExcludes;
function getBuildRootDirectory() {
return core.getInput('build-root-directory');
}
exports.getBuildRootDirectory = getBuildRootDirectory;
function getGradleVersion() {
return core.getInput('gradle-version');
}
exports.getGradleVersion = getGradleVersion;
function getGradleExecutable() {
return core.getInput('gradle-executable');
}
exports.getGradleExecutable = getGradleExecutable;
function getArguments() {
const input = core.getInput('arguments');
return (0, string_argv_1.parseArgsStringToArgv)(input);
}
exports.getArguments = getArguments;
function getJobContext() {
return core.getInput('workflow-job-context');
}
exports.getJobContext = getJobContext;
function getGithubToken() {
return core.getInput('github-token', { required: true });
}
exports.getGithubToken = getGithubToken;
function isJobSummaryEnabled() {
return getBooleanInput('generate-job-summary', true);
}
exports.isJobSummaryEnabled = isJobSummaryEnabled;
function getBooleanInput(paramName, paramDefault = false) {
const paramValue = core.getInput(paramName);
switch (paramValue.toLowerCase().trim()) {
case '':
return paramDefault;
case 'false':
return false;
case 'true':
return true;
}
throw TypeError(`The value '${paramValue} is not valid for '${paramName}. Valid values are: [true, false]`);
}
/***/ }),
/***/ 7345:
@ -65076,23 +65179,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.run = void 0;
const core = __importStar(__nccwpck_require__(2186));
const path = __importStar(__nccwpck_require__(1017));
const string_argv_1 = __nccwpck_require__(9663);
const setupGradle = __importStar(__nccwpck_require__(8652));
const execution = __importStar(__nccwpck_require__(3584));
const provision = __importStar(__nccwpck_require__(2501));
const provisioner = __importStar(__nccwpck_require__(2501));
const layout = __importStar(__nccwpck_require__(8182));
const params = __importStar(__nccwpck_require__(3885));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const workspaceDirectory = process.env[`GITHUB_WORKSPACE`] || '';
const buildRootDirectory = resolveBuildRootDirectory(workspaceDirectory);
yield setupGradle.setup(buildRootDirectory);
const executable = yield provisionGradle(workspaceDirectory);
if (executable !== undefined) {
core.addPath(path.dirname(executable));
}
const args = parseCommandLineArguments();
yield setupGradle.setup();
const executable = yield provisioner.provisionGradle();
const args = params.getArguments();
if (args.length > 0) {
const buildRootDirectory = layout.buildRootDirectory();
yield execution.executeGradleBuild(executable, buildRootDirectory, args);
}
}
@ -65106,28 +65205,6 @@ function run() {
}
exports.run = run;
run();
function provisionGradle(workspaceDirectory) {
return __awaiter(this, void 0, void 0, function* () {
const gradleVersion = core.getInput('gradle-version');
if (gradleVersion !== '' && gradleVersion !== 'wrapper') {
return path.resolve(yield provision.gradleVersion(gradleVersion));
}
const gradleExecutable = core.getInput('gradle-executable');
if (gradleExecutable !== '') {
return path.resolve(workspaceDirectory, gradleExecutable);
}
return undefined;
});
}
function resolveBuildRootDirectory(baseDirectory) {
const buildRootDirectory = core.getInput('build-root-directory');
const resolvedBuildRootDirectory = buildRootDirectory === '' ? path.resolve(baseDirectory) : path.resolve(baseDirectory, buildRootDirectory);
return resolvedBuildRootDirectory;
}
function parseCommandLineArguments() {
const input = core.getInput('arguments');
return (0, string_argv_1.parseArgsStringToArgv)(input);
}
/***/ }),
@ -65170,7 +65247,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.gradleVersion = void 0;
exports.provisionGradle = void 0;
const fs = __importStar(__nccwpck_require__(7147));
const os = __importStar(__nccwpck_require__(2037));
const path = __importStar(__nccwpck_require__(1017));
@ -65179,9 +65256,32 @@ const core = __importStar(__nccwpck_require__(2186));
const cache = __importStar(__nccwpck_require__(7799));
const toolCache = __importStar(__nccwpck_require__(7784));
const gradlew = __importStar(__nccwpck_require__(2335));
const params = __importStar(__nccwpck_require__(3885));
const layout = __importStar(__nccwpck_require__(8182));
const cache_utils_1 = __nccwpck_require__(1678);
const gradleVersionsBaseUrl = 'https://services.gradle.org/versions';
function gradleVersion(version) {
function provisionGradle() {
return __awaiter(this, void 0, void 0, function* () {
const gradleVersion = params.getGradleVersion();
if (gradleVersion !== '' && gradleVersion !== 'wrapper') {
return addToPath(path.resolve(yield installGradle(gradleVersion)));
}
const gradleExecutable = params.getGradleExecutable();
if (gradleExecutable !== '') {
const workspaceDirectory = layout.workspaceDirectory();
return addToPath(path.resolve(workspaceDirectory, gradleExecutable));
}
return undefined;
});
}
exports.provisionGradle = provisionGradle;
function addToPath(executable) {
return __awaiter(this, void 0, void 0, function* () {
core.addPath(path.dirname(executable));
return executable;
});
}
function installGradle(version) {
return __awaiter(this, void 0, void 0, function* () {
switch (version) {
case 'current':
@ -65200,18 +65300,17 @@ function gradleVersion(version) {
}
});
}
exports.gradleVersion = gradleVersion;
function gradleCurrent() {
return __awaiter(this, void 0, void 0, function* () {
const versionInfo = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`);
return provisionGradle(versionInfo);
return installGradleVersion(versionInfo);
});
}
function gradleReleaseCandidate() {
return __awaiter(this, void 0, void 0, function* () {
const versionInfo = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`);
if (versionInfo && versionInfo.version && versionInfo.downloadUrl) {
return provisionGradle(versionInfo);
return installGradleVersion(versionInfo);
}
core.info('No current release-candidate found, will fallback to current');
return gradleCurrent();
@ -65220,13 +65319,13 @@ function gradleReleaseCandidate() {
function gradleNightly() {
return __awaiter(this, void 0, void 0, function* () {
const versionInfo = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/nightly`);
return provisionGradle(versionInfo);
return installGradleVersion(versionInfo);
});
}
function gradleReleaseNightly() {
return __awaiter(this, void 0, void 0, function* () {
const versionInfo = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-nightly`);
return provisionGradle(versionInfo);
return installGradleVersion(versionInfo);
});
}
function gradle(version) {
@ -65235,7 +65334,7 @@ function gradle(version) {
if (!versionInfo) {
throw new Error(`Gradle version ${version} does not exists`);
}
return provisionGradle(versionInfo);
return installGradleVersion(versionInfo);
});
}
function gradleVersionDeclaration(url) {
@ -65251,7 +65350,7 @@ function findGradleVersionDeclaration(version) {
});
});
}
function provisionGradle(versionInfo) {
function installGradleVersion(versionInfo) {
return __awaiter(this, void 0, void 0, function* () {
return core.group(`Provision Gradle ${versionInfo.version}`, () => __awaiter(this, void 0, void 0, function* () {
return locateGradleAndDownloadIfRequired(versionInfo);
@ -65334,6 +65433,55 @@ function httpGetString(url) {
}
/***/ }),
/***/ 8182:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.buildRootDirectory = exports.workspaceDirectory = void 0;
const params = __importStar(__nccwpck_require__(3885));
const path = __importStar(__nccwpck_require__(1017));
function workspaceDirectory() {
return process.env[`GITHUB_WORKSPACE`] || '';
}
exports.workspaceDirectory = workspaceDirectory;
function buildRootDirectory() {
const baseDirectory = workspaceDirectory();
const buildRootDirectoryInput = params.getBuildRootDirectory();
const resolvedBuildRootDirectory = buildRootDirectoryInput === ''
? path.resolve(baseDirectory)
: path.resolve(baseDirectory, buildRootDirectoryInput);
return resolvedBuildRootDirectory;
}
exports.buildRootDirectory = buildRootDirectory;
/***/ }),
/***/ 8652:
@ -65381,6 +65529,8 @@ const summary_1 = __nccwpck_require__(1327);
const path = __importStar(__nccwpck_require__(1017));
const os = __importStar(__nccwpck_require__(2037));
const caches = __importStar(__nccwpck_require__(3800));
const layout = __importStar(__nccwpck_require__(8182));
const params = __importStar(__nccwpck_require__(3885));
const job_summary_1 = __nccwpck_require__(7345);
const build_results_1 = __nccwpck_require__(2107);
const cache_reporting_1 = __nccwpck_require__(6674);
@ -65388,16 +65538,9 @@ const daemon_controller_1 = __nccwpck_require__(5146);
const GRADLE_SETUP_VAR = 'GRADLE_BUILD_ACTION_SETUP_COMPLETED';
const GRADLE_USER_HOME = 'GRADLE_USER_HOME';
const CACHE_LISTENER = 'CACHE_LISTENER';
const JOB_SUMMARY_ENABLED_PARAMETER = 'generate-job-summary';
function shouldGenerateJobSummary() {
if (!process.env[summary_1.SUMMARY_ENV_VAR]) {
return false;
}
return core.getBooleanInput(JOB_SUMMARY_ENABLED_PARAMETER);
}
function setup(buildRootDirectory) {
function setup() {
return __awaiter(this, void 0, void 0, function* () {
const gradleUserHome = yield determineGradleUserHome(buildRootDirectory);
const gradleUserHome = yield determineGradleUserHome();
if (process.env[GRADLE_SETUP_VAR]) {
core.info('Gradle setup only performed on first gradle-build-action step in workflow.');
return;
@ -65432,10 +65575,11 @@ function complete() {
});
}
exports.complete = complete;
function determineGradleUserHome(rootDir) {
function determineGradleUserHome() {
return __awaiter(this, void 0, void 0, function* () {
const customGradleUserHome = process.env['GRADLE_USER_HOME'];
if (customGradleUserHome) {
const rootDir = layout.workspaceDirectory();
return path.resolve(rootDir, customGradleUserHome);
}
return path.resolve(yield determineUserHome(), '.gradle');
@ -65455,6 +65599,12 @@ function determineUserHome() {
return userHome;
});
}
function shouldGenerateJobSummary() {
if (!process.env[summary_1.SUMMARY_ENV_VAR]) {
return false;
}
return params.isJobSummaryEnabled();
}
/***/ }),

File diff suppressed because one or more lines are too long

265
dist/post/index.js vendored
View File

@ -62662,12 +62662,11 @@ const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const path_1 = __importDefault(__nccwpck_require__(1017));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const params = __importStar(__nccwpck_require__(3885));
const cache_utils_1 = __nccwpck_require__(1678);
const cache_extract_entries_1 = __nccwpck_require__(6161);
const RESTORED_CACHE_KEY_KEY = 'restored-cache-key';
exports.META_FILE_DIR = '.gradle-build-action';
const INCLUDE_PATHS_PARAMETER = 'gradle-home-cache-includes';
const EXCLUDE_PATHS_PARAMETER = 'gradle-home-cache-excludes';
class GradleStateCache {
constructor(gradleUserHome) {
this.gradleUserHome = gradleUserHome;
@ -62759,7 +62758,7 @@ class GradleStateCache {
});
}
deleteExcludedPaths() {
const rawPaths = core.getMultilineInput(EXCLUDE_PATHS_PARAMETER);
const rawPaths = params.getCacheExcludes();
const resolvedPaths = rawPaths.map(x => path_1.default.resolve(this.gradleUserHome, x));
for (const p of resolvedPaths) {
(0, cache_utils_1.cacheDebug)(`Deleting excluded path: ${p}`);
@ -62767,7 +62766,7 @@ class GradleStateCache {
}
}
getCachePath() {
const rawPaths = core.getMultilineInput(INCLUDE_PATHS_PARAMETER);
const rawPaths = params.getCacheIncludes();
rawPaths.push(exports.META_FILE_DIR);
const resolvedPaths = rawPaths.map(x => this.resolveCachePath(x));
(0, cache_utils_1.cacheDebug)(`Using cache paths: ${resolvedPaths}`);
@ -62995,6 +62994,7 @@ const path_1 = __importDefault(__nccwpck_require__(1017));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const core = __importStar(__nccwpck_require__(2186));
const glob = __importStar(__nccwpck_require__(8090));
const params = __importStar(__nccwpck_require__(3885));
const cache_base_1 = __nccwpck_require__(6948);
const cache_utils_1 = __nccwpck_require__(1678);
const build_results_1 = __nccwpck_require__(2107);
@ -63127,7 +63127,7 @@ class AbstractEntryExtractor {
}
awaitForDebugging(p) {
return __awaiter(this, void 0, void 0, function* () {
if ((0, cache_utils_1.isCacheDebuggingEnabled)()) {
if (params.isCacheDebuggingEnabled()) {
yield p;
}
return p;
@ -63498,14 +63498,8 @@ const exec = __importStar(__nccwpck_require__(1514));
const crypto = __importStar(__nccwpck_require__(6113));
const path = __importStar(__nccwpck_require__(1017));
const fs = __importStar(__nccwpck_require__(7147));
const params = __importStar(__nccwpck_require__(3885));
const CACHE_PROTOCOL_VERSION = 'v8-';
const JOB_CONTEXT_PARAMETER = 'workflow-job-context';
const CACHE_DISABLED_PARAMETER = 'cache-disabled';
const CACHE_READONLY_PARAMETER = 'cache-read-only';
const CACHE_WRITEONLY_PARAMETER = 'cache-write-only';
const STRICT_CACHE_MATCH_PARAMETER = 'gradle-home-cache-strict-match';
const CACHE_CLEANUP_ENABLED_PARAMETER = 'gradle-home-cache-cleanup';
const CACHE_DEBUG_VAR = 'GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED';
const CACHE_KEY_PREFIX_VAR = 'GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX';
const CACHE_KEY_OS_VAR = 'GRADLE_BUILD_ACTION_CACHE_KEY_ENVIRONMENT';
const CACHE_KEY_JOB_VAR = 'GRADLE_BUILD_ACTION_CACHE_KEY_JOB';
@ -63517,23 +63511,23 @@ function isCacheDisabled() {
if (!cache.isFeatureAvailable()) {
return true;
}
return core.getBooleanInput(CACHE_DISABLED_PARAMETER);
return params.isCacheDisabled();
}
exports.isCacheDisabled = isCacheDisabled;
function isCacheReadOnly() {
return !isCacheWriteOnly() && core.getBooleanInput(CACHE_READONLY_PARAMETER);
return !isCacheWriteOnly() && params.isCacheReadOnly();
}
exports.isCacheReadOnly = isCacheReadOnly;
function isCacheWriteOnly() {
return core.getBooleanInput(CACHE_WRITEONLY_PARAMETER);
return params.isCacheWriteOnly();
}
exports.isCacheWriteOnly = isCacheWriteOnly;
function isCacheDebuggingEnabled() {
return process.env[CACHE_DEBUG_VAR] ? true : false;
return params.isCacheDebuggingEnabled();
}
exports.isCacheDebuggingEnabled = isCacheDebuggingEnabled;
function isCacheCleanupEnabled() {
return core.getBooleanInput(CACHE_CLEANUP_ENABLED_PARAMETER);
return params.isCacheCleanupEnabled();
}
exports.isCacheCleanupEnabled = isCacheCleanupEnabled;
class CacheKey {
@ -63549,7 +63543,7 @@ function generateCacheKey(cacheName) {
const cacheKeyForJob = `${cacheKeyForEnvironment}|${getCacheKeyJob()}`;
const cacheKeyForJobContext = `${cacheKeyForJob}[${getCacheKeyJobInstance()}]`;
const cacheKey = `${cacheKeyForJobContext}-${getCacheKeyJobExecution()}`;
if (core.getBooleanInput(STRICT_CACHE_MATCH_PARAMETER)) {
if (params.isCacheStrictMatch()) {
return new CacheKey(cacheKey, [cacheKeyForJobContext]);
}
return new CacheKey(cacheKey, [cacheKeyForJobContext, cacheKeyForJob, cacheKeyForEnvironment]);
@ -63571,7 +63565,7 @@ function getCacheKeyJobInstance() {
if (override) {
return override;
}
const workflowJobContext = core.getInput(JOB_CONTEXT_PARAMETER);
const workflowJobContext = params.getJobContext();
return hashStrings([workflowJobContext]);
}
function getCacheKeyJobExecution() {
@ -63883,6 +63877,115 @@ class DaemonController {
exports.DaemonController = DaemonController;
/***/ }),
/***/ 3885:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobContext = exports.getArguments = exports.getGradleExecutable = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
const core = __importStar(__nccwpck_require__(2186));
const string_argv_1 = __nccwpck_require__(9663);
function isCacheDisabled() {
return getBooleanInput('cache-disabled');
}
exports.isCacheDisabled = isCacheDisabled;
function isCacheReadOnly() {
return getBooleanInput('cache-read-only');
}
exports.isCacheReadOnly = isCacheReadOnly;
function isCacheWriteOnly() {
return getBooleanInput('cache-write-only');
}
exports.isCacheWriteOnly = isCacheWriteOnly;
function isCacheStrictMatch() {
return getBooleanInput('gradle-home-cache-strict-match');
}
exports.isCacheStrictMatch = isCacheStrictMatch;
function isCacheDebuggingEnabled() {
return process.env['GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED'] ? true : false;
}
exports.isCacheDebuggingEnabled = isCacheDebuggingEnabled;
function isCacheCleanupEnabled() {
return getBooleanInput('gradle-home-cache-cleanup');
}
exports.isCacheCleanupEnabled = isCacheCleanupEnabled;
function getCacheIncludes() {
return core.getMultilineInput('gradle-home-cache-includes');
}
exports.getCacheIncludes = getCacheIncludes;
function getCacheExcludes() {
return core.getMultilineInput('gradle-home-cache-excludes');
}
exports.getCacheExcludes = getCacheExcludes;
function getBuildRootDirectory() {
return core.getInput('build-root-directory');
}
exports.getBuildRootDirectory = getBuildRootDirectory;
function getGradleVersion() {
return core.getInput('gradle-version');
}
exports.getGradleVersion = getGradleVersion;
function getGradleExecutable() {
return core.getInput('gradle-executable');
}
exports.getGradleExecutable = getGradleExecutable;
function getArguments() {
const input = core.getInput('arguments');
return (0, string_argv_1.parseArgsStringToArgv)(input);
}
exports.getArguments = getArguments;
function getJobContext() {
return core.getInput('workflow-job-context');
}
exports.getJobContext = getJobContext;
function getGithubToken() {
return core.getInput('github-token', { required: true });
}
exports.getGithubToken = getGithubToken;
function isJobSummaryEnabled() {
return getBooleanInput('generate-job-summary', true);
}
exports.isJobSummaryEnabled = isJobSummaryEnabled;
function getBooleanInput(paramName, paramDefault = false) {
const paramValue = core.getInput(paramName);
switch (paramValue.toLowerCase().trim()) {
case '':
return paramDefault;
case 'false':
return false;
case 'true':
return true;
}
throw TypeError(`The value '${paramValue} is not valid for '${paramName}. Valid values are: [true, false]`);
}
/***/ }),
/***/ 7345:
@ -64070,6 +64173,55 @@ function handleFailure(error) {
run();
/***/ }),
/***/ 8182:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.buildRootDirectory = exports.workspaceDirectory = void 0;
const params = __importStar(__nccwpck_require__(3885));
const path = __importStar(__nccwpck_require__(1017));
function workspaceDirectory() {
return process.env[`GITHUB_WORKSPACE`] || '';
}
exports.workspaceDirectory = workspaceDirectory;
function buildRootDirectory() {
const baseDirectory = workspaceDirectory();
const buildRootDirectoryInput = params.getBuildRootDirectory();
const resolvedBuildRootDirectory = buildRootDirectoryInput === ''
? path.resolve(baseDirectory)
: path.resolve(baseDirectory, buildRootDirectoryInput);
return resolvedBuildRootDirectory;
}
exports.buildRootDirectory = buildRootDirectory;
/***/ }),
/***/ 8652:
@ -64117,6 +64269,8 @@ const summary_1 = __nccwpck_require__(1327);
const path = __importStar(__nccwpck_require__(1017));
const os = __importStar(__nccwpck_require__(2037));
const caches = __importStar(__nccwpck_require__(3800));
const layout = __importStar(__nccwpck_require__(8182));
const params = __importStar(__nccwpck_require__(3885));
const job_summary_1 = __nccwpck_require__(7345);
const build_results_1 = __nccwpck_require__(2107);
const cache_reporting_1 = __nccwpck_require__(6674);
@ -64124,16 +64278,9 @@ const daemon_controller_1 = __nccwpck_require__(5146);
const GRADLE_SETUP_VAR = 'GRADLE_BUILD_ACTION_SETUP_COMPLETED';
const GRADLE_USER_HOME = 'GRADLE_USER_HOME';
const CACHE_LISTENER = 'CACHE_LISTENER';
const JOB_SUMMARY_ENABLED_PARAMETER = 'generate-job-summary';
function shouldGenerateJobSummary() {
if (!process.env[summary_1.SUMMARY_ENV_VAR]) {
return false;
}
return core.getBooleanInput(JOB_SUMMARY_ENABLED_PARAMETER);
}
function setup(buildRootDirectory) {
function setup() {
return __awaiter(this, void 0, void 0, function* () {
const gradleUserHome = yield determineGradleUserHome(buildRootDirectory);
const gradleUserHome = yield determineGradleUserHome();
if (process.env[GRADLE_SETUP_VAR]) {
core.info('Gradle setup only performed on first gradle-build-action step in workflow.');
return;
@ -64168,10 +64315,11 @@ function complete() {
});
}
exports.complete = complete;
function determineGradleUserHome(rootDir) {
function determineGradleUserHome() {
return __awaiter(this, void 0, void 0, function* () {
const customGradleUserHome = process.env['GRADLE_USER_HOME'];
if (customGradleUserHome) {
const rootDir = layout.workspaceDirectory();
return path.resolve(rootDir, customGradleUserHome);
}
return path.resolve(yield determineUserHome(), '.gradle');
@ -64191,6 +64339,12 @@ function determineUserHome() {
return userHome;
});
}
function shouldGenerateJobSummary() {
if (!process.env[summary_1.SUMMARY_ENV_VAR]) {
return false;
}
return params.isJobSummaryEnabled();
}
/***/ }),
@ -64353,6 +64507,59 @@ module.exports = require("util");
"use strict";
module.exports = require("zlib");
/***/ }),
/***/ 9663:
/***/ ((__unused_webpack_module, exports) => {
"use strict";
exports.__esModule = true;
exports.parseArgsStringToArgv = void 0;
function parseArgsStringToArgv(value, env, file) {
// ([^\s'"]([^\s'"]*(['"])([^\3]*?)\3)+[^\s'"]*) Matches nested quotes until the first space outside of quotes
// [^\s'"]+ or Match if not a space ' or "
// (['"])([^\5]*?)\5 or Match "quoted text" without quotes
// `\3` and `\5` are a backreference to the quote style (' or ") captured
var myRegexp = /([^\s'"]([^\s'"]*(['"])([^\3]*?)\3)+[^\s'"]*)|[^\s'"]+|(['"])([^\5]*?)\5/gi;
var myString = value;
var myArray = [];
if (env) {
myArray.push(env);
}
if (file) {
myArray.push(file);
}
var match;
do {
// Each call to exec returns the next regex match as an array
match = myRegexp.exec(myString);
if (match !== null) {
// Index 1 in the array is the captured group if it exists
// Index 0 is the matched text, which we use if no captured group exists
myArray.push(firstString(match[1], match[6], match[0]));
}
} while (match !== null);
return myArray;
}
exports["default"] = parseArgsStringToArgv;
exports.parseArgsStringToArgv = parseArgsStringToArgv;
// Accepts any number of arguments, and returns the first one that is a string
// (even an empty string)
function firstString() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
for (var i = 0; i < args.length; i++) {
var arg = args[i];
if (typeof arg === "string") {
return arg;
}
}
}
/***/ }),
/***/ 3765:

File diff suppressed because one or more lines are too long

View File

@ -2,6 +2,7 @@ import * as core from '@actions/core'
import * as exec from '@actions/exec'
import path from 'path'
import fs from 'fs'
import * as params from './input-params'
import {CacheListener} from './cache-reporting'
import {saveCache, restoreCache, cacheDebug, isCacheDebuggingEnabled, tryDelete, generateCacheKey} from './cache-utils'
import {GradleHomeEntryExtractor} from './cache-extract-entries'
@ -9,8 +10,6 @@ import {GradleHomeEntryExtractor} from './cache-extract-entries'
const RESTORED_CACHE_KEY_KEY = 'restored-cache-key'
export const META_FILE_DIR = '.gradle-build-action'
const INCLUDE_PATHS_PARAMETER = 'gradle-home-cache-includes'
const EXCLUDE_PATHS_PARAMETER = 'gradle-home-cache-excludes'
export class GradleStateCache {
private cacheName: string
@ -142,7 +141,7 @@ export class GradleStateCache {
* Delete any file paths that are excluded by the `gradle-home-cache-excludes` parameter.
*/
private deleteExcludedPaths(): void {
const rawPaths: string[] = core.getMultilineInput(EXCLUDE_PATHS_PARAMETER)
const rawPaths: string[] = params.getCacheExcludes()
const resolvedPaths = rawPaths.map(x => path.resolve(this.gradleUserHome, x))
for (const p of resolvedPaths) {
@ -157,7 +156,7 @@ export class GradleStateCache {
* but this can be overridden by the `gradle-home-cache-includes` parameter.
*/
protected getCachePath(): string[] {
const rawPaths: string[] = core.getMultilineInput(INCLUDE_PATHS_PARAMETER)
const rawPaths: string[] = params.getCacheIncludes()
rawPaths.push(META_FILE_DIR)
const resolvedPaths = rawPaths.map(x => this.resolveCachePath(x))
cacheDebug(`Using cache paths: ${resolvedPaths}`)

View File

@ -3,17 +3,11 @@ import fs from 'fs'
import * as core from '@actions/core'
import * as glob from '@actions/glob'
import * as params from './input-params'
import {META_FILE_DIR} from './cache-base'
import {CacheEntryListener, CacheListener} from './cache-reporting'
import {
cacheDebug,
getCacheKeyPrefix,
hashFileNames,
isCacheDebuggingEnabled,
restoreCache,
saveCache,
tryDelete
} from './cache-utils'
import {cacheDebug, getCacheKeyPrefix, hashFileNames, restoreCache, saveCache, tryDelete} from './cache-utils'
import {loadBuildResults} from './build-results'
const SKIP_RESTORE_VAR = 'GRADLE_BUILD_ACTION_SKIP_RESTORE'
@ -246,7 +240,7 @@ abstract class AbstractEntryExtractor {
// Run actions sequentially if debugging is enabled
private async awaitForDebugging(p: Promise<ExtractedCacheEntry>): Promise<ExtractedCacheEntry> {
if (isCacheDebuggingEnabled()) {
if (params.isCacheDebuggingEnabled()) {
await p
}
return p

View File

@ -7,18 +7,12 @@ import * as crypto from 'crypto'
import * as path from 'path'
import * as fs from 'fs'
import * as params from './input-params'
import {CacheEntryListener} from './cache-reporting'
const CACHE_PROTOCOL_VERSION = 'v8-'
const JOB_CONTEXT_PARAMETER = 'workflow-job-context'
const CACHE_DISABLED_PARAMETER = 'cache-disabled'
const CACHE_READONLY_PARAMETER = 'cache-read-only'
const CACHE_WRITEONLY_PARAMETER = 'cache-write-only'
const STRICT_CACHE_MATCH_PARAMETER = 'gradle-home-cache-strict-match'
const CACHE_CLEANUP_ENABLED_PARAMETER = 'gradle-home-cache-cleanup'
const CACHE_DEBUG_VAR = 'GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED'
const CACHE_KEY_PREFIX_VAR = 'GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX'
const CACHE_KEY_OS_VAR = 'GRADLE_BUILD_ACTION_CACHE_KEY_ENVIRONMENT'
const CACHE_KEY_JOB_VAR = 'GRADLE_BUILD_ACTION_CACHE_KEY_JOB'
@ -32,23 +26,23 @@ export function isCacheDisabled(): boolean {
if (!cache.isFeatureAvailable()) {
return true
}
return core.getBooleanInput(CACHE_DISABLED_PARAMETER)
return params.isCacheDisabled()
}
export function isCacheReadOnly(): boolean {
return !isCacheWriteOnly() && core.getBooleanInput(CACHE_READONLY_PARAMETER)
return !isCacheWriteOnly() && params.isCacheReadOnly()
}
export function isCacheWriteOnly(): boolean {
return core.getBooleanInput(CACHE_WRITEONLY_PARAMETER)
return params.isCacheWriteOnly()
}
export function isCacheDebuggingEnabled(): boolean {
return process.env[CACHE_DEBUG_VAR] ? true : false
return params.isCacheDebuggingEnabled()
}
export function isCacheCleanupEnabled(): boolean {
return core.getBooleanInput(CACHE_CLEANUP_ENABLED_PARAMETER)
return params.isCacheCleanupEnabled()
}
/**
@ -97,7 +91,7 @@ export function generateCacheKey(cacheName: string): CacheKey {
// Exact match on Git SHA
const cacheKey = `${cacheKeyForJobContext}-${getCacheKeyJobExecution()}`
if (core.getBooleanInput(STRICT_CACHE_MATCH_PARAMETER)) {
if (params.isCacheStrictMatch()) {
return new CacheKey(cacheKey, [cacheKeyForJobContext])
}
@ -126,7 +120,7 @@ function getCacheKeyJobInstance(): string {
// By default, we hash the full `matrix` data for the run, to uniquely identify this job invocation
// The only way we can obtain the `matrix` data is via the `workflow-job-context` parameter in action.yml.
const workflowJobContext = core.getInput(JOB_CONTEXT_PARAMETER)
const workflowJobContext = params.getJobContext()
return hashStrings([workflowJobContext])
}

77
src/input-params.ts Normal file
View File

@ -0,0 +1,77 @@
import * as core from '@actions/core'
import {parseArgsStringToArgv} from 'string-argv'
export function isCacheDisabled(): boolean {
return getBooleanInput('cache-disabled')
}
export function isCacheReadOnly(): boolean {
return getBooleanInput('cache-read-only')
}
export function isCacheWriteOnly(): boolean {
return getBooleanInput('cache-write-only')
}
export function isCacheStrictMatch(): boolean {
return getBooleanInput('gradle-home-cache-strict-match')
}
export function isCacheDebuggingEnabled(): boolean {
return process.env['GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED'] ? true : false
}
export function isCacheCleanupEnabled(): boolean {
return getBooleanInput('gradle-home-cache-cleanup')
}
export function getCacheIncludes(): string[] {
return core.getMultilineInput('gradle-home-cache-includes')
}
export function getCacheExcludes(): string[] {
return core.getMultilineInput('gradle-home-cache-excludes')
}
export function getBuildRootDirectory(): string {
return core.getInput('build-root-directory')
}
export function getGradleVersion(): string {
return core.getInput('gradle-version')
}
export function getGradleExecutable(): string {
return core.getInput('gradle-executable')
}
export function getArguments(): string[] {
const input = core.getInput('arguments')
return parseArgsStringToArgv(input)
}
// Internal parameters
export function getJobContext(): string {
return core.getInput('workflow-job-context')
}
export function getGithubToken(): string {
return core.getInput('github-token', {required: true})
}
export function isJobSummaryEnabled(): boolean {
return getBooleanInput('generate-job-summary', true)
}
function getBooleanInput(paramName: string, paramDefault = false): boolean {
const paramValue = core.getInput(paramName)
switch (paramValue.toLowerCase().trim()) {
case '':
return paramDefault
case 'false':
return false
case 'true':
return true
}
throw TypeError(`The value '${paramValue} is not valid for '${paramName}. Valid values are: [true, false]`)
}

View File

@ -1,30 +1,26 @@
import * as core from '@actions/core'
import * as path from 'path'
import {parseArgsStringToArgv} from 'string-argv'
import * as setupGradle from './setup-gradle'
import * as execution from './execution'
import * as provision from './provision'
import * as provisioner from './provision'
import * as layout from './repository-layout'
import * as params from './input-params'
/**
* The main entry point for the action, called by Github Actions for the step.
*/
export async function run(): Promise<void> {
try {
const workspaceDirectory = process.env[`GITHUB_WORKSPACE`] || ''
const buildRootDirectory = resolveBuildRootDirectory(workspaceDirectory)
// Configure Gradle environment (Gradle User Home)
await setupGradle.setup()
await setupGradle.setup(buildRootDirectory)
const executable = await provisionGradle(workspaceDirectory)
// executable will be undefined if using Gradle wrapper
if (executable !== undefined) {
core.addPath(path.dirname(executable))
}
// Download and install Gradle if required
const executable = await provisioner.provisionGradle()
// Only execute if arguments have been provided
const args: string[] = parseCommandLineArguments()
const args: string[] = params.getArguments()
if (args.length > 0) {
const buildRootDirectory = layout.buildRootDirectory()
await execution.executeGradleBuild(executable, buildRootDirectory, args)
}
} catch (error) {
@ -36,29 +32,3 @@ export async function run(): Promise<void> {
}
run()
async function provisionGradle(workspaceDirectory: string): Promise<string | undefined> {
const gradleVersion = core.getInput('gradle-version')
if (gradleVersion !== '' && gradleVersion !== 'wrapper') {
return path.resolve(await provision.gradleVersion(gradleVersion))
}
const gradleExecutable = core.getInput('gradle-executable')
if (gradleExecutable !== '') {
return path.resolve(workspaceDirectory, gradleExecutable)
}
return undefined
}
function resolveBuildRootDirectory(baseDirectory: string): string {
const buildRootDirectory = core.getInput('build-root-directory')
const resolvedBuildRootDirectory =
buildRootDirectory === '' ? path.resolve(baseDirectory) : path.resolve(baseDirectory, buildRootDirectory)
return resolvedBuildRootDirectory
}
function parseCommandLineArguments(): string[] {
const input = core.getInput('arguments')
return parseArgsStringToArgv(input)
}

View File

@ -7,14 +7,37 @@ import * as cache from '@actions/cache'
import * as toolCache from '@actions/tool-cache'
import * as gradlew from './gradlew'
import * as params from './input-params'
import * as layout from './repository-layout'
import {handleCacheFailure, isCacheDisabled, isCacheReadOnly} from './cache-utils'
const gradleVersionsBaseUrl = 'https://services.gradle.org/versions'
/**
* @return Gradle executable path
* Install any configured version of Gradle, adding the executable to the PATH.
* @return Installed Gradle executable or undefined if no version configured.
*/
export async function gradleVersion(version: string): Promise<string> {
export async function provisionGradle(): Promise<string | undefined> {
const gradleVersion = params.getGradleVersion()
if (gradleVersion !== '' && gradleVersion !== 'wrapper') {
return addToPath(path.resolve(await installGradle(gradleVersion)))
}
const gradleExecutable = params.getGradleExecutable()
if (gradleExecutable !== '') {
const workspaceDirectory = layout.workspaceDirectory()
return addToPath(path.resolve(workspaceDirectory, gradleExecutable))
}
return undefined
}
async function addToPath(executable: string): Promise<string> {
core.addPath(path.dirname(executable))
return executable
}
async function installGradle(version: string): Promise<string> {
switch (version) {
case 'current':
return gradleCurrent()
@ -34,13 +57,13 @@ export async function gradleVersion(version: string): Promise<string> {
async function gradleCurrent(): Promise<string> {
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`)
return provisionGradle(versionInfo)
return installGradleVersion(versionInfo)
}
async function gradleReleaseCandidate(): Promise<string> {
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`)
if (versionInfo && versionInfo.version && versionInfo.downloadUrl) {
return provisionGradle(versionInfo)
return installGradleVersion(versionInfo)
}
core.info('No current release-candidate found, will fallback to current')
return gradleCurrent()
@ -48,12 +71,12 @@ async function gradleReleaseCandidate(): Promise<string> {
async function gradleNightly(): Promise<string> {
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/nightly`)
return provisionGradle(versionInfo)
return installGradleVersion(versionInfo)
}
async function gradleReleaseNightly(): Promise<string> {
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-nightly`)
return provisionGradle(versionInfo)
return installGradleVersion(versionInfo)
}
async function gradle(version: string): Promise<string> {
@ -61,7 +84,7 @@ async function gradle(version: string): Promise<string> {
if (!versionInfo) {
throw new Error(`Gradle version ${version} does not exists`)
}
return provisionGradle(versionInfo)
return installGradleVersion(versionInfo)
}
async function gradleVersionDeclaration(url: string): Promise<GradleVersionInfo> {
@ -75,7 +98,7 @@ async function findGradleVersionDeclaration(version: string): Promise<GradleVers
})
}
async function provisionGradle(versionInfo: GradleVersionInfo): Promise<string> {
async function installGradleVersion(versionInfo: GradleVersionInfo): Promise<string> {
return core.group(`Provision Gradle ${versionInfo.version}`, async () => {
return locateGradleAndDownloadIfRequired(versionInfo)
})

16
src/repository-layout.ts Normal file
View File

@ -0,0 +1,16 @@
import * as params from './input-params'
import * as path from 'path'
export function workspaceDirectory(): string {
return process.env[`GITHUB_WORKSPACE`] || ''
}
export function buildRootDirectory(): string {
const baseDirectory = workspaceDirectory()
const buildRootDirectoryInput = params.getBuildRootDirectory()
const resolvedBuildRootDirectory =
buildRootDirectoryInput === ''
? path.resolve(baseDirectory)
: path.resolve(baseDirectory, buildRootDirectoryInput)
return resolvedBuildRootDirectory
}

View File

@ -4,6 +4,8 @@ import {SUMMARY_ENV_VAR} from '@actions/core/lib/summary'
import * as path from 'path'
import * as os from 'os'
import * as caches from './caches'
import * as layout from './repository-layout'
import * as params from './input-params'
import {logJobSummary, writeJobSummary} from './job-summary'
import {loadBuildResults} from './build-results'
@ -13,19 +15,9 @@ import {DaemonController} from './daemon-controller'
const GRADLE_SETUP_VAR = 'GRADLE_BUILD_ACTION_SETUP_COMPLETED'
const GRADLE_USER_HOME = 'GRADLE_USER_HOME'
const CACHE_LISTENER = 'CACHE_LISTENER'
const JOB_SUMMARY_ENABLED_PARAMETER = 'generate-job-summary'
function shouldGenerateJobSummary(): boolean {
// Check if Job Summary is supported on this platform
if (!process.env[SUMMARY_ENV_VAR]) {
return false
}
return core.getBooleanInput(JOB_SUMMARY_ENABLED_PARAMETER)
}
export async function setup(buildRootDirectory: string): Promise<void> {
const gradleUserHome = await determineGradleUserHome(buildRootDirectory)
export async function setup(): Promise<void> {
const gradleUserHome = await determineGradleUserHome()
// Bypass setup on all but first action step in workflow.
if (process.env[GRADLE_SETUP_VAR]) {
@ -68,9 +60,10 @@ export async function complete(): Promise<void> {
}
}
async function determineGradleUserHome(rootDir: string): Promise<string> {
async function determineGradleUserHome(): Promise<string> {
const customGradleUserHome = process.env['GRADLE_USER_HOME']
if (customGradleUserHome) {
const rootDir = layout.workspaceDirectory()
return path.resolve(rootDir, customGradleUserHome)
}
@ -93,3 +86,12 @@ async function determineUserHome(): Promise<string> {
core.debug(`Determined user.home from java -version output: '${userHome}'`)
return userHome
}
function shouldGenerateJobSummary(): boolean {
// Check if Job Summary is supported on this platform
if (!process.env[SUMMARY_ENV_VAR]) {
return false
}
return params.isJobSummaryEnabled()
}