Skip to content

Commit

Permalink
[CI] Use constant commit sha (facebook#20828)
Browse files Browse the repository at this point in the history
When running the publish workflow, either via the command line or
via the daily cron job, we should use a constant SHA instead of
whatever happens to be at the head of the main branch at the time the
workflow is run.

The difference is subtle: currently, the SHA is read at runtime,
each time the workflow is run. With this change, the SHA is read right
before the workflow is created and passed in as a constant parameter.

In practical terms, this means if a workflow is re-run via the CircleCI
web UI, it will always re-run using the same commit SHA as the original
workflow, instead of fetching the latest SHA from GitHub, which may
have changed.

Also avoids a race condition where the head SHA changes in between the
Next publish job and the Experimental publish job.
  • Loading branch information
acdlite authored and koto committed Jun 15, 2021
1 parent 338a4e6 commit 884d11c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ workflows:
name: Publish to Next channel
requires:
- setup
commit_sha: master
commit_sha: << pipeline.git.revision >>
release_channel: stable
dist_tag: next
- publish_prerelease:
Expand All @@ -590,7 +590,7 @@ workflows:
# different versions of the same package, even if they use different
# dist tags.
- Publish to Next channel
commit_sha: master
commit_sha: << pipeline.git.revision >>
release_channel: experimental
dist_tag: experimental

9 changes: 7 additions & 2 deletions scripts/release/publish-using-ci-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,19 @@ async function pollUntilWorkflowFinishes(workflowID) {
}

async function main() {
const headCommitResponse = await fetch(
'https://api.github.com/repos/facebook/react/commits/master'
);
const headCommitJSON = await headCommitResponse.json();
const headCommitSha = headCommitJSON.sha;

const pipelineResponse = await fetch(
'https://circleci.com/api/v2/project/github/facebook/react/pipeline',
{
method: 'post',
body: JSON.stringify({
parameters: {
// TODO: Make commit SHA configurable
prerelease_commit_sha: 'master',
prerelease_commit_sha: headCommitSha,
},
}),
headers: {
Expand Down

0 comments on commit 884d11c

Please sign in to comment.