-
Notifications
You must be signed in to change notification settings - Fork 105
Upgrade runner-binaries-syncer to aws sdk v3 #7078
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,8 +1,8 @@ | ||||||||||||||||
import { Octokit } from '@octokit/rest'; | ||||||||||||||||
import { PassThrough } from 'stream'; | ||||||||||||||||
import request from 'request'; | ||||||||||||||||
import { S3 } from 'aws-sdk'; | ||||||||||||||||
import AWS from 'aws-sdk'; | ||||||||||||||||
import { S3, Tag } from '@aws-sdk/client-s3'; | ||||||||||||||||
import { Upload } from '@aws-sdk/lib-storage'; | ||||||||||||||||
import yn from 'yn'; | ||||||||||||||||
|
||||||||||||||||
const versionKey = 'name'; | ||||||||||||||||
|
@@ -14,14 +14,12 @@ interface CacheObject { | |||||||||||||||
|
||||||||||||||||
async function getCachedVersion(s3: S3, cacheObject: CacheObject): Promise<string | undefined> { | ||||||||||||||||
try { | ||||||||||||||||
const objectTagging = await s3 | ||||||||||||||||
.getObjectTagging({ | ||||||||||||||||
Bucket: cacheObject.bucket, | ||||||||||||||||
Key: cacheObject.key, | ||||||||||||||||
}) | ||||||||||||||||
.promise(); | ||||||||||||||||
const versions = objectTagging.TagSet?.filter((t: S3.Tag) => t.Key === versionKey); | ||||||||||||||||
return versions.length === 1 ? versions[0].Value : undefined; | ||||||||||||||||
const objectTagging = await s3.getObjectTagging({ | ||||||||||||||||
Bucket: cacheObject.bucket, | ||||||||||||||||
Key: cacheObject.key, | ||||||||||||||||
}); | ||||||||||||||||
const versions = objectTagging.TagSet?.filter((t: Tag) => t.Key === versionKey); | ||||||||||||||||
return versions?.length === 1 ? versions[0].Value : undefined; | ||||||||||||||||
Comment on lines
+21
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The optional chaining
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||
} catch (e) { | ||||||||||||||||
console.debug('No tags found'); | ||||||||||||||||
return undefined; | ||||||||||||||||
|
@@ -65,12 +63,16 @@ async function getReleaseAsset( | |||||||||||||||
|
||||||||||||||||
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 upload = new Upload({ | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original |
||||||||||||||||
client: s3, | ||||||||||||||||
params: { | ||||||||||||||||
Bucket: cacheObject.bucket, | ||||||||||||||||
Key: cacheObject.key, | ||||||||||||||||
Tagging: `${versionKey}=${actionRunnerReleaseAsset.name}`, | ||||||||||||||||
Body: writeStream, | ||||||||||||||||
}, | ||||||||||||||||
}); | ||||||||||||||||
const uploadPromise = upload.done(); | ||||||||||||||||
|
||||||||||||||||
await new Promise<void>((resolve, reject) => { | ||||||||||||||||
console.debug('Start downloading %s and uploading to S3.', actionRunnerReleaseAsset.name); | ||||||||||||||||
|
@@ -87,10 +89,11 @@ async function uploadToS3(s3: S3, cacheObject: CacheObject, actionRunnerReleaseA | |||||||||||||||
}).catch((error) => { | ||||||||||||||||
console.error(`Exception: ${error}`); | ||||||||||||||||
}); | ||||||||||||||||
await uploadPromise; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The uploadPromise is awaited after the request stream has already finished, which could cause the upload to complete before all data is written. Move Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
export const handle = async (): Promise<void> => { | ||||||||||||||||
const s3 = new AWS.S3(); | ||||||||||||||||
const s3 = new S3(); | ||||||||||||||||
|
||||||||||||||||
const fetchPrereleaseBinaries = yn(process.env.GITHUB_RUNNER_ALLOW_PRERELEASE_BINARIES, { default: false }); | ||||||||||||||||
const distributions = [ | ||||||||||||||||
|
@@ -131,7 +134,7 @@ export const handle = async (): Promise<void> => { | |||||||||||||||
const currentVersion = await getCachedVersion(s3, cacheObject); | ||||||||||||||||
console.debug('latest: ' + currentVersion); | ||||||||||||||||
if (currentVersion === undefined || currentVersion != actionRunnerReleaseAsset.name) { | ||||||||||||||||
uploadToS3(s3, cacheObject, actionRunnerReleaseAsset); | ||||||||||||||||
await uploadToS3(s3, cacheObject, actionRunnerReleaseAsset); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an await since uploadToS3 is an async function and is in a for loop, so this should wait for the upload to finish. Alt: add to a list of promises and await at the end |
||||||||||||||||
} else { | ||||||||||||||||
console.debug('Distribution is up-to-date, no action.'); | ||||||||||||||||
} | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was getting build problems so I also swapped the ncc dependency. the other lambdas use
@vercel
, maybe not this version thoThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more than likely correct