diff --git a/dist/index.js b/dist/index.js index 2aa4193..e6c7b68 100644 --- a/dist/index.js +++ b/dist/index.js @@ -31169,22 +31169,23 @@ const fs = __importStar(__webpack_require__(5747)); const path_1 = __importDefault(__webpack_require__(5622)); const constants_1 = __webpack_require__(1211); function doDownload(s3, s3Bucket, fileKey, localKey) { - return __awaiter(this, void 0, void 0, function* () { - return new Promise(function (resolve, reject) { - const localKeyDir = path_1.default.dirname(localKey); - if (!fs.existsSync(localKeyDir)) { - core.debug(`Creating directory (${localKeyDir}) since it did not exist`); - fs.mkdirSync(localKeyDir, { recursive: true }); - } - const getObjectParams = { Bucket: s3Bucket, Key: fileKey }; - const writeStream = fs.createWriteStream(localKey); - core.info(`Started download: ${localKey}`); - core.debug(`S3 download uri: s3://${s3Bucket}/${fileKey}`); - const readStream = s3.getObject(getObjectParams).createReadStream(); - readStream.pipe(writeStream); - readStream.on('close', resolve); - readStream.on('error', reject); + return new Promise(function (resolve, reject) { + const localKeyDir = path_1.default.dirname(localKey); + if (!fs.existsSync(localKeyDir)) { + core.debug(`Creating directory (${localKeyDir}) since it did not exist`); + fs.mkdirSync(localKeyDir, { recursive: true }); + } + const getObjectParams = { Bucket: s3Bucket, Key: fileKey }; + const writeStream = fs.createWriteStream(localKey); + core.info(`Started download: ${localKey}`); + core.debug(`S3 download uri: s3://${s3Bucket}/${fileKey}`); + const readStream = s3.getObject(getObjectParams).createReadStream(); + readStream.pipe(writeStream); + readStream.on('close', () => { + core.info(`Finished download: ${localKey}`); + resolve; }); + readStream.on('error', reject); }); } function run() { @@ -31211,23 +31212,17 @@ function run() { Prefix: s3Prefix }; core.debug(JSON.stringify(s3Params)); - s3.listObjects(s3Params, function (err, data) { - return __awaiter(this, void 0, void 0, function* () { - if (err) { - throw err; - } - if (!data.Contents) { - throw new Error(`Could not find objects with ${s3Prefix}`); - } - for (const fileObject of data.Contents) { - if (!fileObject.Key) { - continue; - } - const localKey = path_1.default.join(resolvedPath, fileObject.Key.replace(s3Prefix, '')); - yield doDownload(s3, s3Bucket, fileObject.Key, localKey); - } - }); - }); + const objects = yield s3.listObjects(s3Params).promise(); + if (!objects.Contents) { + throw new Error(`Could not find objects with ${s3Prefix}`); + } + for (const fileObject of objects.Contents) { + if (!fileObject.Key) { + continue; + } + const localKey = path_1.default.join(resolvedPath, fileObject.Key.replace(s3Prefix, '')); + yield doDownload(s3, s3Bucket, fileObject.Key, localKey); + } // output the directory that the artifact(s) was/were downloaded to // if no path is provided, an empty string resolves to the current working directory core.setOutput(constants_1.Outputs.DownloadPath, resolvedPath); diff --git a/src/download-artifact.ts b/src/download-artifact.ts index 3236ab1..535638c 100644 --- a/src/download-artifact.ts +++ b/src/download-artifact.ts @@ -6,7 +6,7 @@ import * as fs from 'fs' import path from 'path' import {Inputs, Outputs} from './constants' -async function doDownload( +function doDownload( s3: AWS.S3, s3Bucket: string, fileKey: string, @@ -24,7 +24,10 @@ async function doDownload( core.debug(`S3 download uri: s3://${s3Bucket}/${fileKey}`) const readStream = s3.getObject(getObjectParams).createReadStream() readStream.pipe(writeStream) - readStream.on('close', resolve) + readStream.on('close', () => { + core.info(`Finished download: ${localKey}`) + resolve + }) readStream.on('error', reject) }) } @@ -52,24 +55,20 @@ async function run(): Promise { Prefix: s3Prefix } core.debug(JSON.stringify(s3Params)) - s3.listObjects(s3Params, async function (err, data) { - if (err) { - throw err + const objects = await s3.listObjects(s3Params).promise() + if (!objects.Contents) { + throw new Error(`Could not find objects with ${s3Prefix}`) + } + for (const fileObject of objects.Contents) { + if (!fileObject.Key) { + continue } - if (!data.Contents) { - throw new Error(`Could not find objects with ${s3Prefix}`) - } - for (const fileObject of data.Contents) { - if (!fileObject.Key) { - continue - } - const localKey = path.join( - resolvedPath, - fileObject.Key.replace(s3Prefix, '') - ) - await doDownload(s3, s3Bucket, fileObject.Key, localKey) - } - }) + const localKey = path.join( + resolvedPath, + fileObject.Key.replace(s3Prefix, '') + ) + await doDownload(s3, s3Bucket, fileObject.Key, localKey) + } // output the directory that the artifact(s) was/were downloaded to // if no path is provided, an empty string resolves to the current working directory core.setOutput(Outputs.DownloadPath, resolvedPath)