mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-04-06 13:24:13 +02:00
Support use of passed Gradle executable
Signed-off-by: Anders Fischer-Nielsen <andersfischern@me.com>
This commit is contained in:
parent
9b0ff91415
commit
bf387dd8b2
6 changed files with 58 additions and 14 deletions
19
dist/main/index.js
vendored
19
dist/main/index.js
vendored
|
@ -65878,10 +65878,11 @@ const glob = __importStar(__nccwpck_require__(8090));
|
|||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||
class CacheCleaner {
|
||||
constructor(gradleUserHome, tmpDir, gradleVersion) {
|
||||
constructor(gradleUserHome, tmpDir, gradleVersion, gradleExecutable) {
|
||||
this.gradleUserHome = gradleUserHome;
|
||||
this.tmpDir = tmpDir;
|
||||
this.gradleVersion = gradleVersion;
|
||||
this.gradleExecutable = gradleExecutable;
|
||||
}
|
||||
prepare() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
|
@ -65899,12 +65900,19 @@ class CacheCleaner {
|
|||
fs_1.default.mkdirSync(cleanupProjectDir, { recursive: true });
|
||||
fs_1.default.writeFileSync(path_1.default.resolve(cleanupProjectDir, 'settings.gradle'), 'rootProject.name = "dummy-cleanup-project"');
|
||||
fs_1.default.writeFileSync(path_1.default.resolve(cleanupProjectDir, 'build.gradle'), 'task("noop") {}');
|
||||
const gradleExecutable = this.gradleVersion === 'wrapper' ? './gradlew' : 'gradle';
|
||||
const gradleExecutable = this.determineGradleExecutable(this.gradleExecutable, this.gradleVersion);
|
||||
yield exec.exec(`${gradleExecutable} -g ${this.gradleUserHome} --no-daemon --build-cache --no-scan --quiet noop`, [], {
|
||||
cwd: cleanupProjectDir
|
||||
});
|
||||
});
|
||||
}
|
||||
determineGradleExecutable(gradleExecutable, gradleVersion) {
|
||||
if (gradleExecutable)
|
||||
return gradleExecutable;
|
||||
if (gradleVersion === 'wrapper')
|
||||
return './gradlew';
|
||||
return 'gradle';
|
||||
}
|
||||
ageAllFiles(fileName = '*') {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.debug(`Aging all files in Gradle User Homee with name ${fileName}`);
|
||||
|
@ -66740,6 +66748,7 @@ const cache_base_1 = __nccwpck_require__(7591);
|
|||
const cache_cleaner_1 = __nccwpck_require__(57);
|
||||
const CACHE_RESTORED_VAR = 'GRADLE_BUILD_ACTION_CACHE_RESTORED';
|
||||
const GRADLE_VERSION = 'GRADLE_VERSION';
|
||||
const GRADLE_EXECUTABLE = 'GRADLE_EXECUTABLE';
|
||||
function restore(gradleUserHome, cacheListener) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (process.env[CACHE_RESTORED_VAR]) {
|
||||
|
@ -66772,7 +66781,8 @@ function restore(gradleUserHome, cacheListener) {
|
|||
if ((0, cache_utils_1.isCacheCleanupEnabled)() && !(0, cache_utils_1.isCacheReadOnly)()) {
|
||||
core.info('Preparing cache for cleanup.');
|
||||
const gradleVersion = core.getState(GRADLE_VERSION);
|
||||
const cacheCleaner = new cache_cleaner_1.CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP'], gradleVersion);
|
||||
const gradleExecutable = core.getState(GRADLE_EXECUTABLE);
|
||||
const cacheCleaner = new cache_cleaner_1.CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP'], gradleVersion, gradleExecutable);
|
||||
yield cacheCleaner.prepare();
|
||||
}
|
||||
});
|
||||
|
@ -66797,7 +66807,8 @@ function save(gradleUserHome, cacheListener, daemonController) {
|
|||
if ((0, cache_utils_1.isCacheCleanupEnabled)()) {
|
||||
core.info('Forcing cache cleanup.');
|
||||
const gradleVersion = core.getState(GRADLE_VERSION);
|
||||
const cacheCleaner = new cache_cleaner_1.CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP'], gradleVersion);
|
||||
const gradleExecutable = core.getState(GRADLE_EXECUTABLE);
|
||||
const cacheCleaner = new cache_cleaner_1.CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP'], gradleVersion, gradleExecutable);
|
||||
yield cacheCleaner.forceCleanup();
|
||||
}
|
||||
yield core.group('Caching Gradle state', () => __awaiter(this, void 0, void 0, function* () {
|
||||
|
|
2
dist/main/index.js.map
vendored
2
dist/main/index.js.map
vendored
File diff suppressed because one or more lines are too long
19
dist/post/index.js
vendored
19
dist/post/index.js
vendored
|
@ -64929,10 +64929,11 @@ const glob = __importStar(__nccwpck_require__(8090));
|
|||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||
class CacheCleaner {
|
||||
constructor(gradleUserHome, tmpDir, gradleVersion) {
|
||||
constructor(gradleUserHome, tmpDir, gradleVersion, gradleExecutable) {
|
||||
this.gradleUserHome = gradleUserHome;
|
||||
this.tmpDir = tmpDir;
|
||||
this.gradleVersion = gradleVersion;
|
||||
this.gradleExecutable = gradleExecutable;
|
||||
}
|
||||
prepare() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
|
@ -64950,12 +64951,19 @@ class CacheCleaner {
|
|||
fs_1.default.mkdirSync(cleanupProjectDir, { recursive: true });
|
||||
fs_1.default.writeFileSync(path_1.default.resolve(cleanupProjectDir, 'settings.gradle'), 'rootProject.name = "dummy-cleanup-project"');
|
||||
fs_1.default.writeFileSync(path_1.default.resolve(cleanupProjectDir, 'build.gradle'), 'task("noop") {}');
|
||||
const gradleExecutable = this.gradleVersion === 'wrapper' ? './gradlew' : 'gradle';
|
||||
const gradleExecutable = this.determineGradleExecutable(this.gradleExecutable, this.gradleVersion);
|
||||
yield exec.exec(`${gradleExecutable} -g ${this.gradleUserHome} --no-daemon --build-cache --no-scan --quiet noop`, [], {
|
||||
cwd: cleanupProjectDir
|
||||
});
|
||||
});
|
||||
}
|
||||
determineGradleExecutable(gradleExecutable, gradleVersion) {
|
||||
if (gradleExecutable)
|
||||
return gradleExecutable;
|
||||
if (gradleVersion === 'wrapper')
|
||||
return './gradlew';
|
||||
return 'gradle';
|
||||
}
|
||||
ageAllFiles(fileName = '*') {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.debug(`Aging all files in Gradle User Homee with name ${fileName}`);
|
||||
|
@ -65791,6 +65799,7 @@ const cache_base_1 = __nccwpck_require__(7591);
|
|||
const cache_cleaner_1 = __nccwpck_require__(57);
|
||||
const CACHE_RESTORED_VAR = 'GRADLE_BUILD_ACTION_CACHE_RESTORED';
|
||||
const GRADLE_VERSION = 'GRADLE_VERSION';
|
||||
const GRADLE_EXECUTABLE = 'GRADLE_EXECUTABLE';
|
||||
function restore(gradleUserHome, cacheListener) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (process.env[CACHE_RESTORED_VAR]) {
|
||||
|
@ -65823,7 +65832,8 @@ function restore(gradleUserHome, cacheListener) {
|
|||
if ((0, cache_utils_1.isCacheCleanupEnabled)() && !(0, cache_utils_1.isCacheReadOnly)()) {
|
||||
core.info('Preparing cache for cleanup.');
|
||||
const gradleVersion = core.getState(GRADLE_VERSION);
|
||||
const cacheCleaner = new cache_cleaner_1.CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP'], gradleVersion);
|
||||
const gradleExecutable = core.getState(GRADLE_EXECUTABLE);
|
||||
const cacheCleaner = new cache_cleaner_1.CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP'], gradleVersion, gradleExecutable);
|
||||
yield cacheCleaner.prepare();
|
||||
}
|
||||
});
|
||||
|
@ -65848,7 +65858,8 @@ function save(gradleUserHome, cacheListener, daemonController) {
|
|||
if ((0, cache_utils_1.isCacheCleanupEnabled)()) {
|
||||
core.info('Forcing cache cleanup.');
|
||||
const gradleVersion = core.getState(GRADLE_VERSION);
|
||||
const cacheCleaner = new cache_cleaner_1.CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP'], gradleVersion);
|
||||
const gradleExecutable = core.getState(GRADLE_EXECUTABLE);
|
||||
const cacheCleaner = new cache_cleaner_1.CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP'], gradleVersion, gradleExecutable);
|
||||
yield cacheCleaner.forceCleanup();
|
||||
}
|
||||
yield core.group('Caching Gradle state', () => __awaiter(this, void 0, void 0, function* () {
|
||||
|
|
2
dist/post/index.js.map
vendored
2
dist/post/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -8,11 +8,13 @@ export class CacheCleaner {
|
|||
private readonly gradleUserHome: string
|
||||
private readonly tmpDir: string
|
||||
private readonly gradleVersion?: string
|
||||
private readonly gradleExecutable?: string
|
||||
|
||||
constructor(gradleUserHome: string, tmpDir: string, gradleVersion?: string) {
|
||||
constructor(gradleUserHome: string, tmpDir: string, gradleVersion?: string, gradleExecutable?: string) {
|
||||
this.gradleUserHome = gradleUserHome
|
||||
this.tmpDir = tmpDir
|
||||
this.gradleVersion = gradleVersion
|
||||
this.gradleExecutable = gradleExecutable
|
||||
}
|
||||
|
||||
async prepare(): Promise<void> {
|
||||
|
@ -44,7 +46,7 @@ export class CacheCleaner {
|
|||
)
|
||||
fs.writeFileSync(path.resolve(cleanupProjectDir, 'build.gradle'), 'task("noop") {}')
|
||||
|
||||
const gradleExecutable = this.gradleVersion === 'wrapper' ? './gradlew' : 'gradle'
|
||||
const gradleExecutable = this.determineGradleExecutable(this.gradleExecutable, this.gradleVersion)
|
||||
|
||||
await exec.exec(
|
||||
`${gradleExecutable} -g ${this.gradleUserHome} --no-daemon --build-cache --no-scan --quiet noop`,
|
||||
|
@ -55,6 +57,13 @@ export class CacheCleaner {
|
|||
)
|
||||
}
|
||||
|
||||
private determineGradleExecutable(gradleExecutable?: string, gradleVersion?: string): string {
|
||||
if (gradleExecutable) return gradleExecutable
|
||||
if (gradleVersion === 'wrapper') return './gradlew'
|
||||
|
||||
return 'gradle'
|
||||
}
|
||||
|
||||
private async ageAllFiles(fileName = '*'): Promise<void> {
|
||||
core.debug(`Aging all files in Gradle User Homee with name ${fileName}`)
|
||||
await this.setUtimes(`${this.gradleUserHome}/**/${fileName}`, new Date(0))
|
||||
|
|
|
@ -7,6 +7,7 @@ import {CacheCleaner} from './cache-cleaner'
|
|||
|
||||
const CACHE_RESTORED_VAR = 'GRADLE_BUILD_ACTION_CACHE_RESTORED'
|
||||
const GRADLE_VERSION = 'GRADLE_VERSION'
|
||||
const GRADLE_EXECUTABLE = 'GRADLE_EXECUTABLE'
|
||||
|
||||
export async function restore(gradleUserHome: string, cacheListener: CacheListener): Promise<void> {
|
||||
// Bypass restore cache on all but first action step in workflow.
|
||||
|
@ -50,7 +51,13 @@ export async function restore(gradleUserHome: string, cacheListener: CacheListen
|
|||
if (isCacheCleanupEnabled() && !isCacheReadOnly()) {
|
||||
core.info('Preparing cache for cleanup.')
|
||||
const gradleVersion = core.getState(GRADLE_VERSION)
|
||||
const cacheCleaner = new CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP']!, gradleVersion)
|
||||
const gradleExecutable = core.getState(GRADLE_EXECUTABLE)
|
||||
const cacheCleaner = new CacheCleaner(
|
||||
gradleUserHome,
|
||||
process.env['RUNNER_TEMP']!,
|
||||
gradleVersion,
|
||||
gradleExecutable
|
||||
)
|
||||
await cacheCleaner.prepare()
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +88,13 @@ export async function save(
|
|||
if (isCacheCleanupEnabled()) {
|
||||
core.info('Forcing cache cleanup.')
|
||||
const gradleVersion = core.getState(GRADLE_VERSION)
|
||||
const cacheCleaner = new CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP']!, gradleVersion)
|
||||
const gradleExecutable = core.getState(GRADLE_EXECUTABLE)
|
||||
const cacheCleaner = new CacheCleaner(
|
||||
gradleUserHome,
|
||||
process.env['RUNNER_TEMP']!,
|
||||
gradleVersion,
|
||||
gradleExecutable
|
||||
)
|
||||
await cacheCleaner.forceCleanup()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue