5. Some automation magic using the (Lerna) CLI
2 min read
This page is part of The toolkit I needed to make it all happen list - 5/7
To avoid the hassle of manually managing versioning and publishing, I set up a straightforward GitHub Actions workflow to automate these processes for me:
This GitHub Actions workflow, defined in .github/workflows/release.yml
, automates the process of versioning and publishing our packages to NPM whenever changes are pushed to the main
branch affecting any files within the packages/**
directory.
Here's what each step accomplishes:
Checkout Repository Uses the
actions/checkout@v4
action to check out your repository code, making it accessible to the workflow. Thefetch-depth: 0
option ensures the entire commit history is available, which is crucial for Lerna to accurately determine version changes.Setup Node.js The
actions/setup-node@v4
action prepares the environment by setting up the Node.js version specified in the.nvmrc
file. It also caches NPM dependencies to speed up the build process in future runs.Configure Git Configures Git with the user name and email stored in your GitHub secrets. This information is used for commit operations performed by Lerna during the versioning process.
GitHub Package Registry Identity Sets up authentication for the GitHub Package Registry by writing the GitHub token to
.npmrc
. This step ensures that the workflow can publish packages to the GitHub Package Registry under your account.Install Dependencies Runs
npm ci
to install the project dependencies based on thepackage-lock.json
file. This command is preferred for continuous integration workflows as it installs dependencies faster and more reliably thannpm install
.Build Executes the
npm run build
command to build the project. This step compiles the source code into an executable format before publishing.Lerna Publish: Finally, the
lerna publish --yes
command, run only if all previous steps have succeeded, publishes the updated packages to NPM. The--yes
flag automates the confirmation process, allowing Lerna to proceed without manual intervention. The environment variablesCI
,GH_TOKEN
, andNPM_TOKEN
are set to ensure Lerna can operate in the CI environment and authenticate with NPM and GitHub Package Registry as needed.
Moving beyond automation with Lerna's CLI, next up we explore the process of validating changes in our packages—how we ensure that updated packages integrate smoothly within exile.watch, whether through local bumps or prereleases.
Last updated