Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace 'request' dependency by 'node-fetch' (#903) #1082

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@octokit/rest": "^18.5.2",
"@types/jest": "^26.0.22",
"@types/node": "^16.4.13",
"@types/node-fetch": "^2.5.12",
"@types/request": "^2.48.4",
"@typescript-eslint/eslint-plugin": "^4.29.1",
"@typescript-eslint/parser": "^4.29.1",
Expand All @@ -32,7 +33,7 @@
"typescript": "^4.3.4"
},
"dependencies": {
"request": "^2.88.2",
"node-fetch": "^2.6.1",
"yn": "^4.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Octokit } from '@octokit/rest';
import { PassThrough } from 'stream';
import request from 'request';
import fetch from 'node-fetch';
import { S3 } from 'aws-sdk';
import AWS from 'aws-sdk';
import yn from 'yn';
Expand Down Expand Up @@ -65,29 +65,32 @@ async function getLinuxReleaseAsset(

async function uploadToS3(s3: S3, cacheObject: CacheObject, actionRunnerReleaseAsset: ReleaseAsset): Promise<void> {
const writeStream = new PassThrough();
s3.upload({
Bucket: cacheObject.bucket,
Key: cacheObject.key,
Tagging: versionKey + '=' + actionRunnerReleaseAsset.name,
Body: writeStream,
}).promise();
const writePromise = s3
.upload({
Bucket: cacheObject.bucket,
Key: cacheObject.key,
Tagging: versionKey + '=' + actionRunnerReleaseAsset.name,
Body: writeStream,
})
.promise();

await new Promise<void>((resolve, reject) => {
console.debug('Start downloading %s and uploading to S3.', actionRunnerReleaseAsset.name);
request
.get(actionRunnerReleaseAsset.downloadUrl)
.pipe(writeStream)
.on('finish', () => {
console.info(`The new distribution is uploaded to S3.`);
resolve();
})
.on('error', (error) => {
reject(error);
});
}).catch((error) => {
console.error(`Exception: ${error}`);
throw error;
console.debug('Start downloading %s and uploading to S3.', actionRunnerReleaseAsset.name);
const readPromise = new Promise<void>((resolve, reject) => {
fetch(actionRunnerReleaseAsset.downloadUrl)
.then((res) =>
res.body
.pipe(writeStream)
.on('finish', () => resolve())
.on('error', (error) => reject(error)),
)
.catch((error) => reject(error));
});
await Promise.all([readPromise, writePromise])
.then(() => console.info(`The new distribution is uploaded to S3.`))
.catch((error) => {
console.error(`Uploading of the new distribution to S3 failed: ${error}`);
throw error;
});
}

export const handle = async (): Promise<void> => {
Expand Down
Loading