1- const { S3Client, PutObjectCommand, GetObjectCommand } = require ( '@aws-sdk/client-s3' ) ;
2- const fs = require ( 'fs' ) ;
3- const path = require ( 'path' ) ;
1+ const {
2+ S3Client,
3+ PutObjectCommand,
4+ GetObjectCommand,
5+ } = require ( "@aws-sdk/client-s3" ) ;
6+ const fs = require ( "fs" ) ;
7+ const path = require ( "path" ) ;
48
59const s3Client = new S3Client ( {
6- region : ' auto' ,
7- endpoint : `https:// ${ process . env . R2_ACCOUNT_ID } .r2.cloudflarestorage.com` ,
10+ region : " auto" ,
11+ endpoint : process . env . R2_ENDPOINT ,
812 credentials : {
913 accessKeyId : process . env . R2_ACCESS_KEY_ID ,
1014 secretAccessKey : process . env . R2_SECRET_ACCESS_KEY ,
@@ -18,15 +22,17 @@ const GITHUB_REPO = process.env.GITHUB_REPOSITORY;
1822
1923async function fetchExistingReleases ( ) {
2024 try {
21- const response = await s3Client . send ( new GetObjectCommand ( {
22- Bucket : BUCKET ,
23- Key : 'releases.json' ,
24- } ) ) ;
25+ const response = await s3Client . send (
26+ new GetObjectCommand ( {
27+ Bucket : BUCKET ,
28+ Key : "releases.json" ,
29+ } )
30+ ) ;
2531 const body = await response . Body . transformToString ( ) ;
2632 return JSON . parse ( body ) ;
2733 } catch ( error ) {
28- if ( error . name === ' NoSuchKey' || error . $metadata ?. httpStatusCode === 404 ) {
29- console . log ( ' No existing releases.json found, creating new one' ) ;
34+ if ( error . name === " NoSuchKey" || error . $metadata ?. httpStatusCode === 404 ) {
35+ console . log ( " No existing releases.json found, creating new one" ) ;
3036 return { latestVersion : null , releases : [ ] } ;
3137 }
3238 throw error ;
@@ -37,12 +43,14 @@ async function uploadFile(localPath, r2Key, contentType) {
3743 const fileBuffer = fs . readFileSync ( localPath ) ;
3844 const stats = fs . statSync ( localPath ) ;
3945
40- await s3Client . send ( new PutObjectCommand ( {
41- Bucket : BUCKET ,
42- Key : r2Key ,
43- Body : fileBuffer ,
44- ContentType : contentType ,
45- } ) ) ;
46+ await s3Client . send (
47+ new PutObjectCommand ( {
48+ Bucket : BUCKET ,
49+ Key : r2Key ,
50+ Body : fileBuffer ,
51+ ContentType : contentType ,
52+ } )
53+ ) ;
4654
4755 console . log ( `Uploaded: ${ r2Key } (${ stats . size } bytes)` ) ;
4856 return stats . size ;
@@ -51,44 +59,44 @@ async function uploadFile(localPath, r2Key, contentType) {
5159function findArtifacts ( dir , pattern ) {
5260 if ( ! fs . existsSync ( dir ) ) return [ ] ;
5361 const files = fs . readdirSync ( dir ) ;
54- return files . filter ( f => pattern . test ( f ) ) . map ( f => path . join ( dir , f ) ) ;
62+ return files . filter ( ( f ) => pattern . test ( f ) ) . map ( ( f ) => path . join ( dir , f ) ) ;
5563}
5664
5765async function main ( ) {
58- const artifactsDir = ' artifacts' ;
66+ const artifactsDir = " artifacts" ;
5967
6068 // Find all artifacts
6169 const artifacts = {
62- windows : findArtifacts (
63- path . join ( artifactsDir , 'windows-builds' ) ,
64- / \. e x e $ /
65- ) ,
66- macos : findArtifacts (
67- path . join ( artifactsDir , 'macos-builds' ) ,
68- / - x 6 4 \. d m g $ /
69- ) ,
70+ windows : findArtifacts ( path . join ( artifactsDir , "windows-builds" ) , / \. e x e $ / ) ,
71+ macos : findArtifacts ( path . join ( artifactsDir , "macos-builds" ) , / - x 6 4 \. d m g $ / ) ,
7072 macosArm : findArtifacts (
71- path . join ( artifactsDir , ' macos-builds' ) ,
73+ path . join ( artifactsDir , " macos-builds" ) ,
7274 / - a r m 6 4 \. d m g $ /
7375 ) ,
7476 linux : findArtifacts (
75- path . join ( artifactsDir , ' linux-builds' ) ,
77+ path . join ( artifactsDir , " linux-builds" ) ,
7678 / \. A p p I m a g e $ /
7779 ) ,
7880 } ;
7981
80- console . log ( ' Found artifacts:' ) ;
82+ console . log ( " Found artifacts:" ) ;
8183 for ( const [ platform , files ] of Object . entries ( artifacts ) ) {
82- console . log ( ` ${ platform } : ${ files . length > 0 ? files . map ( f => path . basename ( f ) ) . join ( ', ' ) : 'none' } ` ) ;
84+ console . log (
85+ ` ${ platform } : ${
86+ files . length > 0
87+ ? files . map ( ( f ) => path . basename ( f ) ) . join ( ", " )
88+ : "none"
89+ } `
90+ ) ;
8391 }
8492
8593 // Upload each artifact to R2
8694 const assets = { } ;
8795 const contentTypes = {
88- windows : ' application/x-msdownload' ,
89- macos : ' application/x-apple-diskimage' ,
90- macosArm : ' application/x-apple-diskimage' ,
91- linux : ' application/x-executable' ,
96+ windows : " application/x-msdownload" ,
97+ macos : " application/x-apple-diskimage" ,
98+ macosArm : " application/x-apple-diskimage" ,
99+ linux : " application/x-executable" ,
92100 } ;
93101
94102 for ( const [ platform , files ] of Object . entries ( artifacts ) ) {
@@ -107,7 +115,7 @@ async function main() {
107115 url : `${ PUBLIC_URL } /releases/${ VERSION } /${ filename } ` ,
108116 filename,
109117 size,
110- arch : platform === ' macosArm' ? ' arm64' : ' x64' ,
118+ arch : platform === " macosArm" ? " arm64" : " x64" ,
111119 } ;
112120 }
113121
@@ -122,27 +130,31 @@ async function main() {
122130 } ;
123131
124132 // Remove existing entry for this version if re-running
125- releasesData . releases = releasesData . releases . filter ( r => r . version !== VERSION ) ;
133+ releasesData . releases = releasesData . releases . filter (
134+ ( r ) => r . version !== VERSION
135+ ) ;
126136
127137 // Prepend new release
128138 releasesData . releases . unshift ( newRelease ) ;
129139 releasesData . latestVersion = VERSION ;
130140
131141 // Upload updated releases.json
132- await s3Client . send ( new PutObjectCommand ( {
133- Bucket : BUCKET ,
134- Key : 'releases.json' ,
135- Body : JSON . stringify ( releasesData , null , 2 ) ,
136- ContentType : 'application/json' ,
137- CacheControl : 'public, max-age=60' ,
138- } ) ) ;
139-
140- console . log ( 'Successfully updated releases.json' ) ;
142+ await s3Client . send (
143+ new PutObjectCommand ( {
144+ Bucket : BUCKET ,
145+ Key : "releases.json" ,
146+ Body : JSON . stringify ( releasesData , null , 2 ) ,
147+ ContentType : "application/json" ,
148+ CacheControl : "public, max-age=60" ,
149+ } )
150+ ) ;
151+
152+ console . log ( "Successfully updated releases.json" ) ;
141153 console . log ( `Latest version: ${ VERSION } ` ) ;
142154 console . log ( `Total releases: ${ releasesData . releases . length } ` ) ;
143155}
144156
145- main ( ) . catch ( err => {
146- console . error ( ' Failed to upload to R2:' , err ) ;
157+ main ( ) . catch ( ( err ) => {
158+ console . error ( " Failed to upload to R2:" , err ) ;
147159 process . exit ( 1 ) ;
148160} ) ;
0 commit comments