Skip to content

Commit

Permalink
Only clean download repository once
Browse files Browse the repository at this point in the history
  • Loading branch information
Demmonius committed Jan 8, 2021
1 parent 2474978 commit 6785019
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/manageArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,17 @@ const storeArtifact = (variables) => __awaiter(void 0, void 0, void 0, function*
});
const retrieveArtifact = (variables) => __awaiter(void 0, void 0, void 0, function* () {
const client = artifact.create();
rimraf_1.default.sync(config_1.WORKDIR);
fs_1.mkdirSync(config_1.WORKDIR);
for (const variable of variables) {
try {
rimraf_1.default.sync(config_1.WORKDIR);
fs_1.mkdirSync(config_1.WORKDIR);
const file = path_1.join(config_1.WORKDIR, `${variable.key}.txt`);
yield client.downloadAllArtifacts(variable.key);
variable.value = fs_1.readFileSync(file, { encoding: 'utf8' }).toString();
}
catch (error) {
core.warning(`Cannot retrieve variable ${variable.key}`);
console.error(error);
}
}
});
Expand Down
10 changes: 6 additions & 4 deletions src/manageArtifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {readFileSync, mkdirSync, writeFileSync} from 'fs';
import * as core from '@actions/core';
import {VariableDetail, VariableStatus} from "./types/variableStatus";
import {WORKDIR} from "./config";
import {ArtifactClient, UploadOptions} from "@actions/artifact";
import rimraf from "rimraf";
import {ArtifactClient, UploadOptions} from "@actions/artifact";
import {UploadResponse} from "@actions/artifact/lib/internal/upload-response";

const artifact = require('@actions/artifact');
const io = require('@actions/io');
Expand Down Expand Up @@ -44,7 +45,7 @@ const storeArtifact = async (variables: VariableDetail[]): Promise<void> => {
const artifactOptions: UploadOptions = {
retentionDays: 1 // Only keep artifacts 1 day to avoid reach limit: https://github.com/actions/toolkit/blob/c861dd8859fe5294289fcada363ce9bc71e9d260/packages/artifact/src/internal/upload-options.ts#L1
}
const artifactsUploadPromises: Promise<any>[] = [];
const artifactsUploadPromises: Promise<UploadResponse>[] = [];

rimraf.sync(WORKDIR);
mkdirSync(WORKDIR);
Expand All @@ -62,15 +63,16 @@ const storeArtifact = async (variables: VariableDetail[]): Promise<void> => {
const retrieveArtifact = async (variables: VariableDetail[]): Promise<void> => {
const client: ArtifactClient = artifact.create();

rimraf.sync(WORKDIR);
mkdirSync(WORKDIR);
for (const variable of variables) {
try {
rimraf.sync(WORKDIR);
mkdirSync(WORKDIR);
const file = join(WORKDIR, `${variable.key}.txt`);
await client.downloadAllArtifacts(variable.key);
variable.value = readFileSync(file, {encoding: 'utf8'}).toString();
} catch (error) {
core.warning(`Cannot retrieve variable ${variable.key}`)
console.error(error);
}
}
}
Expand Down

0 comments on commit 6785019

Please sign in to comment.