@samitouri / QOS-React-2 / commits / 9e8f3c8955

[CI] Use constant commit sha (#20828)

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.

Andrew Clark committed Feb 16, 2021 at 10:31 UTC 9e8f3c89555e4a2a1877c27d710b4d4c1e069014
2 files changed +9 -4
.circleci/config.yml
+2 -2
@@ -579,7 +579,7 @@ workflows:
579 name: Publish to Next channel
580 requires:
581 - setup
582 - commit_sha: master
582 + commit_sha: << pipeline.git.revision >>
583 release_channel: stable
584 dist_tag: next
585 - publish_prerelease:
@@ -590,7 +590,7 @@ workflows:
590 # different versions of the same package, even if they use different
591 # dist tags.
592 - Publish to Next channel
593 - commit_sha: master
593 + commit_sha: << pipeline.git.revision >>
594 release_channel: experimental
595 dist_tag: experimental
596
scripts/release/publish-using-ci-workflow.js
+7 -2
@@ -77,14 +77,19 @@ async function pollUntilWorkflowFinishes(workflowID) {
77 }
78
79 async function main() {
80 + const headCommitResponse = await fetch(
81 + 'https://api.github.com/repos/facebook/react/commits/master'
82 + );
83 + const headCommitJSON = await headCommitResponse.json();
84 + const headCommitSha = headCommitJSON.sha;
85 +
86 const pipelineResponse = await fetch(
87 'https://circleci.com/api/v2/project/github/facebook/react/pipeline',
88 {
89 method: 'post',
90 body: JSON.stringify({
91 parameters: {
86 - // TODO: Make commit SHA configurable
87 - prerelease_commit_sha: 'master',
92 + prerelease_commit_sha: headCommitSha,
93 },
94 }),
95 headers: {