Merge pull request #344 from gradle/dd/issue341

Only stop Gradle Daemons when saving Gradle User Home state
This commit is contained in:
Daz DeBoer 2022-06-23 09:32:56 -06:00 committed by GitHub
commit bc41b8f654
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 414 additions and 244 deletions

View file

@ -205,7 +205,6 @@ Caching is enabled by default. You can disable caching for the action as follows
```yaml
cache-disabled: true
```
### Cache keys
Distributions downloaded to satisfy a `gradle-version` parameter are stored outside of Gradle User Home and cached separately. The cache key is unique to the downloaded distribution and will not change over time.
@ -234,6 +233,13 @@ You can configure read-only caching for the `gradle-build-action` as follows:
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/release' }}
```
### Stopping the Gradle daemon
By default, the action will stop all running Gradle daemons in the post-action step, prior to saving the Gradle User Home state.
This allows for any Gradle User Home cleanup to occur, and avoid file-locking issues on Windows.
If caching is unavailable or the cache is in read-only mode, the daemon will not be stopped and will continue running after the job is completed.
### Gradle User Home cache tuning
As well as any wrapper distributions, the action will attempt to save and restore the `caches` and `notifications` directories from Gradle User Home.

225
dist/main/index.js vendored
View file

@ -64874,6 +64874,54 @@ function wrappy (fn, cb) {
}).call(this);
/***/ }),
/***/ 3017:
/***/ (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.loadBuildResults = void 0;
const fs = __importStar(__nccwpck_require__(7147));
const path = __importStar(__nccwpck_require__(1017));
function loadBuildResults() {
const buildResultsDir = path.resolve(process.env['RUNNER_TEMP'], '.build-results');
if (!fs.existsSync(buildResultsDir)) {
return [];
}
return fs.readdirSync(buildResultsDir).map(file => {
const filePath = path.join(buildResultsDir, file);
const content = fs.readFileSync(filePath, 'utf8');
return JSON.parse(content);
});
}
exports.loadBuildResults = loadBuildResults;
/***/ }),
/***/ 7591:
@ -65133,7 +65181,7 @@ const core = __importStar(__nccwpck_require__(2186));
const glob = __importStar(__nccwpck_require__(8090));
const cache_base_1 = __nccwpck_require__(7591);
const cache_utils_1 = __nccwpck_require__(1678);
const job_summary_1 = __nccwpck_require__(7345);
const build_results_1 = __nccwpck_require__(3017);
const SKIP_RESTORE_VAR = 'GRADLE_BUILD_ACTION_SKIP_RESTORE';
class ExtractedCacheEntry {
constructor(artifactType, pattern, cacheKey) {
@ -65366,7 +65414,7 @@ class ConfigurationCacheEntryExtractor extends AbstractEntryExtractor {
});
}
getProjectRoots() {
const buildResults = (0, job_summary_1.loadBuildResults)();
const buildResults = (0, build_results_1.loadBuildResults)();
const projectRootDirs = buildResults.map(x => x.rootProjectDir);
return [...new Set(projectRootDirs)];
}
@ -65411,9 +65459,9 @@ const cache = __importStar(__nccwpck_require__(7799));
class CacheListener {
constructor() {
this.cacheEntries = [];
this.isCacheReadOnly = false;
this.isCacheWriteOnly = false;
this.isCacheDisabled = false;
this.cacheReadOnly = false;
this.cacheWriteOnly = false;
this.cacheDisabled = false;
}
get fullyRestored() {
return this.cacheEntries.every(x => !x.wasRequestedButNotRestored());
@ -65421,11 +65469,11 @@ class CacheListener {
get cacheStatus() {
if (!cache.isFeatureAvailable())
return 'not available';
if (this.isCacheDisabled)
if (this.cacheDisabled)
return 'disabled';
if (this.isCacheWriteOnly)
if (this.cacheWriteOnly)
return 'write-only';
if (this.isCacheReadOnly)
if (this.cacheReadOnly)
return 'read-only';
return 'enabled';
}
@ -65528,16 +65576,16 @@ function renderEntryDetails(listener) {
Requested Key : ${(_a = entry.requestedKey) !== null && _a !== void 0 ? _a : ''}
Restored Key : ${(_b = entry.restoredKey) !== null && _b !== void 0 ? _b : ''}
Size: ${formatSize(entry.restoredSize)}
${getRestoredMessage(entry, listener.isCacheWriteOnly)}
${getRestoredMessage(entry, listener.cacheWriteOnly)}
Saved Key : ${(_c = entry.savedKey) !== null && _c !== void 0 ? _c : ''}
Size: ${formatSize(entry.savedSize)}
${getSavedMessage(entry, listener.isCacheReadOnly)}
${getSavedMessage(entry, listener.cacheReadOnly)}
`;
})
.join('---\n');
}
function getRestoredMessage(entry, isCacheWriteOnly) {
if (isCacheWriteOnly) {
function getRestoredMessage(entry, cacheWriteOnly) {
if (cacheWriteOnly) {
return '(Entry not restored: cache is write-only)';
}
if (entry.restoredKey === undefined) {
@ -65548,12 +65596,12 @@ function getRestoredMessage(entry, isCacheWriteOnly) {
}
return '(Entry restored: partial match found)';
}
function getSavedMessage(entry, isCacheReadOnly) {
function getSavedMessage(entry, cacheReadOnly) {
if (entry.unsaved) {
return `(Entry not saved: ${entry.unsaved})`;
}
if (entry.savedKey === undefined) {
if (isCacheReadOnly) {
if (cacheReadOnly) {
return '(Entry not saved: cache is read-only)';
}
return '(Entry not saved: reason unknown)';
@ -65868,7 +65916,7 @@ function restore(gradleUserHome, cacheListener) {
if ((0, cache_utils_1.isCacheDisabled)()) {
core.info('Cache is disabled: will not restore state from previous builds.');
gradleStateCache.init();
cacheListener.isCacheDisabled = true;
cacheListener.cacheDisabled = true;
return;
}
if (gradleStateCache.cacheOutputExists()) {
@ -65880,7 +65928,7 @@ function restore(gradleUserHome, cacheListener) {
core.saveState(CACHE_RESTORED_VAR, true);
if ((0, cache_utils_1.isCacheWriteOnly)()) {
core.info('Cache is write-only: will not restore from cache.');
cacheListener.isCacheWriteOnly = true;
cacheListener.cacheWriteOnly = true;
return;
}
yield core.group('Restore Gradle state from cache', () => __awaiter(this, void 0, void 0, function* () {
@ -65889,33 +65937,101 @@ function restore(gradleUserHome, cacheListener) {
});
}
exports.restore = restore;
function save(gradleUserHome, cacheListener) {
function save(gradleUserHome, cacheListener, daemonController) {
return __awaiter(this, void 0, void 0, function* () {
if (!shouldSaveCaches()) {
if ((0, cache_utils_1.isCacheDisabled)()) {
core.info('Cache is disabled: will not save state for later builds.');
return;
}
if (!core.getState(CACHE_RESTORED_VAR)) {
core.info('Cache will not be saved: not restored in main action step.');
return;
}
if ((0, cache_utils_1.isCacheReadOnly)()) {
core.info('Cache is read-only: will not save state for use in subsequent builds.');
cacheListener.isCacheReadOnly = true;
cacheListener.cacheReadOnly = true;
return;
}
yield daemonController.stopAllDaemons();
yield core.group('Caching Gradle state', () => __awaiter(this, void 0, void 0, function* () {
return new cache_base_1.GradleStateCache(gradleUserHome).save(cacheListener);
}));
});
}
exports.save = save;
function shouldSaveCaches() {
if ((0, cache_utils_1.isCacheDisabled)()) {
core.info('Cache is disabled: will not save state for later builds.');
return false;
/***/ }),
/***/ 5146:
/***/ (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]; } };
}
if (!core.getState(CACHE_RESTORED_VAR)) {
core.info('Cache will not be saved: not restored in main action step.');
return false;
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;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DaemonController = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const fs = __importStar(__nccwpck_require__(7147));
const path = __importStar(__nccwpck_require__(1017));
class DaemonController {
constructor(buildResults) {
const allHomes = buildResults.map(buildResult => buildResult.gradleHomeDir);
this.gradleHomes = Array.from(new Set(allHomes));
}
return true;
stopAllDaemons() {
return __awaiter(this, void 0, void 0, function* () {
core.info('Stopping all Gradle daemons before saving Gradle User Home state');
const executions = [];
const args = ['--stop'];
for (const gradleHome of this.gradleHomes) {
const executable = path.resolve(gradleHome, 'bin', 'gradle');
if (!fs.existsSync(executable)) {
core.warning(`Gradle executable not found at ${executable}. Could not stop Gradle daemons.`);
continue;
}
core.info(`Stopping Gradle daemons for ${gradleHome}`);
executions.push(exec.exec(executable, args, {
ignoreReturnCode: true
}));
}
yield Promise.all(executions);
});
}
}
exports.DaemonController = DaemonController;
/***/ }),
@ -66088,14 +66204,9 @@ 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.loadBuildResults = exports.logJobSummary = exports.writeJobSummary = void 0;
exports.logJobSummary = exports.writeJobSummary = void 0;
const core = __importStar(__nccwpck_require__(2186));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const path_1 = __importDefault(__nccwpck_require__(1017));
const cache_reporting_1 = __nccwpck_require__(6674);
function writeJobSummary(buildResults, cacheListener) {
return __awaiter(this, void 0, void 0, function* () {
@ -66123,18 +66234,6 @@ function logJobSummary(buildResults, cacheListener) {
});
}
exports.logJobSummary = logJobSummary;
function loadBuildResults() {
const buildResultsDir = path_1.default.resolve(process.env['RUNNER_TEMP'], '.build-results');
if (!fs_1.default.existsSync(buildResultsDir)) {
return [];
}
return fs_1.default.readdirSync(buildResultsDir).map(file => {
const filePath = path_1.default.join(buildResultsDir, file);
const content = fs_1.default.readFileSync(filePath, 'utf8');
return JSON.parse(content);
});
}
exports.loadBuildResults = loadBuildResults;
function writeSummaryTable(results) {
core.summary.addHeading('Gradle Builds', 3);
core.summary.addRaw(`
@ -66533,12 +66632,13 @@ exports.complete = exports.setup = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const summary_1 = __nccwpck_require__(1327);
const fs = __importStar(__nccwpck_require__(7147));
const path = __importStar(__nccwpck_require__(1017));
const os = __importStar(__nccwpck_require__(2037));
const caches = __importStar(__nccwpck_require__(3800));
const cache_reporting_1 = __nccwpck_require__(6674);
const job_summary_1 = __nccwpck_require__(7345);
const build_results_1 = __nccwpck_require__(3017);
const cache_reporting_1 = __nccwpck_require__(6674);
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';
@ -66571,13 +66671,12 @@ function complete() {
core.info('Gradle setup post-action only performed for first gradle-build-action step in workflow.');
return;
}
const buildResults = (0, job_summary_1.loadBuildResults)();
core.info('Stopping all Gradle daemons');
yield stopAllDaemons(getUniqueGradleHomes(buildResults));
core.info('In final post-action step, saving state and writing summary');
const cacheListener = cache_reporting_1.CacheListener.rehydrate(core.getState(CACHE_LISTENER));
const buildResults = (0, build_results_1.loadBuildResults)();
const gradleUserHome = core.getState(GRADLE_USER_HOME);
yield caches.save(gradleUserHome, cacheListener);
const cacheListener = cache_reporting_1.CacheListener.rehydrate(core.getState(CACHE_LISTENER));
const daemonController = new daemon_controller_1.DaemonController(buildResults);
yield caches.save(gradleUserHome, cacheListener, daemonController);
if (shouldGenerateJobSummary()) {
yield (0, job_summary_1.writeJobSummary)(buildResults, cacheListener);
}
@ -66610,28 +66709,6 @@ function determineUserHome() {
return userHome;
});
}
function getUniqueGradleHomes(buildResults) {
const gradleHomes = buildResults.map(buildResult => buildResult.gradleHomeDir);
return Array.from(new Set(gradleHomes));
}
function stopAllDaemons(gradleHomes) {
return __awaiter(this, void 0, void 0, function* () {
const executions = [];
const args = ['--stop'];
for (const gradleHome of gradleHomes) {
const executable = path.resolve(gradleHome, 'bin', 'gradle');
if (!fs.existsSync(executable)) {
core.warning(`Gradle executable not found at ${executable}. Could not stop Gradle daemons.`);
continue;
}
core.info(`Stopping Gradle daemons in ${gradleHome}`);
executions.push(exec.exec(executable, args, {
ignoreReturnCode: true
}));
}
yield Promise.all(executions);
});
}
/***/ }),

File diff suppressed because one or more lines are too long

225
dist/post/index.js vendored
View file

@ -63925,6 +63925,54 @@ function wrappy (fn, cb) {
}).call(this);
/***/ }),
/***/ 3017:
/***/ (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.loadBuildResults = void 0;
const fs = __importStar(__nccwpck_require__(7147));
const path = __importStar(__nccwpck_require__(1017));
function loadBuildResults() {
const buildResultsDir = path.resolve(process.env['RUNNER_TEMP'], '.build-results');
if (!fs.existsSync(buildResultsDir)) {
return [];
}
return fs.readdirSync(buildResultsDir).map(file => {
const filePath = path.join(buildResultsDir, file);
const content = fs.readFileSync(filePath, 'utf8');
return JSON.parse(content);
});
}
exports.loadBuildResults = loadBuildResults;
/***/ }),
/***/ 7591:
@ -64184,7 +64232,7 @@ const core = __importStar(__nccwpck_require__(2186));
const glob = __importStar(__nccwpck_require__(8090));
const cache_base_1 = __nccwpck_require__(7591);
const cache_utils_1 = __nccwpck_require__(1678);
const job_summary_1 = __nccwpck_require__(7345);
const build_results_1 = __nccwpck_require__(3017);
const SKIP_RESTORE_VAR = 'GRADLE_BUILD_ACTION_SKIP_RESTORE';
class ExtractedCacheEntry {
constructor(artifactType, pattern, cacheKey) {
@ -64417,7 +64465,7 @@ class ConfigurationCacheEntryExtractor extends AbstractEntryExtractor {
});
}
getProjectRoots() {
const buildResults = (0, job_summary_1.loadBuildResults)();
const buildResults = (0, build_results_1.loadBuildResults)();
const projectRootDirs = buildResults.map(x => x.rootProjectDir);
return [...new Set(projectRootDirs)];
}
@ -64462,9 +64510,9 @@ const cache = __importStar(__nccwpck_require__(7799));
class CacheListener {
constructor() {
this.cacheEntries = [];
this.isCacheReadOnly = false;
this.isCacheWriteOnly = false;
this.isCacheDisabled = false;
this.cacheReadOnly = false;
this.cacheWriteOnly = false;
this.cacheDisabled = false;
}
get fullyRestored() {
return this.cacheEntries.every(x => !x.wasRequestedButNotRestored());
@ -64472,11 +64520,11 @@ class CacheListener {
get cacheStatus() {
if (!cache.isFeatureAvailable())
return 'not available';
if (this.isCacheDisabled)
if (this.cacheDisabled)
return 'disabled';
if (this.isCacheWriteOnly)
if (this.cacheWriteOnly)
return 'write-only';
if (this.isCacheReadOnly)
if (this.cacheReadOnly)
return 'read-only';
return 'enabled';
}
@ -64579,16 +64627,16 @@ function renderEntryDetails(listener) {
Requested Key : ${(_a = entry.requestedKey) !== null && _a !== void 0 ? _a : ''}
Restored Key : ${(_b = entry.restoredKey) !== null && _b !== void 0 ? _b : ''}
Size: ${formatSize(entry.restoredSize)}
${getRestoredMessage(entry, listener.isCacheWriteOnly)}
${getRestoredMessage(entry, listener.cacheWriteOnly)}
Saved Key : ${(_c = entry.savedKey) !== null && _c !== void 0 ? _c : ''}
Size: ${formatSize(entry.savedSize)}
${getSavedMessage(entry, listener.isCacheReadOnly)}
${getSavedMessage(entry, listener.cacheReadOnly)}
`;
})
.join('---\n');
}
function getRestoredMessage(entry, isCacheWriteOnly) {
if (isCacheWriteOnly) {
function getRestoredMessage(entry, cacheWriteOnly) {
if (cacheWriteOnly) {
return '(Entry not restored: cache is write-only)';
}
if (entry.restoredKey === undefined) {
@ -64599,12 +64647,12 @@ function getRestoredMessage(entry, isCacheWriteOnly) {
}
return '(Entry restored: partial match found)';
}
function getSavedMessage(entry, isCacheReadOnly) {
function getSavedMessage(entry, cacheReadOnly) {
if (entry.unsaved) {
return `(Entry not saved: ${entry.unsaved})`;
}
if (entry.savedKey === undefined) {
if (isCacheReadOnly) {
if (cacheReadOnly) {
return '(Entry not saved: cache is read-only)';
}
return '(Entry not saved: reason unknown)';
@ -64919,7 +64967,7 @@ function restore(gradleUserHome, cacheListener) {
if ((0, cache_utils_1.isCacheDisabled)()) {
core.info('Cache is disabled: will not restore state from previous builds.');
gradleStateCache.init();
cacheListener.isCacheDisabled = true;
cacheListener.cacheDisabled = true;
return;
}
if (gradleStateCache.cacheOutputExists()) {
@ -64931,7 +64979,7 @@ function restore(gradleUserHome, cacheListener) {
core.saveState(CACHE_RESTORED_VAR, true);
if ((0, cache_utils_1.isCacheWriteOnly)()) {
core.info('Cache is write-only: will not restore from cache.');
cacheListener.isCacheWriteOnly = true;
cacheListener.cacheWriteOnly = true;
return;
}
yield core.group('Restore Gradle state from cache', () => __awaiter(this, void 0, void 0, function* () {
@ -64940,33 +64988,101 @@ function restore(gradleUserHome, cacheListener) {
});
}
exports.restore = restore;
function save(gradleUserHome, cacheListener) {
function save(gradleUserHome, cacheListener, daemonController) {
return __awaiter(this, void 0, void 0, function* () {
if (!shouldSaveCaches()) {
if ((0, cache_utils_1.isCacheDisabled)()) {
core.info('Cache is disabled: will not save state for later builds.');
return;
}
if (!core.getState(CACHE_RESTORED_VAR)) {
core.info('Cache will not be saved: not restored in main action step.');
return;
}
if ((0, cache_utils_1.isCacheReadOnly)()) {
core.info('Cache is read-only: will not save state for use in subsequent builds.');
cacheListener.isCacheReadOnly = true;
cacheListener.cacheReadOnly = true;
return;
}
yield daemonController.stopAllDaemons();
yield core.group('Caching Gradle state', () => __awaiter(this, void 0, void 0, function* () {
return new cache_base_1.GradleStateCache(gradleUserHome).save(cacheListener);
}));
});
}
exports.save = save;
function shouldSaveCaches() {
if ((0, cache_utils_1.isCacheDisabled)()) {
core.info('Cache is disabled: will not save state for later builds.');
return false;
/***/ }),
/***/ 5146:
/***/ (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]; } };
}
if (!core.getState(CACHE_RESTORED_VAR)) {
core.info('Cache will not be saved: not restored in main action step.');
return false;
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;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DaemonController = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const fs = __importStar(__nccwpck_require__(7147));
const path = __importStar(__nccwpck_require__(1017));
class DaemonController {
constructor(buildResults) {
const allHomes = buildResults.map(buildResult => buildResult.gradleHomeDir);
this.gradleHomes = Array.from(new Set(allHomes));
}
return true;
stopAllDaemons() {
return __awaiter(this, void 0, void 0, function* () {
core.info('Stopping all Gradle daemons before saving Gradle User Home state');
const executions = [];
const args = ['--stop'];
for (const gradleHome of this.gradleHomes) {
const executable = path.resolve(gradleHome, 'bin', 'gradle');
if (!fs.existsSync(executable)) {
core.warning(`Gradle executable not found at ${executable}. Could not stop Gradle daemons.`);
continue;
}
core.info(`Stopping Gradle daemons for ${gradleHome}`);
executions.push(exec.exec(executable, args, {
ignoreReturnCode: true
}));
}
yield Promise.all(executions);
});
}
}
exports.DaemonController = DaemonController;
/***/ }),
@ -65008,14 +65124,9 @@ 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.loadBuildResults = exports.logJobSummary = exports.writeJobSummary = void 0;
exports.logJobSummary = exports.writeJobSummary = void 0;
const core = __importStar(__nccwpck_require__(2186));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const path_1 = __importDefault(__nccwpck_require__(1017));
const cache_reporting_1 = __nccwpck_require__(6674);
function writeJobSummary(buildResults, cacheListener) {
return __awaiter(this, void 0, void 0, function* () {
@ -65043,18 +65154,6 @@ function logJobSummary(buildResults, cacheListener) {
});
}
exports.logJobSummary = logJobSummary;
function loadBuildResults() {
const buildResultsDir = path_1.default.resolve(process.env['RUNNER_TEMP'], '.build-results');
if (!fs_1.default.existsSync(buildResultsDir)) {
return [];
}
return fs_1.default.readdirSync(buildResultsDir).map(file => {
const filePath = path_1.default.join(buildResultsDir, file);
const content = fs_1.default.readFileSync(filePath, 'utf8');
return JSON.parse(content);
});
}
exports.loadBuildResults = loadBuildResults;
function writeSummaryTable(results) {
core.summary.addHeading('Gradle Builds', 3);
core.summary.addRaw(`
@ -65217,12 +65316,13 @@ exports.complete = exports.setup = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const summary_1 = __nccwpck_require__(1327);
const fs = __importStar(__nccwpck_require__(7147));
const path = __importStar(__nccwpck_require__(1017));
const os = __importStar(__nccwpck_require__(2037));
const caches = __importStar(__nccwpck_require__(3800));
const cache_reporting_1 = __nccwpck_require__(6674);
const job_summary_1 = __nccwpck_require__(7345);
const build_results_1 = __nccwpck_require__(3017);
const cache_reporting_1 = __nccwpck_require__(6674);
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';
@ -65255,13 +65355,12 @@ function complete() {
core.info('Gradle setup post-action only performed for first gradle-build-action step in workflow.');
return;
}
const buildResults = (0, job_summary_1.loadBuildResults)();
core.info('Stopping all Gradle daemons');
yield stopAllDaemons(getUniqueGradleHomes(buildResults));
core.info('In final post-action step, saving state and writing summary');
const cacheListener = cache_reporting_1.CacheListener.rehydrate(core.getState(CACHE_LISTENER));
const buildResults = (0, build_results_1.loadBuildResults)();
const gradleUserHome = core.getState(GRADLE_USER_HOME);
yield caches.save(gradleUserHome, cacheListener);
const cacheListener = cache_reporting_1.CacheListener.rehydrate(core.getState(CACHE_LISTENER));
const daemonController = new daemon_controller_1.DaemonController(buildResults);
yield caches.save(gradleUserHome, cacheListener, daemonController);
if (shouldGenerateJobSummary()) {
yield (0, job_summary_1.writeJobSummary)(buildResults, cacheListener);
}
@ -65294,28 +65393,6 @@ function determineUserHome() {
return userHome;
});
}
function getUniqueGradleHomes(buildResults) {
const gradleHomes = buildResults.map(buildResult => buildResult.gradleHomeDir);
return Array.from(new Set(gradleHomes));
}
function stopAllDaemons(gradleHomes) {
return __awaiter(this, void 0, void 0, function* () {
const executions = [];
const args = ['--stop'];
for (const gradleHome of gradleHomes) {
const executable = path.resolve(gradleHome, 'bin', 'gradle');
if (!fs.existsSync(executable)) {
core.warning(`Gradle executable not found at ${executable}. Could not stop Gradle daemons.`);
continue;
}
core.info(`Stopping Gradle daemons in ${gradleHome}`);
executions.push(exec.exec(executable, args, {
ignoreReturnCode: true
}));
}
yield Promise.all(executions);
});
}
/***/ }),

File diff suppressed because one or more lines are too long

27
src/build-results.ts Normal file
View file

@ -0,0 +1,27 @@
import * as fs from 'fs'
import * as path from 'path'
export interface BuildResult {
get rootProjectName(): string
get rootProjectDir(): string
get requestedTasks(): string
get gradleVersion(): string
get gradleHomeDir(): string
get buildFailed(): boolean
get buildScanUri(): string
get buildScanFailed(): boolean
}
export function loadBuildResults(): BuildResult[] {
const buildResultsDir = path.resolve(process.env['RUNNER_TEMP']!, '.build-results')
if (!fs.existsSync(buildResultsDir)) {
return []
}
return fs.readdirSync(buildResultsDir).map(file => {
// Every file in the .build-results dir should be a BuildResults JSON
const filePath = path.join(buildResultsDir, file)
const content = fs.readFileSync(filePath, 'utf8')
return JSON.parse(content) as BuildResult
})
}

View file

@ -14,7 +14,7 @@ import {
saveCache,
tryDelete
} from './cache-utils'
import {loadBuildResults} from './job-summary'
import {loadBuildResults} from './build-results'
const SKIP_RESTORE_VAR = 'GRADLE_BUILD_ACTION_SKIP_RESTORE'

View file

@ -7,9 +7,9 @@ import * as cache from '@actions/cache'
*/
export class CacheListener {
cacheEntries: CacheEntryListener[] = []
isCacheReadOnly = false
isCacheWriteOnly = false
isCacheDisabled = false
cacheReadOnly = false
cacheWriteOnly = false
cacheDisabled = false
get fullyRestored(): boolean {
return this.cacheEntries.every(x => !x.wasRequestedButNotRestored())
@ -17,9 +17,9 @@ export class CacheListener {
get cacheStatus(): string {
if (!cache.isFeatureAvailable()) return 'not available'
if (this.isCacheDisabled) return 'disabled'
if (this.isCacheWriteOnly) return 'write-only'
if (this.isCacheReadOnly) return 'read-only'
if (this.cacheDisabled) return 'disabled'
if (this.cacheWriteOnly) return 'write-only'
if (this.cacheReadOnly) return 'read-only'
return 'enabled'
}
@ -156,17 +156,17 @@ function renderEntryDetails(listener: CacheListener): string {
Requested Key : ${entry.requestedKey ?? ''}
Restored Key : ${entry.restoredKey ?? ''}
Size: ${formatSize(entry.restoredSize)}
${getRestoredMessage(entry, listener.isCacheWriteOnly)}
${getRestoredMessage(entry, listener.cacheWriteOnly)}
Saved Key : ${entry.savedKey ?? ''}
Size: ${formatSize(entry.savedSize)}
${getSavedMessage(entry, listener.isCacheReadOnly)}
${getSavedMessage(entry, listener.cacheReadOnly)}
`
)
.join('---\n')
}
function getRestoredMessage(entry: CacheEntryListener, isCacheWriteOnly: boolean): string {
if (isCacheWriteOnly) {
function getRestoredMessage(entry: CacheEntryListener, cacheWriteOnly: boolean): string {
if (cacheWriteOnly) {
return '(Entry not restored: cache is write-only)'
}
if (entry.restoredKey === undefined) {
@ -178,12 +178,12 @@ function getRestoredMessage(entry: CacheEntryListener, isCacheWriteOnly: boolean
return '(Entry restored: partial match found)'
}
function getSavedMessage(entry: CacheEntryListener, isCacheReadOnly: boolean): string {
function getSavedMessage(entry: CacheEntryListener, cacheReadOnly: boolean): string {
if (entry.unsaved) {
return `(Entry not saved: ${entry.unsaved})`
}
if (entry.savedKey === undefined) {
if (isCacheReadOnly) {
if (cacheReadOnly) {
return '(Entry not saved: cache is read-only)'
}
return '(Entry not saved: reason unknown)'

View file

@ -1,6 +1,7 @@
import * as core from '@actions/core'
import {isCacheDisabled, isCacheReadOnly, isCacheWriteOnly} from './cache-utils'
import {CacheListener} from './cache-reporting'
import {DaemonController} from './daemon-controller'
import {GradleStateCache} from './cache-base'
const CACHE_RESTORED_VAR = 'GRADLE_BUILD_ACTION_CACHE_RESTORED'
@ -19,7 +20,7 @@ export async function restore(gradleUserHome: string, cacheListener: CacheListen
core.info('Cache is disabled: will not restore state from previous builds.')
// Initialize the Gradle User Home even when caching is disabled.
gradleStateCache.init()
cacheListener.isCacheDisabled = true
cacheListener.cacheDisabled = true
return
}
@ -36,7 +37,7 @@ export async function restore(gradleUserHome: string, cacheListener: CacheListen
if (isCacheWriteOnly()) {
core.info('Cache is write-only: will not restore from cache.')
cacheListener.isCacheWriteOnly = true
cacheListener.cacheWriteOnly = true
return
}
@ -45,32 +46,30 @@ export async function restore(gradleUserHome: string, cacheListener: CacheListen
})
}
export async function save(gradleUserHome: string, cacheListener: CacheListener): Promise<void> {
if (!shouldSaveCaches()) {
export async function save(
gradleUserHome: string,
cacheListener: CacheListener,
daemonController: DaemonController
): Promise<void> {
if (isCacheDisabled()) {
core.info('Cache is disabled: will not save state for later builds.')
return
}
if (!core.getState(CACHE_RESTORED_VAR)) {
core.info('Cache will not be saved: not restored in main action step.')
return
}
if (isCacheReadOnly()) {
core.info('Cache is read-only: will not save state for use in subsequent builds.')
cacheListener.isCacheReadOnly = true
cacheListener.cacheReadOnly = true
return
}
await daemonController.stopAllDaemons()
await core.group('Caching Gradle state', async () => {
return new GradleStateCache(gradleUserHome).save(cacheListener)
})
}
function shouldSaveCaches(): boolean {
if (isCacheDisabled()) {
core.info('Cache is disabled: will not save state for later builds.')
return false
}
if (!core.getState(CACHE_RESTORED_VAR)) {
core.info('Cache will not be saved: not restored in main action step.')
return false
}
return true
}

36
src/daemon-controller.ts Normal file
View file

@ -0,0 +1,36 @@
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as fs from 'fs'
import * as path from 'path'
import {BuildResult} from './build-results'
export class DaemonController {
private readonly gradleHomes
constructor(buildResults: BuildResult[]) {
const allHomes = buildResults.map(buildResult => buildResult.gradleHomeDir)
this.gradleHomes = Array.from(new Set(allHomes))
}
async stopAllDaemons(): Promise<void> {
core.info('Stopping all Gradle daemons before saving Gradle User Home state')
const executions: Promise<number>[] = []
const args = ['--stop']
for (const gradleHome of this.gradleHomes) {
const executable = path.resolve(gradleHome, 'bin', 'gradle')
if (!fs.existsSync(executable)) {
core.warning(`Gradle executable not found at ${executable}. Could not stop Gradle daemons.`)
continue
}
core.info(`Stopping Gradle daemons for ${gradleHome}`)
executions.push(
exec.exec(executable, args, {
ignoreReturnCode: true
})
)
}
await Promise.all(executions)
}
}

View file

@ -1,19 +1,7 @@
import * as core from '@actions/core'
import fs from 'fs'
import path from 'path'
import {BuildResult} from './build-results'
import {writeCachingReport, CacheListener, logCachingReport} from './cache-reporting'
export interface BuildResult {
get rootProjectName(): string
get rootProjectDir(): string
get requestedTasks(): string
get gradleVersion(): string
get gradleHomeDir(): string
get buildFailed(): boolean
get buildScanUri(): string
get buildScanFailed(): boolean
}
export async function writeJobSummary(buildResults: BuildResult[], cacheListener: CacheListener): Promise<void> {
core.info('Writing job summary')
@ -38,20 +26,6 @@ export async function logJobSummary(buildResults: BuildResult[], cacheListener:
logCachingReport(cacheListener)
}
export function loadBuildResults(): BuildResult[] {
const buildResultsDir = path.resolve(process.env['RUNNER_TEMP']!, '.build-results')
if (!fs.existsSync(buildResultsDir)) {
return []
}
return fs.readdirSync(buildResultsDir).map(file => {
// Every file in the .build-results dir should be a BuildResults JSON
const filePath = path.join(buildResultsDir, file)
const content = fs.readFileSync(filePath, 'utf8')
return JSON.parse(content) as BuildResult
})
}
function writeSummaryTable(results: BuildResult[]): void {
core.summary.addHeading('Gradle Builds', 3)

View file

@ -1,13 +1,14 @@
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import {SUMMARY_ENV_VAR} from '@actions/core/lib/summary'
import * as fs from 'fs'
import * as path from 'path'
import * as os from 'os'
import * as caches from './caches'
import {logJobSummary, writeJobSummary} from './job-summary'
import {loadBuildResults} from './build-results'
import {CacheListener} from './cache-reporting'
import {BuildResult, loadBuildResults, logJobSummary, writeJobSummary} from './job-summary'
import {DaemonController} from './daemon-controller'
const GRADLE_SETUP_VAR = 'GRADLE_BUILD_ACTION_SETUP_COMPLETED'
const GRADLE_USER_HOME = 'GRADLE_USER_HOME'
@ -50,17 +51,15 @@ export async function complete(): Promise<void> {
core.info('Gradle setup post-action only performed for first gradle-build-action step in workflow.')
return
}
core.info('In final post-action step, saving state and writing summary')
const buildResults = loadBuildResults()
core.info('Stopping all Gradle daemons')
await stopAllDaemons(getUniqueGradleHomes(buildResults))
core.info('In final post-action step, saving state and writing summary')
const cacheListener: CacheListener = CacheListener.rehydrate(core.getState(CACHE_LISTENER))
const gradleUserHome = core.getState(GRADLE_USER_HOME)
await caches.save(gradleUserHome, cacheListener)
const cacheListener: CacheListener = CacheListener.rehydrate(core.getState(CACHE_LISTENER))
const daemonController = new DaemonController(buildResults)
await caches.save(gradleUserHome, cacheListener, daemonController)
if (shouldGenerateJobSummary()) {
await writeJobSummary(buildResults, cacheListener)
@ -94,28 +93,3 @@ async function determineUserHome(): Promise<string> {
core.debug(`Determined user.home from java -version output: '${userHome}'`)
return userHome
}
function getUniqueGradleHomes(buildResults: BuildResult[]): string[] {
const gradleHomes = buildResults.map(buildResult => buildResult.gradleHomeDir)
return Array.from(new Set(gradleHomes))
}
async function stopAllDaemons(gradleHomes: string[]): Promise<void> {
const executions: Promise<number>[] = []
const args = ['--stop']
for (const gradleHome of gradleHomes) {
const executable = path.resolve(gradleHome, 'bin', 'gradle')
if (!fs.existsSync(executable)) {
core.warning(`Gradle executable not found at ${executable}. Could not stop Gradle daemons.`)
continue
}
core.info(`Stopping Gradle daemons in ${gradleHome}`)
executions.push(
exec.exec(executable, args, {
ignoreReturnCode: true
})
)
}
await Promise.all(executions)
}