Merge 7b84952f53c8fabb90561153a686cb595fb00cb8 into 3f3b0175e8c66fb49b9a6d5a0cd1f8436d4c3ab6

This commit is contained in:
autoantwort 2024-05-23 12:22:37 +00:00 committed by GitHub
commit 8f0be2d6f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 60 additions and 15 deletions

48
dist/index.js vendored
View File

@ -1595,7 +1595,6 @@ const core = __importStar(__nccwpck_require__(2186));
const github_1 = __nccwpck_require__(5438); const github_1 = __nccwpck_require__(5438);
const plugin_retry_1 = __nccwpck_require__(6298); const plugin_retry_1 = __nccwpck_require__(6298);
const cache = __importStar(__nccwpck_require__(7799)); const cache = __importStar(__nccwpck_require__(7799));
const CACHE_KEY = '_state';
const STATE_FILE = 'state.txt'; const STATE_FILE = 'state.txt';
const STALE_DIR = '56acbeaa-1fef-4c79-8f84-7565e560fb03'; const STALE_DIR = '56acbeaa-1fef-4c79-8f84-7565e560fb03';
const mkTempDir = () => { const mkTempDir = () => {
@ -1644,22 +1643,25 @@ const resetCacheWithOctokit = (cacheKey) => __awaiter(void 0, void 0, void 0, fu
} }
}); });
class StateCacheStorage { class StateCacheStorage {
constructor(cacheKey) {
this.cacheKey = cacheKey;
}
save(serializedState) { save(serializedState) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const tmpDir = mkTempDir(); const tmpDir = mkTempDir();
const filePath = path_1.default.join(tmpDir, STATE_FILE); const filePath = path_1.default.join(tmpDir, STATE_FILE);
fs_1.default.writeFileSync(filePath, serializedState); fs_1.default.writeFileSync(filePath, serializedState);
try { try {
const cacheExists = yield checkIfCacheExists(CACHE_KEY); const cacheExists = yield checkIfCacheExists(this.cacheKey);
if (cacheExists) { if (cacheExists) {
yield resetCacheWithOctokit(CACHE_KEY); yield resetCacheWithOctokit(this.cacheKey);
} }
const fileSize = fs_1.default.statSync(filePath).size; const fileSize = fs_1.default.statSync(filePath).size;
if (fileSize === 0) { if (fileSize === 0) {
core.info(`the state will be removed`); core.info(`the state will be removed`);
return; return;
} }
yield cache.saveCache([path_1.default.dirname(filePath)], CACHE_KEY); yield cache.saveCache([path_1.default.dirname(filePath)], this.cacheKey);
} }
catch (error) { catch (error) {
core.warning(`Saving the state was not successful due to "${error.message || 'unknown reason'}"`); core.warning(`Saving the state was not successful due to "${error.message || 'unknown reason'}"`);
@ -1675,12 +1677,12 @@ class StateCacheStorage {
const filePath = path_1.default.join(tmpDir, STATE_FILE); const filePath = path_1.default.join(tmpDir, STATE_FILE);
unlinkSafely(filePath); unlinkSafely(filePath);
try { try {
const cacheExists = yield checkIfCacheExists(CACHE_KEY); const cacheExists = yield checkIfCacheExists(this.cacheKey);
if (!cacheExists) { if (!cacheExists) {
core.info('The saved state was not found, the process starts from the first issue.'); core.info('The saved state was not found, the process starts from the first issue.');
return ''; return '';
} }
yield cache.restoreCache([path_1.default.dirname(filePath)], CACHE_KEY); yield cache.restoreCache([path_1.default.dirname(filePath)], this.cacheKey);
if (!fs_1.default.existsSync(filePath)) { if (!fs_1.default.existsSync(filePath)) {
core.warning('Unknown error when unpacking the cache, the process starts from the first issue.'); core.warning('Unknown error when unpacking the cache, the process starts from the first issue.');
return ''; return '';
@ -2685,16 +2687,46 @@ exports.LoggerService = LoggerService;
/***/ }), /***/ }),
/***/ 6330: /***/ 6330:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict"; "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 })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getStateInstance = void 0; exports.getStateInstance = void 0;
const crypto = __importStar(__nccwpck_require__(6113));
const state_1 = __nccwpck_require__(5186); const state_1 = __nccwpck_require__(5186);
const state_cache_storage_1 = __nccwpck_require__(3709); const state_cache_storage_1 = __nccwpck_require__(3709);
function sha256(message) {
const hash = crypto.createHash('sha256');
hash.update(message);
return hash.digest('hex');
}
const getStateInstance = (options) => { const getStateInstance = (options) => {
const storage = new state_cache_storage_1.StateCacheStorage(); const cacheKey = sha256(JSON.stringify(options));
const storage = new state_cache_storage_1.StateCacheStorage(cacheKey);
return new state_1.State(storage, options); return new state_1.State(storage, options);
}; };
exports.getStateInstance = getStateInstance; exports.getStateInstance = getStateInstance;

View File

@ -7,7 +7,6 @@ import {context, getOctokit} from '@actions/github';
import {retry as octokitRetry} from '@octokit/plugin-retry'; import {retry as octokitRetry} from '@octokit/plugin-retry';
import * as cache from '@actions/cache'; import * as cache from '@actions/cache';
const CACHE_KEY = '_state';
const STATE_FILE = 'state.txt'; const STATE_FILE = 'state.txt';
const STALE_DIR = '56acbeaa-1fef-4c79-8f84-7565e560fb03'; const STALE_DIR = '56acbeaa-1fef-4c79-8f84-7565e560fb03';
@ -65,15 +64,21 @@ const resetCacheWithOctokit = async (cacheKey: string): Promise<void> => {
} }
}; };
export class StateCacheStorage implements IStateStorage { export class StateCacheStorage implements IStateStorage {
private cacheKey: string;
constructor(cacheKey: string) {
this.cacheKey = cacheKey;
}
async save(serializedState: string): Promise<void> { async save(serializedState: string): Promise<void> {
const tmpDir = mkTempDir(); const tmpDir = mkTempDir();
const filePath = path.join(tmpDir, STATE_FILE); const filePath = path.join(tmpDir, STATE_FILE);
fs.writeFileSync(filePath, serializedState); fs.writeFileSync(filePath, serializedState);
try { try {
const cacheExists = await checkIfCacheExists(CACHE_KEY); const cacheExists = await checkIfCacheExists(this.cacheKey);
if (cacheExists) { if (cacheExists) {
await resetCacheWithOctokit(CACHE_KEY); await resetCacheWithOctokit(this.cacheKey);
} }
const fileSize = fs.statSync(filePath).size; const fileSize = fs.statSync(filePath).size;
@ -82,7 +87,7 @@ export class StateCacheStorage implements IStateStorage {
return; return;
} }
await cache.saveCache([path.dirname(filePath)], CACHE_KEY); await cache.saveCache([path.dirname(filePath)], this.cacheKey);
} catch (error) { } catch (error) {
core.warning( core.warning(
`Saving the state was not successful due to "${ `Saving the state was not successful due to "${
@ -99,7 +104,7 @@ export class StateCacheStorage implements IStateStorage {
const filePath = path.join(tmpDir, STATE_FILE); const filePath = path.join(tmpDir, STATE_FILE);
unlinkSafely(filePath); unlinkSafely(filePath);
try { try {
const cacheExists = await checkIfCacheExists(CACHE_KEY); const cacheExists = await checkIfCacheExists(this.cacheKey);
if (!cacheExists) { if (!cacheExists) {
core.info( core.info(
'The saved state was not found, the process starts from the first issue.' 'The saved state was not found, the process starts from the first issue.'
@ -107,7 +112,7 @@ export class StateCacheStorage implements IStateStorage {
return ''; return '';
} }
await cache.restoreCache([path.dirname(filePath)], CACHE_KEY); await cache.restoreCache([path.dirname(filePath)], this.cacheKey);
if (!fs.existsSync(filePath)) { if (!fs.existsSync(filePath)) {
core.warning( core.warning(

View File

@ -1,9 +1,17 @@
import * as crypto from 'crypto';
import {IState} from '../interfaces/state/state'; import {IState} from '../interfaces/state/state';
import {State} from '../classes/state/state'; import {State} from '../classes/state/state';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {StateCacheStorage} from '../classes/state/state-cache-storage'; import {StateCacheStorage} from '../classes/state/state-cache-storage';
function sha256(message: string): string {
const hash = crypto.createHash('sha256');
hash.update(message);
return hash.digest('hex');
}
export const getStateInstance = (options: IIssuesProcessorOptions): IState => { export const getStateInstance = (options: IIssuesProcessorOptions): IState => {
const storage = new StateCacheStorage(); const cacheKey = sha256(JSON.stringify(options));
const storage = new StateCacheStorage(cacheKey);
return new State(storage, options); return new State(storage, options);
}; };