Releasing Packages to GitHub and the npm Registry
3 min readJun 6, 2023
This publication describes a simple process I follow to tag and release a new package version to GitHub and the npm Registry. I am sharing this publication because I believe others can use this process as a guideline, while modifying certain steps as they see fit.
For simplicity, this publication assumes that you have already published your package on the npm Registry and also assumes that you are working off of at least 2 GitHub branches: develop
and main
. develop
being the branch that is undergoing development, and main
being the production branch.
When you are ready to release a new version of your package, follow the steps below.
- Checkout the
develop
branch and pull latest:git checkout develop && git pull
- Create release branch from the
develop
branch, replacing<YYYY.MM.DD>
with today's date. I.e.2023.06.06
:git checkout -b release/<YYYY.MM.DD>
Note: For multiple releases on the same day, add a hyphen followed by a letter. I.e.release/2023.06.06-b
. - Update
package.json
version, replacing<update_type>
with one of the semantic versioning release types (major, minor, or patch):npm — no-git-tag-version version <update_type>
- Add appropriate release notes to
CHANGELOG.md
file and add version number frompackage.json
file - Commit
CHANGELOG.md
andpackage.json
files, replacing<YYYY.MM.DD>
with today's date. I.e.2023.06.06
:git add -A && git commit -m ‘release <YYYY.MM.DD>’
- Push to origin release branch, replacing
<branch_name>
with the branch name that you created in step 2. I.e.release/2023.06.06
:git push -u origin <branch_name>
- Create pull request from the release branch to the
develop
branch - Merge (without squashing) pull request and delete release branch from GitHub
- Create and merge (without squashing) pull request from the
develop
branch to themain
branch - Checkout the
main
branch locally and pull latest:git checkout main && git pull
Note: It’s good practice to ensure that you are working on a cleanmain
branch. To ensure that you have not made any unexpected changes locally to themain
branch, rungit status
. - Prepare the package for publishing. This includes transpiling or compiling a new distributed build, linting, and compiling assets.
- Create and push tag, replacing
<version_number>
with version number fromCHANGELOG.md
andpackage.json
files:git tag -a v<version_number> -m ‘version <version_number>’ && git push — tags
Note: Take notice of the “v” prefix when creating GitHub tags in the command above. I.e.v1.0.0
. - Log in to your npm Registry account:
npm login
- Publish on the npm Registry:
npm publish — access public
- Checkout the
develop
branch locally and merge themain
branch into it so that the two branches are up-to-date:git checkout develop && git pull && git merge main
Note: It’s good practice to ensure that you are working on a cleandevelop
branch. To ensure that you have not made any unexpected changes locally to thedevelop
branch, rungit status
before merging inmain
. - Push updated
develop
branch to origindevelop
:git push
- And finally, publish a release on GitHub by going to https://github.com/<github-account>/<github-repository>/releases/new, replacing
<github-account>
and<github-repository>
with the appropriate values