Merge pull request #414 from gradle/dd/cache-cleanup-windows

Implement cache-cleanup on Windows
This commit is contained in:
Daz DeBoer 2022-08-26 09:04:41 -06:00 committed by GitHub
commit 356abb47e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 89 additions and 33 deletions

View file

@ -7,7 +7,7 @@ on:
type: string type: string
runner-os: runner-os:
type: string type: string
default: '["ubuntu-latest", "macos-latest"]' # Windows is not yet supported default: '["ubuntu-latest", "windows-latest", "macos-latest"]'
download-dist: download-dist:
type: boolean type: boolean
default: false default: false

43
dist/main/index.js vendored
View file

@ -65860,12 +65860,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
var __importDefault = (this && this.__importDefault) || function (mod) { var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CacheCleaner = void 0; exports.CacheCleaner = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514)); const exec = __importStar(__nccwpck_require__(1514));
const glob = __importStar(__nccwpck_require__(8090));
const fs_1 = __importDefault(__nccwpck_require__(7147)); const fs_1 = __importDefault(__nccwpck_require__(7147));
const path_1 = __importDefault(__nccwpck_require__(1017)); const path_1 = __importDefault(__nccwpck_require__(1017));
class CacheCleaner { class CacheCleaner {
@ -65896,12 +65905,35 @@ class CacheCleaner {
} }
ageAllFiles(fileName = '*') { ageAllFiles(fileName = '*') {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
yield exec.exec('find', [this.gradleUserHome, '-name', fileName, '-exec', 'touch', '-m', '-t', '197001010000', '{}', '+'], {}); core.debug(`Aging all files in Gradle User Homee with name ${fileName}`);
yield this.setUtimes(`${this.gradleUserHome}/**/${fileName}`, new Date(0));
}); });
} }
touchAllFiles(fileName = '*') { touchAllFiles(fileName = '*') {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
yield exec.exec('find', [this.gradleUserHome, '-name', fileName, '-exec', 'touch', '-m', '{}', '+'], {}); core.debug(`Touching all files in Gradle User Home with name ${fileName}`);
yield this.setUtimes(`${this.gradleUserHome}/**/${fileName}`, new Date());
});
}
setUtimes(pattern, timestamp) {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
const globber = yield glob.create(pattern, {
implicitDescendants: false
});
try {
for (var _b = __asyncValues(globber.globGenerator()), _c; _c = yield _b.next(), !_c.done;) {
const file = _c.value;
fs_1.default.utimesSync(file, timestamp, timestamp);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
}); });
} }
} }
@ -66494,12 +66526,7 @@ function isCacheDebuggingEnabled() {
} }
exports.isCacheDebuggingEnabled = isCacheDebuggingEnabled; exports.isCacheDebuggingEnabled = isCacheDebuggingEnabled;
function isCacheCleanupEnabled() { function isCacheCleanupEnabled() {
const userEnabled = core.getBooleanInput(CACHE_CLEANUP_ENABLED_PARAMETER); return core.getBooleanInput(CACHE_CLEANUP_ENABLED_PARAMETER);
if (userEnabled && process.platform === 'win32') {
core.warning('Cache cleanup is not yet supported on Windows');
return false;
}
return userEnabled;
} }
exports.isCacheCleanupEnabled = isCacheCleanupEnabled; exports.isCacheCleanupEnabled = isCacheCleanupEnabled;
class CacheKey { class CacheKey {

File diff suppressed because one or more lines are too long

43
dist/post/index.js vendored
View file

@ -64911,12 +64911,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
var __importDefault = (this && this.__importDefault) || function (mod) { var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CacheCleaner = void 0; exports.CacheCleaner = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514)); const exec = __importStar(__nccwpck_require__(1514));
const glob = __importStar(__nccwpck_require__(8090));
const fs_1 = __importDefault(__nccwpck_require__(7147)); const fs_1 = __importDefault(__nccwpck_require__(7147));
const path_1 = __importDefault(__nccwpck_require__(1017)); const path_1 = __importDefault(__nccwpck_require__(1017));
class CacheCleaner { class CacheCleaner {
@ -64947,12 +64956,35 @@ class CacheCleaner {
} }
ageAllFiles(fileName = '*') { ageAllFiles(fileName = '*') {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
yield exec.exec('find', [this.gradleUserHome, '-name', fileName, '-exec', 'touch', '-m', '-t', '197001010000', '{}', '+'], {}); core.debug(`Aging all files in Gradle User Homee with name ${fileName}`);
yield this.setUtimes(`${this.gradleUserHome}/**/${fileName}`, new Date(0));
}); });
} }
touchAllFiles(fileName = '*') { touchAllFiles(fileName = '*') {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
yield exec.exec('find', [this.gradleUserHome, '-name', fileName, '-exec', 'touch', '-m', '{}', '+'], {}); core.debug(`Touching all files in Gradle User Home with name ${fileName}`);
yield this.setUtimes(`${this.gradleUserHome}/**/${fileName}`, new Date());
});
}
setUtimes(pattern, timestamp) {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
const globber = yield glob.create(pattern, {
implicitDescendants: false
});
try {
for (var _b = __asyncValues(globber.globGenerator()), _c; _c = yield _b.next(), !_c.done;) {
const file = _c.value;
fs_1.default.utimesSync(file, timestamp, timestamp);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
}); });
} }
} }
@ -65545,12 +65577,7 @@ function isCacheDebuggingEnabled() {
} }
exports.isCacheDebuggingEnabled = isCacheDebuggingEnabled; exports.isCacheDebuggingEnabled = isCacheDebuggingEnabled;
function isCacheCleanupEnabled() { function isCacheCleanupEnabled() {
const userEnabled = core.getBooleanInput(CACHE_CLEANUP_ENABLED_PARAMETER); return core.getBooleanInput(CACHE_CLEANUP_ENABLED_PARAMETER);
if (userEnabled && process.platform === 'win32') {
core.warning('Cache cleanup is not yet supported on Windows');
return false;
}
return userEnabled;
} }
exports.isCacheCleanupEnabled = isCacheCleanupEnabled; exports.isCacheCleanupEnabled = isCacheCleanupEnabled;
class CacheKey { class CacheKey {

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,6 @@
import * as core from '@actions/core'
import * as exec from '@actions/exec' import * as exec from '@actions/exec'
import * as glob from '@actions/glob'
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
@ -46,14 +48,21 @@ export class CacheCleaner {
} }
private async ageAllFiles(fileName = '*'): Promise<void> { private async ageAllFiles(fileName = '*'): Promise<void> {
await exec.exec( core.debug(`Aging all files in Gradle User Homee with name ${fileName}`)
'find', await this.setUtimes(`${this.gradleUserHome}/**/${fileName}`, new Date(0))
[this.gradleUserHome, '-name', fileName, '-exec', 'touch', '-m', '-t', '197001010000', '{}', '+'],
{}
)
} }
private async touchAllFiles(fileName = '*'): Promise<void> { private async touchAllFiles(fileName = '*'): Promise<void> {
await exec.exec('find', [this.gradleUserHome, '-name', fileName, '-exec', 'touch', '-m', '{}', '+'], {}) core.debug(`Touching all files in Gradle User Home with name ${fileName}`)
await this.setUtimes(`${this.gradleUserHome}/**/${fileName}`, new Date())
}
private async setUtimes(pattern: string, timestamp: Date): Promise<void> {
const globber = await glob.create(pattern, {
implicitDescendants: false
})
for await (const file of globber.globGenerator()) {
fs.utimesSync(file, timestamp, timestamp)
}
} }
} }

View file

@ -48,14 +48,7 @@ export function isCacheDebuggingEnabled(): boolean {
} }
export function isCacheCleanupEnabled(): boolean { export function isCacheCleanupEnabled(): boolean {
const userEnabled = core.getBooleanInput(CACHE_CLEANUP_ENABLED_PARAMETER) return core.getBooleanInput(CACHE_CLEANUP_ENABLED_PARAMETER)
if (userEnabled && process.platform === 'win32') {
core.warning('Cache cleanup is not yet supported on Windows')
return false
}
return userEnabled
} }
/** /**