Skip to content

Commit 5b8cf20

Browse files
authored
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.
1 parent 73deff0 commit 5b8cf20

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

scripts/release/shared-commands/download-build-artifacts.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ const run = async ({build, cwd, releaseChannel}) => {
2222
}
2323

2424
// 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+
}
2531
await exec(`rm -rf ./build`, {cwd});
2632
await exec(
27-
`curl -L $(fwdproxy-config curl) ${buildArtifacts.url} | tar -xvz`,
33+
`curl -L $(fwdproxy-config curl) ${buildArtifacts.url} ${header}| tar -xvz`,
2834
{
2935
cwd,
3036
}

scripts/release/utils.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ const extractCommitFromVersionNumber = version => {
5959
};
6060

6161
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+
}
6267
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});
6469
return jobArtifacts.json();
6570
};
6671

0 commit comments

Comments
 (0)