Skip to content

Commit df892eb

Browse files
committed
Make getWithCurl compatible with older curl
Summary: We were using `--write-out %{header_json}` but this feature requires curl 7.83.0. Some of our CI environments have an older version of curl so we need a different approach.
1 parent 5b02181 commit df892eb

4 files changed

Lines changed: 11 additions & 10 deletions

File tree

scripts/releases/__tests__/__snapshots__/upload-release-assets-for-dotslash-test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Array [
138138
]
139139
`;
140140
141-
exports[`uploadReleaseAssetsForDotSlashFile fails loudly if the upstream asset is unreachable 1`] = `"curl --silent --location --output <CURL_TEMP_DIR>/data <serverUrl>/error --write-out %{header_json} --fail exited with non-zero code: 22"`;
141+
exports[`uploadReleaseAssetsForDotSlashFile fails loudly if the upstream asset is unreachable 1`] = `"curl --silent --location --output <CURL_TEMP_DIR>/data <serverUrl>/error --write-out %{content_type} --fail exited with non-zero code: 22"`;
142142
143143
exports[`uploadReleaseAssetsForDotSlashFile fails loudly if the upstream asset is unreachable: console.log calls 1`] = `
144144
Array [

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,12 @@ async function fetchAndValidateUpstreamAsset(
328328
console.log(`[${name}] Downloading from ${url}...`);
329329
// NOTE: Using curl because we have seen issues with fetch() on GHA
330330
// and the Meta CDN. ¯\_(ツ)_/¯
331-
const {data, headers} = await getWithCurl(url);
331+
const {data, contentType} = await getWithCurl(url);
332332
console.log(`[${name}] Validating download...`);
333333
await validateDotSlashArtifactData(data, artifactInfo);
334334
return {
335335
data,
336-
contentType: headers['content-type']?.[0] ?? 'application/octet-stream',
336+
contentType: contentType ?? 'application/octet-stream',
337337
};
338338
}
339339

scripts/releases/utils/__tests__/curl-utils-test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ describe('getWithCurl', () => {
5050
test('success', async () => {
5151
await expect(getWithCurl(serverUrl)).resolves.toEqual({
5252
data: Buffer.from('Hello World\n'),
53-
headers: expect.objectContaining({
54-
'content-type': ['text/plain'],
55-
}),
53+
contentType: 'text/plain',
5654
});
5755
});
5856

scripts/releases/utils/curl-utils.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const path = require('path');
1818
/*::
1919
type CurlResult = {
2020
data: Buffer,
21-
headers: {[string]: Array<string>},
21+
contentType?: string,
2222
};
2323
*/
2424

@@ -37,14 +37,17 @@ async function getWithCurl(url /*: string */) /*: Promise<CurlResult> */ {
3737
tempFile,
3838
url,
3939
'--write-out',
40-
'%{header_json}',
40+
'%{content_type}',
4141
'--fail',
4242
],
4343
{encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe']},
4444
);
4545
const data = await fs.readFile(tempFile);
46-
const headers = JSON.parse(curlStdout);
47-
return {data, headers};
46+
const contentType = curlStdout.trim();
47+
if (contentType === '') {
48+
return {data};
49+
}
50+
return {data, contentType};
4851
} finally {
4952
await fs.rm(tempDir, {recursive: true, force: true});
5053
}

0 commit comments

Comments
 (0)