Skip to content

Commit 3bf63b3

Browse files
committed
Switch from fetch() to curl
1 parent 16ec82e commit 3bf63b3

File tree

4 files changed

+68
-9
lines changed

4 files changed

+68
-9
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@babel/preset-env": "^7.25.3",
5555
"@babel/preset-flow": "^7.24.7",
5656
"@electron/packager": "^18.3.6",
57+
"@expo/spawn-async": "^1.7.2",
5758
"@jest/create-cache-key-function": "^29.7.0",
5859
"@microsoft/api-extractor": "^7.52.2",
5960
"@motizilberman/dotslash": "0.5.7-1754587239403",

scripts/releases/upload-release-assets-for-dotslash.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const {Octokit} = require('@octokit/rest');
2121
const {
2222
FIRST_PARTY_DOTSLASH_FILES,
2323
} = require('./write-dotslash-release-asset-urls');
24+
const {getWithCurl} = require('./utils/curl-utils');
2425

2526
const config = {
2627
allowPositionals: true,
@@ -166,14 +167,9 @@ async function uploadReleaseAssetsForDotSlash(
166167
console.log(
167168
`[${targetReleaseAssetInfo.name}] Downloading from ${upstreamUrl}...`,
168169
);
169-
const response = await fetch(upstreamUrl);
170-
if (!response.ok) {
171-
throw new Error(
172-
`Failed to download ${upstreamUrl}: ${response.status} ${response.statusText}`,
173-
);
174-
}
175-
const data = await response.arrayBuffer();
176-
const contentType = response.headers.get('content-type');
170+
// NOTE: Using curl because we have seen issues with fetch() on GHA
171+
// and the Meta CDN. ¯\_(ツ)_/¯
172+
const {data, headers} = await getWithCurl(upstreamUrl);
177173
if (dryRun) {
178174
console.log(
179175
`[${targetReleaseAssetInfo.name}] Dry run: Not uploading to release.`,
@@ -190,7 +186,8 @@ async function uploadReleaseAssetsForDotSlash(
190186
name: targetReleaseAssetInfo.name,
191187
data,
192188
headers: {
193-
'content-type': contentType,
189+
'content-type':
190+
headers['content-type'] ?? 'application/octet-stream',
194191
},
195192
});
196193
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
'use strict';
12+
13+
const {promises: fs} = require('fs');
14+
const spawnAsync = require('@expo/spawn-async');
15+
const os = require('os');
16+
const path = require('path');
17+
18+
/*::
19+
type CurlResult = {
20+
data: Buffer,
21+
headers: {[string]: string},
22+
};
23+
*/
24+
25+
async function getWithCurl(url /*: string */) /*: Promise<CurlResult> */ {
26+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'get-with-curl-'));
27+
const tempFile = path.join(tempDir, 'data');
28+
try {
29+
const {
30+
output: [curlStdout],
31+
} = await spawnAsync(
32+
'curl',
33+
[
34+
'--silent',
35+
'--location',
36+
'--output',
37+
tempFile,
38+
url,
39+
'--write-out',
40+
'%{header_json}',
41+
],
42+
{encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe']},
43+
);
44+
const data = await fs.readFile(tempFile);
45+
const headers = JSON.parse(curlStdout);
46+
return {data, headers};
47+
} finally {
48+
await fs.rm(tempDir, {recursive: true, force: true});
49+
}
50+
}
51+
52+
module.exports = {
53+
getWithCurl,
54+
};

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,13 @@
14111411
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f"
14121412
integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==
14131413

1414+
"@expo/spawn-async@^1.7.2":
1415+
version "1.7.2"
1416+
resolved "https://registry.yarnpkg.com/@expo/spawn-async/-/spawn-async-1.7.2.tgz#fcfe66c3e387245e72154b1a7eae8cada6a47f58"
1417+
integrity sha512-QdWi16+CHB9JYP7gma19OVVg0BFkvU8zNj9GjWorYI8Iv8FUxjOCcYRuAmX4s/h91e4e7BPsskc8cSrZYho9Ew==
1418+
dependencies:
1419+
cross-spawn "^7.0.3"
1420+
14141421
"@fastify/busboy@^2.0.0":
14151422
version "2.1.1"
14161423
resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d"

0 commit comments

Comments
 (0)