Demo: Nestjs Packages Monorepo Example with Yarn Workspaces and Github Actions
- You need Node.js (>=18)
- Install the dependencies
yarn
- Run build for all packages
yarn build:packages
- Run unit tests for all packages
yarn test:ci:packages
- Run linter for all packages
yarn lint:packages
You can also build, test, lint a single package:
yarn workspace [package_name] build
# Example
yarn workspace @angulartist/utilities build
# Output
PASS test/specs/placeholder.spec.ts
Logger
just test that the tests are testing
✓ dumb test (3 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.487 s, estimated 2 s
Ran all test suites.
In order to publish a package, you have to generate a Github Personal access tokens with read:write packages permissions.
In case you'd like to publish a package from your local environment:
- Export the Github access token to
NPM_TOKEN
env variable
export NPM_TOKEN=[my-github-token]
- Tag a new package version:
Note: this project is using standard-version to automatically bump the package version and to update the changelog.
yarn workspace [package_name] run release:version
git push --follow-tags origin [your_branch]
- Publish the package:
yarn workspace [package_name] run release:publish
You can also publish a pre-release version, while I recommend you to do it from the CI pipeline.
yarn workspace [package_name] run release:version --prerelease next-[commit_hash_short_sha]
You can copy/paste a packages/utilities
package and update the package.json
file accordingly (name, version).
You also have to update the Github workflow to add your new package to the matrix:
# .github/workflow/main.yml - stringify_packages job
# Edit that line
echo "packages={\"names\":[\"@angulartist/utilities\"]}" >> $GITHUB_OUTPUT
This project is using Github workflows/actions to build, lint, test the changes and to automatically release a new version of the packages.
Pushing to the main
branch will result to releasing a new package version.
Pushing to any other branch will result to pre-releasing a new package version with the current branch commit hash.
-
The setup requires that you add a secret at the project level
CI_JOB_TOKEN=[my-github-token]
-
You also have to add an environment variable at the project level
ORG_EMAIL=[my-github-email]
-
You have also to replace the packages' prefix with your own organization in the .github/workflows/main.yml file.