[go: up one dir, main page]

Skip to content

CLI that automates the process of releasing NPM packages using Yarn v2

License

Notifications You must be signed in to change notification settings

meatwallace/yarks

Repository files navigation

📦 yarks

automated package version management and publishing workflow for Yarn v2 (Berry) projects

yarks aims to fill the gap left by semantic-release when using Yarn v2 (Berry), automating a "common" package release workflow that is compatible with both single package repositories and monorepos that are powered by Yarn's workspaces.

⚡ Quick Start

To quickly see how yarks would release your current project:

yarn dlx @yarks/cli release-workspaces

For ongoing usage, it's recommended you add yarks to your dependencies and run it from there:

yarn add @yarks/cli --dev
yarn release-workspaces

When releasing, yarks expects the following environment variables to be set:

export NPM_TOKEN="your NPM token for publishing"
export GITHUB_TOKEN="your GitHub token with push access to your project's repo"
export GIT_AUTHOR_NAME="the name used to author the release commits"
export GIT_AUTHOR_EMAIL="the email used to author the release commits"

By default, yarks will only release packages when ran inside a CI environment. To release locally, this behaviour can be mimiced by setting your CI environment variable to true:

export CI=true
yarn release-workspaces

❓ Why yarks?

yarks automates your release workflow:

  • Processes your commits using conventional-changelog
  • Writes release notes to your workspaces' CHANGELOG.md
  • Bumps your workspaces' versions following the semantic versioning specification
  • Publishes your workspace package updates to the NPM registry
  • Commits your new version and pushes it back to your git repository

🤔 Why not semantic-release?

While semantic-release can be used with any package manager in any repository configuration, there are caveats when used in conjunction with Yarn workspaces that require brittle hacks and workarounds, all of which are incompatible with Yarn v2. yarks is specifically built to address these caveats and offer a robust solution that treats Yarn v2 & workspaces as first-class citizens.

🔬 What problems does yarks solve?

When working in a monorepo, a reliable release strategy requires centralized coordination to ensure workspaces that depend on sibling workspaces are queued for release as needed, and all workspaces are evaluated before final versions are applied and the release process begins.

If workspaces are simply processed and released sequentially, workspaces that depend on sibling workspaces may not be released when they should be, or if they are released, may depend on the incorrect versions of sibling workspaces, potentially introducing errors that would likely be missed by your tests.

💎 What makes yarks different?

Rather than shoehorning Yarn workspaces into another semantic-release-based workaround, yarks addresses the aforementioned issues, avoids any form of brittle integration and uses it's own release strategy, and interfaces with Yarn itself. The initial goal is to create a reliable tool that's been designed with intention and tailored to the problem, rather providing another short-term workaround.

📋 Release Strategy

The process begins by collating workspace and git metadata to determine the release strategy:

  1. Create a list of workspaces including the root of the project, allowing usage with single package repositories and workspace-based monorepos
  2. Filter out workspaces that are flagged as private
  3. For each workspace, find the latest git tag that match the pattern package-name@x.x.x that's available, if any
  4. Parse the commits that modified each workspace since the last release (or the first commit if there is no previous release) using conventional-changelog and determine what type of release is required, if any
  5. Check if each workspace's workspace dependencies have changed, and determine additional releases as required
  6. For each release required, log the release type, new version, and the relevant changes
  7. If on CI, increment workspace versions as needed

When all workspaces have been processed, if we are executing in a CI environment, release each workspace sequentially:

  1. Ammend or write a CHANGELOG.md to the workspace
  2. Publish the workspace to the package registry
  3. Commit and tag the workspace, then push the changes to your remote repository
  4. Publish a GitHub release

🔭 Project Goals

Although yarks is currently a simplistic release automation tool, it's roadmap is positioned towards maturing into a lightweight and flexible Yarn workspaces task runner. At a high level, the development milestones look like:

  1. Release automation: serves as a drop in replacement for semantic-release that accounts for monorepo nuances, with 'essentials' such as changelog generation, semantic versioning, and package publishing
  2. Plugin driven: the initial release strategy is extracted to optional plugins to be used via a streamlined core API and CLI, similar to semantic-release's current architecture
  3. Generic task running: expansion of the core API, CLI, and plugins to facilitate generic task execution with access to workspace related context and convenience APIs

🛠️ Contributing

💬 Code of Conduct

yarks has adopted a Code of Conduct that we expect project participants to adhere to. TODO

📖 Contributing Guide

Read the contributing guide to learn about the development process, how to propose bug fixes and improvements, and how to build and test your changes to yarks

📜 License

All yarks related packages are MIT licensed.

📚 Prior Art