diff --git a/dist/index.js b/dist/index.js index a67fd4ee6..b1edb0c64 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36,7 +36,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.downloadFileFromActionsCache = void 0; const cache = __importStar(__nccwpck_require__(7799)); const path_1 = __importDefault(__nccwpck_require__(1017)); -const downloadFileFromActionsCache = (destFileName, cacheKey, cacheVersion) => cache.restoreCache([path_1.default.dirname(destFileName)], cacheKey, [ +const downloadFileFromActionsCache = (destFileName, cacheKey, +// eslint-disable-next-line @typescript-eslint/no-unused-vars +cacheVersion) => cache.restoreCache([path_1.default.dirname(destFileName)], cacheKey, [ cacheKey ]); exports.downloadFileFromActionsCache = downloadFileFromActionsCache; @@ -91,6 +93,7 @@ const core = __importStar(__nccwpck_require__(2186)); const cache = __importStar(__nccwpck_require__(7799)); const github_1 = __nccwpck_require__(5438); const plugin_retry_1 = __nccwpck_require__(6298); +const path_1 = __importDefault(__nccwpck_require__(1017)); const resetCacheWithOctokit = (cacheKey) => __awaiter(void 0, void 0, void 0, function* () { const token = core.getInput('repo-token'); const client = (0, github_1.getOctokit)(token, undefined, plugin_retry_1.retry); @@ -110,14 +113,17 @@ const resetCacheWithOctokit = (cacheKey) => __awaiter(void 0, void 0, void 0, fu } } }); -const uploadFileToActionsCache = (filePath, cacheKey, cacheVersion) => __awaiter(void 0, void 0, void 0, function* () { +const uploadFileToActionsCache = (filePath, cacheKey, +// eslint-disable-next-line @typescript-eslint/no-unused-vars +cacheVersion) => __awaiter(void 0, void 0, void 0, function* () { yield resetCacheWithOctokit(cacheKey); const fileSize = fs_1.default.statSync(filePath).size; if (fileSize === 0) { core.info(`the cache ${cacheKey} will be removed`); return; } - cache.saveCache([filePath], cacheKey); + core.debug('content: ' + fs_1.default.readFileSync(filePath).toString()); + cache.saveCache([path_1.default.dirname(filePath)], cacheKey); }); exports.uploadFileToActionsCache = uploadFileToActionsCache; @@ -1691,26 +1697,61 @@ import {downloadFileFromActionsCache} from '../actions-cache-internal/download'; const CACHE_KEY = '_state'; const CACHE_VERSION = '1'; const STATE_FILE = 'state.txt'; +const STALE_DIR = '56acbeaa-1fef-4c79-8f84-7565e560fb03'; +const mkTempDir = () => { + const tmpDir = path_1.default.join(os_1.default.tmpdir(), STALE_DIR); + fs_1.default.mkdirSync(tmpDir, { recursive: true }); + return tmpDir; +}; +const unlinkSafely = (filePath) => { + try { + fs_1.default.unlinkSync(filePath); + } + catch (foo) { + /* ignore */ + } +}; class StateCacheStorage { save(serializedState) { return __awaiter(this, void 0, void 0, function* () { - const tmpDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'state-')); - const file = path_1.default.join(tmpDir, STATE_FILE); - fs_1.default.writeFileSync(file, serializedState); + const tmpDir = mkTempDir(); + const fileName = path_1.default.join(tmpDir, STATE_FILE); + fs_1.default.writeFileSync(fileName, serializedState); try { - yield (0, upload_1.uploadFileToActionsCache)(file, CACHE_KEY, CACHE_VERSION); + core.debug(tmpDir); + core.debug(path_1.default.dirname(fileName)); + core.debug(fileName); + core.debug(serializedState); + core.debug(fs_1.default.readFileSync(fileName).toString()); + fs_1.default.readdir(path_1.default.dirname(fileName), (err, files) => { + files.forEach(file => { + core.debug(file); + }); + }); + yield (0, upload_1.uploadFileToActionsCache)(fileName, CACHE_KEY, CACHE_VERSION); } catch (error) { core.warning(`Saving the state was not successful due to "${error.message || 'unknown reason'}"`); } + finally { + unlinkSafely(fileName); + } }); } restore() { return __awaiter(this, void 0, void 0, function* () { - const tmpDir = fs_1.default.mkdtempSync('state-'); + const tmpDir = mkTempDir(); //fs.mkdtempSync('state-'); const fileName = path_1.default.join(tmpDir, STATE_FILE); + unlinkSafely(fileName); try { yield (0, download_1.downloadFileFromActionsCache)(fileName, CACHE_KEY, CACHE_VERSION); + core.debug(tmpDir); + core.debug(path_1.default.dirname(fileName)); + fs_1.default.readdir(path_1.default.dirname(fileName), (err, files) => { + files.forEach(file => { + core.debug(file); + }); + }); if (!fs_1.default.existsSync(fileName)) { core.info('The stored state has not been found, probably because of the very first run or the previous run failed'); return ''; diff --git a/src/classes/actions-cache-hilevel/download.ts b/src/classes/actions-cache-hilevel/download.ts index d17924430..7bc08ef29 100644 --- a/src/classes/actions-cache-hilevel/download.ts +++ b/src/classes/actions-cache-hilevel/download.ts @@ -4,6 +4,7 @@ import path from 'path'; export const downloadFileFromActionsCache = ( destFileName: string, cacheKey: string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars cacheVersion: string ): Promise => cache.restoreCache([path.dirname(destFileName)], cacheKey, [ diff --git a/src/classes/actions-cache-hilevel/upload.ts b/src/classes/actions-cache-hilevel/upload.ts index 890eed0ab..1338a333c 100644 --- a/src/classes/actions-cache-hilevel/upload.ts +++ b/src/classes/actions-cache-hilevel/upload.ts @@ -3,6 +3,7 @@ import * as core from '@actions/core'; import * as cache from '@actions/cache'; import {getOctokit} from '@actions/github'; import {retry as octokitRetry} from '@octokit/plugin-retry'; +import path from 'path'; const resetCacheWithOctokit = async (cacheKey: string): Promise => { const token = core.getInput('repo-token'); @@ -26,6 +27,7 @@ const resetCacheWithOctokit = async (cacheKey: string): Promise => { export const uploadFileToActionsCache = async ( filePath: string, cacheKey: string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars cacheVersion: string ) => { await resetCacheWithOctokit(cacheKey); @@ -36,5 +38,6 @@ export const uploadFileToActionsCache = async ( return; } - cache.saveCache([filePath], cacheKey); + core.debug('content: ' + fs.readFileSync(filePath).toString()); + cache.saveCache([path.dirname(filePath)], cacheKey); }; diff --git a/src/classes/state/state-cache-storage.ts b/src/classes/state/state-cache-storage.ts index 88fb3fb2f..82cd8563a 100644 --- a/src/classes/state/state-cache-storage.ts +++ b/src/classes/state/state-cache-storage.ts @@ -13,28 +13,65 @@ import {downloadFileFromActionsCache} from '../actions-cache-internal/download'; const CACHE_KEY = '_state'; const CACHE_VERSION = '1'; const STATE_FILE = 'state.txt'; +const STALE_DIR = '56acbeaa-1fef-4c79-8f84-7565e560fb03'; + +const mkTempDir = (): string => { + const tmpDir = path.join(os.tmpdir(), STALE_DIR); + fs.mkdirSync(tmpDir, {recursive: true}); + return tmpDir; +}; + +const unlinkSafely = (filePath: string) => { + try { + fs.unlinkSync(filePath); + } catch (foo) { + /* ignore */ + } +}; export class StateCacheStorage implements IStateStorage { async save(serializedState: string): Promise { - const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'state-')); - const file = path.join(tmpDir, STATE_FILE); - fs.writeFileSync(file, serializedState); + const tmpDir = mkTempDir(); + const fileName = path.join(tmpDir, STATE_FILE); + fs.writeFileSync(fileName, serializedState); try { - await uploadFileToActionsCache(file, CACHE_KEY, CACHE_VERSION); + core.debug(tmpDir); + core.debug(path.dirname(fileName)); + core.debug(fileName); + core.debug(serializedState); + core.debug(fs.readFileSync(fileName).toString()); + fs.readdir(path.dirname(fileName), (err, files) => { + files.forEach(file => { + core.debug(file); + }); + }); + await uploadFileToActionsCache(fileName, CACHE_KEY, CACHE_VERSION); } catch (error) { core.warning( `Saving the state was not successful due to "${ error.message || 'unknown reason' }"` ); + } finally { + unlinkSafely(fileName); } } async restore(): Promise { - const tmpDir = fs.mkdtempSync('state-'); + const tmpDir = mkTempDir(); //fs.mkdtempSync('state-'); const fileName = path.join(tmpDir, STATE_FILE); + unlinkSafely(fileName); try { await downloadFileFromActionsCache(fileName, CACHE_KEY, CACHE_VERSION); + + core.debug(tmpDir); + core.debug(path.dirname(fileName)); + fs.readdir(path.dirname(fileName), (err, files) => { + files.forEach(file => { + core.debug(file); + }); + }); + if (!fs.existsSync(fileName)) { core.info( 'The stored state has not been found, probably because of the very first run or the previous run failed'