|
1 | 1 | import { Octokit } from '@octokit/rest';
|
2 | 2 | import { PassThrough } from 'stream';
|
3 |
| -import request from 'request'; |
| 3 | +import fetch from 'node-fetch'; |
4 | 4 | import { S3 } from 'aws-sdk';
|
5 | 5 | import AWS from 'aws-sdk';
|
6 | 6 | import yn from 'yn';
|
@@ -65,29 +65,32 @@ async function getLinuxReleaseAsset(
|
65 | 65 |
|
66 | 66 | async function uploadToS3(s3: S3, cacheObject: CacheObject, actionRunnerReleaseAsset: ReleaseAsset): Promise<void> {
|
67 | 67 | const writeStream = new PassThrough();
|
68 |
| - s3.upload({ |
69 |
| - Bucket: cacheObject.bucket, |
70 |
| - Key: cacheObject.key, |
71 |
| - Tagging: versionKey + '=' + actionRunnerReleaseAsset.name, |
72 |
| - Body: writeStream, |
73 |
| - }).promise(); |
| 68 | + const writePromise = s3 |
| 69 | + .upload({ |
| 70 | + Bucket: cacheObject.bucket, |
| 71 | + Key: cacheObject.key, |
| 72 | + Tagging: versionKey + '=' + actionRunnerReleaseAsset.name, |
| 73 | + Body: writeStream, |
| 74 | + }) |
| 75 | + .promise(); |
74 | 76 |
|
75 |
| - await new Promise<void>((resolve, reject) => { |
76 |
| - console.debug('Start downloading %s and uploading to S3.', actionRunnerReleaseAsset.name); |
77 |
| - request |
78 |
| - .get(actionRunnerReleaseAsset.downloadUrl) |
79 |
| - .pipe(writeStream) |
80 |
| - .on('finish', () => { |
81 |
| - console.info(`The new distribution is uploaded to S3.`); |
82 |
| - resolve(); |
83 |
| - }) |
84 |
| - .on('error', (error) => { |
85 |
| - reject(error); |
86 |
| - }); |
87 |
| - }).catch((error) => { |
88 |
| - console.error(`Exception: ${error}`); |
89 |
| - throw error; |
| 77 | + console.debug('Start downloading %s and uploading to S3.', actionRunnerReleaseAsset.name); |
| 78 | + const readPromise = new Promise<void>((resolve, reject) => { |
| 79 | + fetch(actionRunnerReleaseAsset.downloadUrl) |
| 80 | + .then((res) => |
| 81 | + res.body |
| 82 | + .pipe(writeStream) |
| 83 | + .on('finish', () => resolve()) |
| 84 | + .on('error', (error) => reject(error)), |
| 85 | + ) |
| 86 | + .catch((error) => reject(error)); |
90 | 87 | });
|
| 88 | + await Promise.all([readPromise, writePromise]) |
| 89 | + .then(() => console.info(`The new distribution is uploaded to S3.`)) |
| 90 | + .catch((error) => { |
| 91 | + console.error(`Uploading of the new distribution to S3 failed: ${error}`); |
| 92 | + throw error; |
| 93 | + }); |
91 | 94 | }
|
92 | 95 |
|
93 | 96 | export const handle = async (): Promise<void> => {
|
|
0 commit comments