1
1
import { Octokit } from '@octokit/rest' ;
2
2
import { PassThrough } from 'stream' ;
3
3
import request from 'request' ;
4
- import { S3 } from 'aws-sdk' ;
5
- import AWS from 'aws-sdk' ;
4
+ import { S3 , Tag } from '@ aws-sdk/client-s3 ' ;
5
+ import { Upload } from '@ aws-sdk/lib-storage ' ;
6
6
import yn from 'yn' ;
7
7
8
8
const versionKey = 'name' ;
@@ -14,14 +14,12 @@ interface CacheObject {
14
14
15
15
async function getCachedVersion ( s3 : S3 , cacheObject : CacheObject ) : Promise < string | undefined > {
16
16
try {
17
- const objectTagging = await s3
18
- . getObjectTagging ( {
19
- Bucket : cacheObject . bucket ,
20
- Key : cacheObject . key ,
21
- } )
22
- . promise ( ) ;
23
- const versions = objectTagging . TagSet ?. filter ( ( t : S3 . Tag ) => t . Key === versionKey ) ;
24
- return versions . length === 1 ? versions [ 0 ] . Value : undefined ;
17
+ const objectTagging = await s3 . getObjectTagging ( {
18
+ Bucket : cacheObject . bucket ,
19
+ Key : cacheObject . key ,
20
+ } ) ;
21
+ const versions = objectTagging . TagSet ?. filter ( ( t : Tag ) => t . Key === versionKey ) ;
22
+ return versions ?. length === 1 ? versions [ 0 ] . Value : undefined ;
25
23
} catch ( e ) {
26
24
console . debug ( 'No tags found' ) ;
27
25
return undefined ;
@@ -65,12 +63,16 @@ async function getReleaseAsset(
65
63
66
64
async function uploadToS3 ( s3 : S3 , cacheObject : CacheObject , actionRunnerReleaseAsset : ReleaseAsset ) : Promise < void > {
67
65
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 ( ) ;
66
+ const upload = new Upload ( {
67
+ client : s3 ,
68
+ params : {
69
+ Bucket : cacheObject . bucket ,
70
+ Key : cacheObject . key ,
71
+ Tagging : `${ versionKey } =${ actionRunnerReleaseAsset . name } ` ,
72
+ Body : writeStream ,
73
+ } ,
74
+ } ) ;
75
+ const uploadPromise = upload . done ( ) ;
74
76
75
77
await new Promise < void > ( ( resolve , reject ) => {
76
78
console . debug ( 'Start downloading %s and uploading to S3.' , actionRunnerReleaseAsset . name ) ;
@@ -87,10 +89,11 @@ async function uploadToS3(s3: S3, cacheObject: CacheObject, actionRunnerReleaseA
87
89
} ) . catch ( ( error ) => {
88
90
console . error ( `Exception: ${ error } ` ) ;
89
91
} ) ;
92
+ await uploadPromise ;
90
93
}
91
94
92
95
export const handle = async ( ) : Promise < void > => {
93
- const s3 = new AWS . S3 ( ) ;
96
+ const s3 = new S3 ( ) ;
94
97
95
98
const fetchPrereleaseBinaries = yn ( process . env . GITHUB_RUNNER_ALLOW_PRERELEASE_BINARIES , { default : false } ) ;
96
99
const distributions = [
@@ -131,7 +134,7 @@ export const handle = async (): Promise<void> => {
131
134
const currentVersion = await getCachedVersion ( s3 , cacheObject ) ;
132
135
console . debug ( 'latest: ' + currentVersion ) ;
133
136
if ( currentVersion === undefined || currentVersion != actionRunnerReleaseAsset . name ) {
134
- uploadToS3 ( s3 , cacheObject , actionRunnerReleaseAsset ) ;
137
+ await uploadToS3 ( s3 , cacheObject , actionRunnerReleaseAsset ) ;
135
138
} else {
136
139
console . debug ( 'Distribution is up-to-date, no action.' ) ;
137
140
}
0 commit comments