Skip to content

Commit ba5dc6c

Browse files
authored
Add authorization header to artifacts request (#24106)
* Add authorization header to artifacts request CircleCI's artifacts API was updated; it now errors unless you're logged in. This affects any of our workflows that download build artifacts. To fix, I added an authorization header to the request. * Update sizbot to pull artifacts from public mirror We can't use the normal download-build script in sizebot because it depends on the CircleCI artifacts API, which was recently changed to require authorization. And we can't pass an authorization token without possibly leaking it to the public, since we run sizebot on PRs from external contributors. As a temporary workaround, this job will pull the artifacts from a public mirror that I set up. But we should find some other solution so we don't have to maintain the mirror.
1 parent 0412f0c commit ba5dc6c

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

.circleci/config.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,19 @@ jobs:
127127
environment: *environment
128128
steps:
129129
- checkout
130-
- run: yarn workspaces info | head -n -1 > workspace_info.txt
131-
- *restore_node_modules
132130
- run:
133131
name: Download artifacts for base revision
132+
# TODO: We can't use the normal download-build script here because it
133+
# depends on the CircleCI artifacts API, which was recently changed to
134+
# require authorization. And we can't pass an authorization token
135+
# without possibly leaking it to the public, since we run sizebot on
136+
# PRs from external contributors. As a temporary workaround, this job
137+
# will pull the artifacts from a public mirror that I set up. But we
138+
# should find some other solution so we don't have to maintain
139+
# the mirror.
134140
command: |
135-
git fetch origin main
136-
cd ./scripts/release && yarn && cd ../../
137-
scripts/release/download-experimental-build.js --commit=$(git merge-base HEAD origin/main)
138-
mv ./build ./base-build
139-
- run:
140-
# TODO: The `download-experimental-build` script copies the npm
141-
# packages into the `node_modules` directory. This is a historical
142-
# quirk of how the release script works. Let's pretend they
143-
# don't exist.
144-
name: Delete extraneous files
145-
command: rm -rf ./base-build/node_modules
141+
curl -L --retry 60 --retry-delay 10 --retry-max-time 600 https://react-builds.vercel.app/api/commits/$(git merge-base HEAD origin/main)/artifacts/build.tgz | tar -xz
142+
mv ./build ./base-build
146143
147144
- persist_to_workspace:
148145
root: .

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ const {getArtifactsList, logPromise} = require('../utils');
99
const theme = require('../theme');
1010

1111
const run = async ({build, cwd, releaseChannel}) => {
12+
const CIRCLE_TOKEN = process.env.CIRCLE_CI_API_TOKEN;
13+
if (!CIRCLE_TOKEN) {
14+
console.error(
15+
theme.error('Missing required environment variable: CIRCLE_CI_API_TOKEN')
16+
);
17+
process.exit(1);
18+
}
19+
1220
const artifacts = await getArtifactsList(build);
1321
const buildArtifacts = artifacts.find(entry =>
1422
entry.path.endsWith('build.tgz')
@@ -24,7 +32,7 @@ const run = async ({build, cwd, releaseChannel}) => {
2432
// Download and extract artifact
2533
await exec(`rm -rf ./build`, {cwd});
2634
await exec(
27-
`curl -L $(fwdproxy-config curl) ${buildArtifacts.url} | tar -xvz`,
35+
`curl -L $(fwdproxy-config curl) ${buildArtifacts.url} -H "Circle-Token: ${CIRCLE_TOKEN}" | tar -xvz`,
2836
{
2937
cwd,
3038
}

0 commit comments

Comments
 (0)