From 9d3e69673844ecacefdb68f06c1d217b5568017a Mon Sep 17 00:00:00 2001 From: Ger Teck Date: Fri, 5 Jul 2024 09:36:53 +0800 Subject: [PATCH 1/2] Configure global cache --- packages/core/src/Site/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/core/src/Site/index.ts b/packages/core/src/Site/index.ts index 0918e75fb..b26bd81ad 100644 --- a/packages/core/src/Site/index.ts +++ b/packages/core/src/Site/index.ts @@ -1382,6 +1382,11 @@ export class Site { }; options.message = options.message.concat(' [skip ci]'); + // Globally set cache folder to cwd/.cache/gh-pages. + if (!process.env.CACHE_DIR || ['true', 'false', '1', '0'].includes(process.env.CACHE_DIR)) { + process.env.CACHE_DIR = path.join(process.cwd(), '.cache', 'gh-pages'); + } + if (ciTokenVar) { const ciToken = _.isBoolean(ciTokenVar) ? 'GITHUB_TOKEN' : ciTokenVar; if (!process.env[ciToken]) { @@ -1406,7 +1411,7 @@ export class Site { }; } else if (process.env.GITHUB_ACTIONS) { // Set cache folder to a location Github Actions can find. - process.env.CACHE_DIR = path.join(process.env.GITHUB_WORKSPACE || '', 'gh-pages', '.cache'); + process.env.CACHE_DIR = path.join(process.env.GITHUB_WORKSPACE || '.cache', 'gh-pages'); repoSlug = Site.extractRepoSlug(options.repo, process.env.GITHUB_REPOSITORY); options.user = { From 5b19c72a9168996a3037c9418f83a559c8a85436 Mon Sep 17 00:00:00 2001 From: Ger Teck Date: Tue, 9 Jul 2024 09:17:07 +0800 Subject: [PATCH 2/2] Update Cache and Cleaning --- packages/core/src/Site/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/core/src/Site/index.ts b/packages/core/src/Site/index.ts index b26bd81ad..c7dee49b3 100644 --- a/packages/core/src/Site/index.ts +++ b/packages/core/src/Site/index.ts @@ -1382,9 +1382,11 @@ export class Site { }; options.message = options.message.concat(' [skip ci]'); - // Globally set cache folder to cwd/.cache/gh-pages. + // Globally set Cache Directory to /node_modules/.cache for gh-pages if (!process.env.CACHE_DIR || ['true', 'false', '1', '0'].includes(process.env.CACHE_DIR)) { - process.env.CACHE_DIR = path.join(process.cwd(), '.cache', 'gh-pages'); + const cacheDirectory = path.join(this.rootPath, 'node_modules', '.cache'); + fs.emptydirSync(path.join(cacheDirectory, 'gh-pages')); + process.env.CACHE_DIR = cacheDirectory; } if (ciTokenVar) { @@ -1411,7 +1413,7 @@ export class Site { }; } else if (process.env.GITHUB_ACTIONS) { // Set cache folder to a location Github Actions can find. - process.env.CACHE_DIR = path.join(process.env.GITHUB_WORKSPACE || '.cache', 'gh-pages'); + process.env.CACHE_DIR = path.join(process.env.GITHUB_WORKSPACE || '.cache'); repoSlug = Site.extractRepoSlug(options.repo, process.env.GITHUB_REPOSITORY); options.user = {