@samitouri / QOS-React-2 / commits / 5b8cf20b38

Add Circle CI API token to request header if available (#26519)

Follow up of #26499 A Circle CI team member got back to me. It is indeed not necessary, but they had a regression not long ago on fetching without token. https://discuss.circleci.com/t/is-api-token-required-when-fetching-artifacts/47606/5 To mitigate the impact of this kind of issues, let's add this token to requests' header when it's available.

Mengdi Chen committed Mar 30, 2023 at 16:06 UTC 5b8cf20b388c014ae3d0cdbde6ffc1ed7667db89
2 files changed +13 -2
scripts/release/shared-commands/download-build-artifacts.js
+7 -1
@@ -22,9 +22,15 @@ const run = async ({build, cwd, releaseChannel}) => {
22 }
23
24 // Download and extract artifact
25 + const {CIRCLE_CI_API_TOKEN} = process.env;
26 + let header = '';
27 + // Add Circle CI API token to request header if available.
28 + if (CIRCLE_CI_API_TOKEN != null) {
29 + header = '-H "Circle-Token: ${CIRCLE_CI_API_TOKEN}" ';
30 + }
31 await exec(`rm -rf ./build`, {cwd});
32 await exec(
27 - `curl -L $(fwdproxy-config curl) ${buildArtifacts.url} | tar -xvz`,
33 + `curl -L $(fwdproxy-config curl) ${buildArtifacts.url} ${header}| tar -xvz`,
34 {
35 cwd,
36 }
scripts/release/utils.js
+6 -1
@@ -59,8 +59,13 @@ const extractCommitFromVersionNumber = version => {
59 };
60
61 const getArtifactsList = async buildID => {
62 + const headers = {};
63 + const {CIRCLE_CI_API_TOKEN} = process.env;
64 + if (CIRCLE_CI_API_TOKEN != null) {
65 + headers['Circle-Token'] = CIRCLE_CI_API_TOKEN;
66 + }
67 const jobArtifactsURL = `https://circleci.com/api/v1.1/project/github/facebook/react/${buildID}/artifacts`;
63 - const jobArtifacts = await fetch(jobArtifactsURL);
68 + const jobArtifacts = await fetch(jobArtifactsURL, {headers});
69 return jobArtifacts.json();
70 };
71