本文档详细介绍了 Gutenberg 仓库中 npm 包的发布流程,包括与 WordPress 核心更新的同步机制。它涵盖了多种发布类型,如 Gutenberg 插件同步、WordPress 发布、开发发布和独立 bugfix 发布,并提供了自动化与手动操作的步骤指南。
# 手动同步 wp/latest 分支的示例命令
git checkout wp/latest
git rm -r .
git checkout release/x.x -- .
git commit -m "Merge changes published in the Gutenberg plugin vX.X release"
git push
# 手动发布 npm 包的示例命令
npx lerna publish --no-private
npx lerna publish patch --no-private --dist-tag wp-5.2
npx lerna publish from-package # 用于恢复不完整的发布过程
# 开发发布安装示例
npm install @wordpress/components@nextThe Gutenberg repository follows the WordPress SVN repository’s branching strategy for every major WordPress release. In addition to that, it also contains two other special branches that control npm publishing workflows:
wp/latest branch contains the same version of packages as those published to npm with the latest distribution tag. The goal here is to have this branch synchronized with the last Gutenberg plugin release, and the only exception would be an unplanned bugfix release.wp/next branch contains the same version of packages as those published to npm with the next distribution tag. It always gets synchronized with the trunk branch. Projects should use those packages for development or testing purposes only.wp/X.Y (example wp/6.2) targeting a specific WordPress major release (including its further minor increments) gets created based on the current Gutenberg plugin release branch release/X.Y (example release/15.1) shortly after the last release planned for inclusion in the next major WordPress release.Release types and their schedule:
latest dist tag) – publishing happens automatically every two weeks based on the newly created release/X.Y (example release/12.8) branch with the RC1 version of the Gutenberg plugin.wp-X.Y dist tag, example wp-6.2) – publishing gets triggered on demand from the wp/X.Y (example wp/6.2) branch. Once we reach the point in the WordPress major release cycle (shortly before Beta 1) where we only cherry-pick commits from the Gutenberg repository to the WordPress core, we use wp/X.Y branch (created from release/X.Y branch, example release/15.1) for npm publishing with the wp-X.Y dist-tag. It’s also possible to use older branches to backport bug or security fixes to the corresponding older versions of WordPress Core.next dist tag) – it is also possible to perform development releases at any time when there is a need to test the upcoming changes.There is also an option to perform Standalone Bugfix Package Releases at will. It should be reserved only for critical bug fixes or security releases that must be published to npm outside of regular cycles.
For each Gutenberg plugin release, we also publish to npm an updated version of WordPress packages. This is automated with the Release Tool that handles releases for the Gutenberg plugin. A successful RC1 release triggers the npm publishing job, and this needs to be approved by a Gutenberg Core team member. Locate the “Build Gutenberg Plugin Zip” workflow for the new version, and have it approved.
We deliberately update the wp/latest branch within the Gutenberg repo with the content from the Gutenberg release release/X.Y (example release/12.7) branch at the time of the Gutenberg RC1 release. This is done to ensure that the wp/latest branch is as close as possible to the latest version of the Gutenberg plugin. It also practically removes the chances of conflicts while backporting to trunk commits with updates applied during publishing to package.json and CHANGELOG.md files. In the past, we had many issues in that aspect when doing npm publishing after the regular Gutenberg release a week later. When publishing the new package versions to npm, we pick at least the minor version bump to account for future bugfix or security releases.
Behind the scenes, all steps are automated via ./bin/plugin/cli.js npm-latest command. For the record, the manual process would look very close to the following steps:
trunk branch is open for enhancements.git fetch.wp/latest branch.git rm -r ..git checkout release/x.x -- ..wp/latest branch with git commit -m "Merge changes published in the Gutenberg plugin vX.X release" and push to the repository.CHANGELOG.md files of the packages with the new publish version calculated and commit to the wp/latest branch. Assuming the package versions are written using this format major.minor.patch, make sure to bump at least the minor version bumps gets applied. For example, if the CHANGELOG of the package to be released indicates that the next unreleased version is 5.6.1, choose 5.7.0 as a version in case of minor version. This is important as the patch version numbers should be reserved in case bug fixes are needed for a minor WordPress release (see below).npm login. Note that you should have 2FA enabled.wp/latest branch, install npm dependencies with npm ci.npx lerna publish --no-private.
npx lerna publish from-package.trunk branch of Gutenberg.The following workflow is needed when bug or security fixes need to be backported into WordPress Core. This can happen in a few use-cases:
beta and RC periods of the WordPress release cycle when wp/X.Y (example wp/5.7) branch for the release is already present.5.1.1).5.2.1, check out wp/5.2).npm run other:cherry-pick script.Now, the wp/X.Y branch is ready for publishing npm packages. In order to start the process, go to Gutenberg’s GitHub repository’s Actions tab, and locate the “Publish npm packages” action. Note the blue banner that says “This workflow has a workflow_dispatch event trigger.”, and expand the “Run workflow” dropdown on its right hand side.

To publish packages to npm for the WordPress major release, select trunk as the branch to run the workflow from (this means that the script used to run the workflow comes from the trunk branch, though the packages themselves will published from the release branch as long as the correct “Release type” is selected below), then select wp from the “Release type” dropdown and enter X.Y (example 5.2) in the “WordPress major release” input field. Finally, press the green “Run workflow” button. It triggers the npm publishing job, and this needs to be approved by a Gutenberg Core team member. Locate the “Publish npm packages” action for the current publishing, and have it approved.
For the record, the manual process would look like the following:
wp/5.2).git pull.npx lerna publish patch --no-private --dist-tag wp-5.2 command (see more in package release process) but when asked for the version numbers to choose for each package, (assuming the package versions are written using this format major.minor.patch) make sure to bump only the patch version number. For example, if the last published package version for this WordPress branch was 5.6.0, choose 5.6.1 as a version.Note: For WordPress 5.0 and WordPress 5.1, a different release process was used. This means that when choosing npm package versions targeting these two releases, you won’t be able to use the next patch version number as it may have been already used. You should use the “metadata” modifier for these. For example, if the last published package version for this WordPress branch was 5.6.1, choose 5.6.1+patch.1 as a version.
CHANGELOG.md files of the published packages with the new released versions and commit to the corresponding branch (Example wp/5.2).trunk branch of Gutenberg.Now, the npm packages should be ready and a patch can be created and committed into the corresponding WordPress SVN branch.
The following workflow is needed when packages require bug fixes or security releases to be published to npm outside of a regular release cycle.
Note: Both the trunk and wp/latest branches are restricted and can only be pushed to by the Gutenberg Core team.
Identify the commit hashes from the pull requests that need to be ported from the repo trunk branch to wp/latest
The wp/latest branch now needs to be prepared to release and publish the packages to npm.
Open a terminal and perform the following steps:
git checkout trunkgit pullgit checkout wp/latestgit pullBefore porting commits check that the wp/latest branch does not have any outstanding packages waiting to be published:
git checkout wp/latestnpx lerna updatedNow cherry-pick the commits from trunk to wp/latest, use -m 1 commithash if the commit was a pull request merge commit:
git cherry-pick -m 1 cb150a2git pushWhilst waiting for the GitHub actions build for wp/latestbranch to pass, identify and begin updating the CHANGELOG.md files:
git checkout wp/latestnpx lerna updatedshell<br />
npx lerna updated<br />
@wordpress/e2e-tests<br />
@wordpress/jest-preset-default<br />
@wordpress/scripts<br />
lerna success found 3 packages ready to publishCheck the versions listed in the current CHANGELOG.md file, looking through the commit history of a package e.g @wordpress/scripts and look out for “chore(release): publish” and “Update changelogs” commits to determine recent version bumps, then looking at the commits since the most recent release should aid with discovering what changes have occurred since the last release.
Note: You may discover the current version of each package is not up to date, if so updating the previously released versions would be appreciated.
Now, the wp/latest branch is ready for publishing npm packages. In order to start the process, go to Gutenberg’s GitHub repository’s Actions tab, and locate the “Publish npm packages” action. Note the blue banner that says “This workflow has a workflow_dispatch event trigger.”, and expand the “Run workflow” dropdown on its right hand side.

To publish packages to npm with bugfixes, select bugfix from the “Release type” dropdown and leave empty “WordPress major release” input field. Finally, press the green “Run workflow” button. It triggers the npm publishing job, and this needs to be approved by a Gutenberg Core team member. Locate the “Publish npm packages” action for the current publishing, and have it approved.
Behind the scenes, the rest of the process is automated with ./bin/plugin/cli.js npm-bugfix command. For the record, the manual process would look very close to the following steps:
wp/latest branch.CHANGELOG.md files of the packages with the new publish version calculated and commit to the wp/latest branch.npm login. Note that you should have 2FA enabled.wp/latest branch, install npm dependencies with npm ci.npx lerna publish --no-private.
npx lerna publish from-package.trunk branch of Gutenberg.As noted in the Synchronizing Gutenberg Plugin section, packages publishing happens every two weeks from the wp/latest branch. It’s also possible to use the development release to test the upcoming changes present in the trunk branch at any time. We are taking advantage of package distribution tags that make it possible to consume the future version of the codebase according to npm guidelines:
By default, the
latesttag is used by npm to identify the current version of a package, andnpm install <pkg>(without any@<version>or@<tag>specifier) installs thelatesttag. Typically, projects only use thelatesttag for stable release versions, and use other tags for unstable versions such as prereleases.
In our case, we use the next distribution tag for code. Developers that want to install such a version of the package need to type:
npm install @wordpress/components@next
In order to start the publishing process for development version of npm packages, go to Gutenberg’s GitHub repository’s Actions tab, and locate the “Publish npm packages” action. Note the blue banner that says “This workflow has a workflow_dispatch event trigger.”, and expand the “Run workflow” dropdown on its right hand side.

To publish development packages to npm, select development from the “Release type” dropdown and leave empty “WordPress major release” input field. Finally, press the green “Run workflow” button. It triggers the npm publishing job, and this needs to be approved by a Gutenberg Core team member. Locate the “Publish npm packages” action for the current publishing, and have it approved.
Behind the scenes, the release process is fully automated via ./bin/plugin/cli.js npm-next command. It ensures
the wp/next branch is synchronized with the latest release branch (release/X.Y) created for the Gutenberg plugin. To avoid collisions in the versioning of packages, we always include the newest commit’s sha, for example, @wordpress/block-editor@5.2.10-next.645224df70.0.