* Uploads release files to Cloudflare R2. * @return {Promise }
()
| 179 | * @return {Promise<void>} |
| 180 | */ |
| 181 | async function uploadFiles_() { |
| 182 | const [accountId, accessKeyId, secretAccessKey] = ensureEnvVariable_( |
| 183 | 'R2_ACCOUNT_ID', |
| 184 | 'R2_ACCESS_KEY_ID', |
| 185 | 'R2_SECRET_ACCESS_KEY' |
| 186 | ); |
| 187 | |
| 188 | const s3 = new S3({ |
| 189 | region: 'auto', |
| 190 | endpoint: `https://${accountId}.r2.cloudflarestorage.com`, |
| 191 | credentials: { |
| 192 | accessKeyId, |
| 193 | secretAccessKey, |
| 194 | }, |
| 195 | maxAttempts: 7, |
| 196 | }); |
| 197 | |
| 198 | let totalFiles = 0; |
| 199 | for await (const {stats} of klaw(DEST_DIR)) { |
| 200 | if (stats.isFile()) { |
| 201 | totalFiles++; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | log('Uploading', cyan(totalFiles), 'files to R2:'); |
| 206 | const uploadsPromises = []; |
| 207 | let uploadedFiles = 0; |
| 208 | for await (const {path, stats} of klaw(DEST_DIR)) { |
| 209 | if (!stats.isFile()) { |
| 210 | continue; |
| 211 | } |
| 212 | |
| 213 | const key = path.slice(DEST_DIR.length + 1); |
| 214 | uploadsPromises.push( |
| 215 | s3 |
| 216 | .putObject({Bucket: 'ampjs', Key: key, Body: fs.createReadStream(path)}) |
| 217 | .then(() => { |
| 218 | logProgress_(totalFiles, ++uploadedFiles); |
| 219 | }) |
| 220 | ); |
| 221 | } |
| 222 | |
| 223 | await Promise.all(uploadsPromises); |
| 224 | log('Finished uploading all files.'); |
| 225 | } |
| 226 | |
| 227 | runReleaseJob(jobName, async () => { |
| 228 | fs.ensureDirSync(DEST_DIR); |
no test coverage detected