Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit fb51756

Browse files
authored
fix: replace depcrated 'request' dependency by 'node-fetch' (#903) (#1082)
Also await the success of both promises before reporting that it was successfully uploaded to S3.
1 parent 083bd8a commit fb51756

File tree

3 files changed

+41
-266
lines changed

3 files changed

+41
-266
lines changed

modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@octokit/rest": "^18.5.2",
1919
"@types/jest": "^26.0.22",
2020
"@types/node": "^16.4.13",
21+
"@types/node-fetch": "^2.5.12",
2122
"@types/request": "^2.48.4",
2223
"@typescript-eslint/eslint-plugin": "^4.29.1",
2324
"@typescript-eslint/parser": "^4.29.1",
@@ -32,7 +33,7 @@
3233
"typescript": "^4.3.4"
3334
},
3435
"dependencies": {
35-
"request": "^2.88.2",
36+
"node-fetch": "^2.6.1",
3637
"yn": "^4.0.0"
3738
}
3839
}

modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/src/syncer/handler.ts

+25-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Octokit } from '@octokit/rest';
22
import { PassThrough } from 'stream';
3-
import request from 'request';
3+
import fetch from 'node-fetch';
44
import { S3 } from 'aws-sdk';
55
import AWS from 'aws-sdk';
66
import yn from 'yn';
@@ -65,29 +65,32 @@ async function getLinuxReleaseAsset(
6565

6666
async function uploadToS3(s3: S3, cacheObject: CacheObject, actionRunnerReleaseAsset: ReleaseAsset): Promise<void> {
6767
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();
7476

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));
9087
});
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+
});
9194
}
9295

9396
export const handle = async (): Promise<void> => {

0 commit comments

Comments
 (0)