MCPcopy Create free account
hub / github.com/ampproject/amphtml / uploadFiles_

Function uploadFiles_

build-system/release-workflows/upload-release.js:181–225  ·  view source on GitHub ↗

* Uploads release files to Cloudflare R2. * @return {Promise }

()

Source from the content-addressed store, hash-verified

179 * @return {Promise<void>}
180 */
181async 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
227runReleaseJob(jobName, async () => {
228 fs.ensureDirSync(DEST_DIR);

Callers 1

upload-release.jsFile · 0.85

Calls 6

ensureEnvVariable_Function · 0.85
cyanFunction · 0.85
logProgress_Function · 0.85
logFunction · 0.50
pushMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected