mirror of
https://github.com/actions/download-artifact.git
synced 2025-07-26 00:18:30 +02:00
try to do it without a weird callback
Signed-off-by: Eli Uriegas <eliuriegas@fb.com>
This commit is contained in:
parent
35ec0229c4
commit
fdf1695da1
2 changed files with 45 additions and 51 deletions
59
dist/index.js
vendored
59
dist/index.js
vendored
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue