Continuous Integration and Deployment
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- scripts/release/README.md
- scripts/release/shared-commands/download-build-artifacts.js
- scripts/release/publish-commands/print-follow-up-instructions.js
- dangerfile.js
- scripts/devtools/README.md
- scripts/devtools/build-and-test.js
- scripts/devtools/prepare-release.js
- packages/react-devtools-extensions/build.js
- fixtures/flight/scripts/build.js
The React repository utilizes a comprehensive Continuous Integration (CI) and Continuous Deployment (CD) system primarily managed through GitHub Actions and a suite of custom release scripts. This system automates builds, tests, and prereleases, while providing a structured, manual process for stable releases. The main goals are to ensure code quality, provide experimental features to collaborators quickly, and manage official releases safely.
The CI process is triggered on every commit pushed to the repository, running workflows like (Runtime) Build and Test to build all release bundles and execute unit tests. The CD process includes automated daily prereleases to NPM's next and experimental channels, as well as a manual path for promoting these prereleases to stable latest versions.
CI/CD Architecture Overview
The CI/CD pipeline is a multi-stage process that begins with a code commit and can end with a published NPM package and browser extension update.
This diagram shows the high-level flow from a code change to a final release.
GitHub Actions Workflows
GitHub Actions are central to the CI process. When a commit is pushed, workflows automatically build and test the code.
(Runtime) Build and Test: This is a core workflow that builds all release bundles and runs unit tests against both the source code and the built bundles. The build artifacts generated by this workflow are essential for subsequent release steps. It is identified in scripts asruntime_build_and_test.yml.
Sources: scripts/release/README.md:21-23, scripts/release/shared-commands/download-build-artifacts.js:14-15- Automated Prereleases: A cron job runs each weekday to publish prereleases from the tip of the
mainbranch to thenextandexperimentalNPM channels. This job can also be triggered manually via the GitHub UI, which requires the commit SHA of a successfully completed(Runtime) Build and Testworkflow.
Sources: scripts/release/README.md:24-27, 40-51
Artifact Handling
Build artifacts are generated by CI and stored for later use, particularly for releases. The download-build-artifacts.js script is responsible for fetching these artifacts from GitHub Actions.
The process involves:
- Identifying the correct workflow run for a given commit SHA.
- Finding the
artifacts_combinedartifact within that run. - Downloading and extracting the artifact.
- Optionally verifying the artifact using
gh attestation verify. - Copying the relevant release channel's build (
oss-stable,oss-experimental, etc.) into thebuild/node_modulesdirectory for publishing.
This diagram illustrates the artifact download flow.
Release Process
The repository distinguishes between automated prereleases and manual stable releases.
Automated Prereleases (next & experimental)
Prereleases are published automatically from the main branch to provide quick access to experimental features.
nextchannel: Contains upcoming stable features.experimentalchannel: Contains experimental features that are not yet ready for stable release.
These are typically published by a daily cron job but can be triggered manually for immediate release.
Sources: scripts/release/README.md:24-27, 65-76
Manual Stable and Patch Releases
Stable releases are always created by promoting a version from the next channel, ensuring that the exact release artifacts have been tested. Patch releases are created from a branch off a previous release tag to minimize the risk of including unintended changes.
Key Release Scripts
A collection of scripts in scripts/release/ facilitates the manual release process.
| Script | Description |
|---|---|
prepare-release-from-ci | Downloads pre-built release artifacts from a specific CI build (commit SHA) for publishing to next or experimental. |
prepare-release-from-npm | Prepares an existing NPM "next" release to be promoted to a "stable" release. It prompts for new version numbers and updates package files accordingly. |
publish.js | Publishes the contents of build/node_modules to NPM with specified tags (e.g., latest, next). Can be run with --dry to see commands without publishing. |
build-release-locally | An escape hatch to build a release from the local Git revision without CI verification. This script does not run any tests. |
print-follow-up-instructions.js | After a successful publish, this script provides instructions for post-release tasks like tagging the commit, updating the changelog, and creating a GitHub release. |
Sources: scripts/release/README.md:34-38, 126-175, scripts/release/publish-commands/print-follow-up-instructions.js:10-107
Stable Release Flow
The following diagram shows the sequence of actions a release engineer performs to publish a stable release.
React DevTools Release Process
The React DevTools have a separate, dedicated release process managed by scripts in scripts/devtools/.
The process is broken into three main steps:
- Prepare a release: Run
./prepare-release.jsto increment version numbers inpackage.jsonandmanifest.jsonfiles, and update theCHANGELOG.md. This script determines changes since the last release commit. - Build and test a release: Run
./build-and-test.jsto download the latest React build from CI, build all DevTools packages (react-devtools-core,react-devtools-inline, extensions), and prompt for manual smoke testing. - Publish a release: Run
./publish-release.jsto publish the packages to NPM and provides instructions for uploading the extensions to the Chrome, Edge, and Firefox stores.
Sources: scripts/devtools/README.md:3-19, scripts/devtools/prepare-release.js, scripts/devtools/build-and-test.js
Pull Request Checks with DangerJS
On every pull request, a DangerJS script (dangerfile.js) runs to provide automated feedback, most notably by checking for changes in production bundle sizes.
Bundle Size Check
The script compares build artifacts from the PR's head commit against the base commit. It calculates the size difference for both raw and gzipped files.
- It reads the
COMMIT_SHAfrombase-build/andbuild/directories. - It finds all
*.jsartifacts in both build directories. - For each artifact, it compares file sizes and gzipped sizes.
- A report is posted as a comment on the PR, highlighting critical and significant size changes.
This flow is visualized below:
Sources: dangerfile.js:70-221
The script defines thresholds for reporting changes:
| Category | Threshold | Description |
|---|---|---|
| Critical | > 2% | Any change greater than 2%, or any change to a predefined list of critical production bundles. |
| Significant | > 0.2% | Any change greater than 0.2%. These are reported in a collapsed section of the comment. |
Sources: dangerfile.js:29-31, 182-209
Conclusion
React's CI/CD infrastructure is a mature system designed for a large-scale open-source project. It effectively balances automation for rapid iteration on experimental features with a cautious, human-gated process for stable releases. The use of GitHub Actions for core build and test cycles, custom scripts for release orchestration, and automated PR checks via DangerJS ensures both development velocity and production stability. The separate, tailored release process for DevTools further demonstrates the system's adaptability to different project components.