Use cache instead of artifacts
This commit is contained in:
parent
6e0ace4210
commit
c7d43763bf
File diff suppressed because one or more lines are too long
|
@ -4,8 +4,9 @@ import os from 'os';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as artifact from '@actions/artifact';
|
// import * as artifact from '@actions/artifact';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
import {restoreCache, saveCache} from '@actions/cache';
|
||||||
|
|
||||||
type IssueID = number;
|
type IssueID = number;
|
||||||
export class State implements IState {
|
export class State implements IState {
|
||||||
|
@ -31,7 +32,8 @@ export class State implements IState {
|
||||||
if (!this.debug) this.processedIssuesIDs.clear();
|
if (!this.debug) this.processedIssuesIDs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly ARTIFACT_NAME = '_stale_state';
|
private static readonly ARTIFACT_NAME = '_state';
|
||||||
|
private static readonly STATE_FILE = 'state.txt';
|
||||||
async persist() {
|
async persist() {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
core.debug('The state is not persisted in the debug mode');
|
core.debug('The state is not persisted in the debug mode');
|
||||||
|
@ -43,16 +45,18 @@ export class State implements IState {
|
||||||
const tmpDir = os.tmpdir();
|
const tmpDir = os.tmpdir();
|
||||||
const file = path.join(
|
const file = path.join(
|
||||||
tmpDir,
|
tmpDir,
|
||||||
crypto.randomBytes(8).readBigUInt64LE(0).toString()
|
State.STATE_FILE
|
||||||
|
// crypto.randomBytes(8).readBigUInt64LE(0).toString()
|
||||||
);
|
);
|
||||||
fs.writeFileSync(file, serialized);
|
fs.writeFileSync(file, serialized);
|
||||||
|
|
||||||
core.debug(
|
core.debug(
|
||||||
`Persisting state includes info about ${this.processedIssuesIDs.size} issue(s)`
|
`Persisting state includes info about ${this.processedIssuesIDs.size} issue(s)`
|
||||||
);
|
);
|
||||||
const artifactClient = artifact.create();
|
// const artifactClient = artifact.create();
|
||||||
try {
|
try {
|
||||||
await artifactClient.uploadArtifact(State.ARTIFACT_NAME, [file], tmpDir);
|
saveCache([tmpDir], State.ARTIFACT_NAME);
|
||||||
|
// await artifactClient.uploadArtifact(State.ARTIFACT_NAME, [file], tmpDir);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.warning(
|
core.warning(
|
||||||
`Persisting the state was not successful due to "${
|
`Persisting the state was not successful due to "${
|
||||||
|
@ -66,21 +70,26 @@ export class State implements IState {
|
||||||
this.reset();
|
this.reset();
|
||||||
|
|
||||||
const tmpDir = os.tmpdir();
|
const tmpDir = os.tmpdir();
|
||||||
const artifactClient = artifact.create();
|
// const artifactClient = artifact.create();
|
||||||
try {
|
try {
|
||||||
|
/*
|
||||||
const downloadResponse = await artifactClient.downloadArtifact(
|
const downloadResponse = await artifactClient.downloadArtifact(
|
||||||
State.ARTIFACT_NAME,
|
State.ARTIFACT_NAME,
|
||||||
tmpDir
|
tmpDir
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
|
await restoreCache([tmpDir], State.ARTIFACT_NAME);
|
||||||
|
|
||||||
|
/*
|
||||||
const downloadedFiles = fs.readdirSync(downloadResponse.downloadPath);
|
const downloadedFiles = fs.readdirSync(downloadResponse.downloadPath);
|
||||||
if (downloadedFiles.length === 0) {
|
if (downloadedFiles.length === 0) {
|
||||||
throw Error(
|
throw Error(
|
||||||
'There is no data in the state artifact, probably because of the previous run failed'
|
'There is no data in the state artifact, probably because of the previous run failed'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
const serialized = fs.readFileSync(
|
const serialized = fs.readFileSync(
|
||||||
path.join(downloadResponse.downloadPath, downloadedFiles[0]),
|
path.join(tmpDir, State.ARTIFACT_NAME),
|
||||||
{encoding: 'utf8'}
|
{encoding: 'utf8'}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue