mirror of
https://github.com/actions/stale.git
synced 2025-12-31 20:38:17 +00:00
Handle error during rehydration & persistings
This commit is contained in:
@@ -5,6 +5,7 @@ import crypto from 'crypto';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import * as artifact from '@actions/artifact';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
type IssueID = number;
|
||||
export class State implements IState {
|
||||
@@ -30,12 +31,22 @@ export class State implements IState {
|
||||
const serialized = Array.from(this.processedIssuesIDs).join('|');
|
||||
|
||||
const tmpDir = os.tmpdir();
|
||||
const file = crypto.randomBytes(8).readBigUInt64LE(0).toString();
|
||||
fs.writeFileSync(path.join(tmpDir, file), serialized);
|
||||
const file = path.join(
|
||||
tmpDir,
|
||||
crypto.randomBytes(8).readBigUInt64LE(0).toString()
|
||||
);
|
||||
fs.writeFileSync(file, serialized);
|
||||
|
||||
const artifactClient = artifact.create();
|
||||
// TODO: handle errors
|
||||
await artifactClient.uploadArtifact(State.ARTIFACT_NAME, [file], tmpDir);
|
||||
try {
|
||||
await artifactClient.uploadArtifact(State.ARTIFACT_NAME, [file], tmpDir);
|
||||
} catch (error) {
|
||||
core.warning(
|
||||
`Persisting the state was not successful due to "${
|
||||
error.message || 'unknown reason'
|
||||
}"`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async rehydrate() {
|
||||
@@ -43,27 +54,40 @@ export class State implements IState {
|
||||
|
||||
const tmpDir = os.tmpdir();
|
||||
const artifactClient = artifact.create();
|
||||
const downloadResponse = await artifactClient.downloadArtifact(
|
||||
State.ARTIFACT_NAME,
|
||||
tmpDir
|
||||
);
|
||||
try {
|
||||
const downloadResponse = await artifactClient.downloadArtifact(
|
||||
State.ARTIFACT_NAME,
|
||||
tmpDir
|
||||
);
|
||||
|
||||
const downloadedFiles = fs.readdirSync(downloadResponse.downloadPath);
|
||||
if (downloadedFiles.length === 0) {
|
||||
// TODO: handle error
|
||||
const downloadedFiles = fs.readdirSync(downloadResponse.downloadPath);
|
||||
if (downloadedFiles.length === 0) {
|
||||
throw Error(
|
||||
'There is no data in the state artifact, probably because of the previous run failed'
|
||||
);
|
||||
}
|
||||
const serialized = fs.readFileSync(
|
||||
path.join(downloadResponse.downloadPath, downloadedFiles[0]),
|
||||
{encoding: 'utf8'}
|
||||
);
|
||||
|
||||
if (serialized.length === 0) return;
|
||||
|
||||
const issueIDs = serialized
|
||||
.split('|')
|
||||
.map(parseInt)
|
||||
.filter(i => !isNaN(i));
|
||||
|
||||
this.processedIssuesIDs = new Set(issueIDs);
|
||||
core.debug(
|
||||
`Rehydrated state includes info about ${issueIDs.length} issue(s)`
|
||||
);
|
||||
} catch (error) {
|
||||
core.warning(
|
||||
`Rehydrating the state was not successful due to "${
|
||||
error.message || 'unknown reason'
|
||||
}"`
|
||||
);
|
||||
}
|
||||
const serialized = fs.readFileSync(
|
||||
path.join(downloadResponse.downloadPath, downloadedFiles[0]),
|
||||
{encoding: 'utf8'}
|
||||
);
|
||||
|
||||
if (serialized.length === 0) return;
|
||||
|
||||
const issueIDs = serialized
|
||||
.split('|')
|
||||
.map(parseInt)
|
||||
.filter(i => !isNaN(i));
|
||||
|
||||
this.processedIssuesIDs = new Set(issueIDs);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user