From 2377d067bce2b71a6f882dceb0d1aaf9cb5a8633 Mon Sep 17 00:00:00 2001 From: Caleb Gosiak Date: Thu, 30 Sep 2021 15:52:51 -0500 Subject: [PATCH] try this --- dist/restore/index.js | 22 ++++++++-------------- dist/save/index.js | 22 ++++++++-------------- package.json | 2 +- src/cache.service.ts | 31 ++++++++++++++----------------- 4 files changed, 31 insertions(+), 46 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index ad3cbdf..b7d67ee 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -43330,20 +43330,14 @@ class CacheService { uploadToS3(key, archivePath) { return __awaiter(this, void 0, void 0, function* () { const client = new aws_sdk_1.S3(); - // Read in the file, convert it to base64, store to S3 - fs_1.default.readFile(archivePath, (err, data) => { - if (err) { - throw err; - } - const base64data = data.toString("base64"); - client - .putObject({ - Bucket: this._bucket, - Key: key, - Body: base64data - }) - .send(); - }); + const data = fs_1.default.readFileSync(archivePath).toString("base64"); + return client + .putObject({ + Bucket: this._bucket, + Key: key, + Body: data + }) + .promise(); }); } } diff --git a/dist/save/index.js b/dist/save/index.js index fe66d2a..2a9b9f8 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -43330,20 +43330,14 @@ class CacheService { uploadToS3(key, archivePath) { return __awaiter(this, void 0, void 0, function* () { const client = new aws_sdk_1.S3(); - // Read in the file, convert it to base64, store to S3 - fs_1.default.readFile(archivePath, (err, data) => { - if (err) { - throw err; - } - const base64data = data.toString("base64"); - client - .putObject({ - Bucket: this._bucket, - Key: key, - Body: base64data - }) - .send(); - }); + const data = fs_1.default.readFileSync(archivePath).toString("base64"); + return client + .putObject({ + Bucket: this._bucket, + Key: key, + Body: data + }) + .promise(); }); } } diff --git a/package.json b/package.json index 8d12081..78ec707 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cache", - "version": "0.2.0", + "version": "0.3.0", "private": true, "description": "Cache dependencies and build outputs", "main": "dist/restore/index.js", diff --git a/src/cache.service.ts b/src/cache.service.ts index ef45c4d..65365e3 100644 --- a/src/cache.service.ts +++ b/src/cache.service.ts @@ -1,7 +1,8 @@ import * as utils from "@actions/cache/lib/internal/cacheUtils"; import { createTar, listTar } from "@actions/cache/lib/internal/tar"; import * as core from "@actions/core"; -import { S3 } from "aws-sdk"; +import { AWSError, S3 } from "aws-sdk"; +import { PromiseResult } from "aws-sdk/lib/request"; import filesize from "filesize"; import fs from "fs"; import * as path from "path"; @@ -73,23 +74,19 @@ export class CacheService { return key; } - private async uploadToS3(key: string, archivePath: string): Promise { + private async uploadToS3( + key: string, + archivePath: string + ): Promise> { const client = new S3(); - // Read in the file, convert it to base64, store to S3 - fs.readFile(archivePath, (err, data) => { - if (err) { - throw err; - } + const data = fs.readFileSync(archivePath).toString("base64"); - const base64data = data.toString("base64"); - - client - .putObject({ - Bucket: this._bucket, - Key: key, - Body: base64data - }) - .send(); - }); + return client + .putObject({ + Bucket: this._bucket, + Key: key, + Body: data + }) + .promise(); } }