Beachball Documentation

repository·main·Indexed 21 days ago

https://github.com/microsoft/beachball

Beachball is a version bumping tool for managing dependency updates and releases. It provides a CLI for bumping versions, generating changelogs, and publishing to npm, alongside GitHub Actions for automating release workflows, such as checking for modified files and determining if a release is necessary. It also includes a github-app-token tool for minting GitHub App installation tokens using Azure Key Vault.

Tokens
53K
Snippets
137
Records
230
Agent score
73%

What's inside Beachball

  1. Overview of @microsoft/esrp-npm-release

    main

    The @microsoft/esrp-npm-release tool is a CLI designed for Microsoft teams to release npm packages to ESRP in dependency-topological order. This ensures that a package's internal dependencies are published before the package itself, preventing dangling references and installation failures in consuming repositories.

    How it works

    The tool is a bundled CLI (dist/index.mjs) intended to be run during a release job. It does not calculate dependency order itself; instead, it expects a directory of "packed packages" organized into numbered dependency layers. For each layer, the tool:

    1. Zips the layer's package tarballs.
    2. Uploads the zip to a temporary "staging" Azure Blob Storage account.
    3. Calls the ESRP release API to publish the layer and waits for completion.
    4. Deletes the staged zip (with an automated lifecycle policy fallback).

    When to use this tool

    • Use it when: You have a large monorepo or many packages where publishing order is critical to prevent broken dependencies.
    • Do NOT use it when: You are managing single packages or small monorepos where the official EsrpRelease task is simpler, or if you prefer manual grouping.
  2. Overview of Beachball features

    main

    Beachball is a tool designed to automate npm publishing. Key capabilities include:

    • Synchronized Versioning: Keeps Git and npm versions in sync across CI and local workflows.
    • Changelog Generation: Automatically generates changelogs for users during the versioning process.
    • Automated Semver Bumps: Provides a single command-line interface to bump package versions using semantic versioning.
    • Flexible Workspace Support: Works out of the box for both single-package repositories and monorepos.
    • Pre-Publish Validation: Performs checks against the Git repository and the npm registry before publishing to ensure safety.
    • Zero Config: Can be used immediately with no initial configuration required.
  3. Create GitHub App installation tokens via Azure Key Vault

    main

    The github-app-token tool allows you to mint GitHub App installation tokens by signing a GitHub App JWT using an Azure Key Vault key. This approach improves security because the GitHub App private key is stored only within Azure Key Vault and is never exposed as a secret in GitHub Actions, Azure Pipelines, or your repository. The tool uses the Azure CLI (az keyvault key sign) to perform the signing operation.

    Prerequisites

    1. GitHub App: Create a GitHub App and install it on the target repository. Note the Client ID (distinct from the App ID).
    2. Private Key: Generate a private key for the app and save it locally.
    3. Azure Key Vault: Import the private key into an Azure Key Vault as a key supporting the RS256 sign operation.
    4. Authentication: Ensure the environment running the CLI (local machine via az login or Azure Pipelines via AzureCLI@2 task) has permission to perform the sign operation on the Key Vault key.
    node github-app-token.mjs create --app-client-id "YOUR_CLIENT_ID" --key-id "https://my-vault.vault.azure.net/keys/my-github-app-key" --repository "owner/repo"
  4. How the beachball-change-file skill works

    main

    The beachball-change-file skill is designed to guide AI agents through the change file generation process without using the interactive beachball change CLI.

    Workflow:

    1. The agent uses the skill's instructions to identify which packages have changed.
    2. The agent analyzes the diffs for each package.
    3. The agent generates a change file manually, assigning the correct type and comment to each package (while respecting configuration settings like disallowedChangeTypes).

    Why use the skill instead of the CLI? The beachball change command is limited because it only accepts a single --type and --message. Applying one type to all packages is often inaccurate, and running the command multiple times with --package would result in multiple separate change files instead of a single consolidated one. The skill allows the agent to create a single, high-quality change file containing multiple distinct package entries.

  5. Limitations of yarn-plugin-npmrc

    main

    The plugin uses @npmcli/config to read effective npm configurations (including process.env.NPM_CONFIG_*, project, user, and global configs), but has the following limitations:

    • CLI Arguments: CLI arguments are not respected to avoid interfering with Yarn's own processing.
    • Environment Variables: Variable replacement only supports variables from the actual process environment. It does not support variables that npm would normally inject into the environment.
    • Auth Methods: Certificate or key-based authentication (certfile, keyfile) is not supported.
  6. Understand the Beachball workflow

    main

    Beachball automates the process of tracking changes, bumping versions, and publishing to npm. The workflow consists of three main stages:

    1. Inner Loop: As you make commits, run beachball change to generate change files that describe your work.
    2. Pull Request: During the PR phase, beachball check is used to verify that the necessary change files are present. This allows reviewers to validate the change types and descriptions before merging.
    3. Publish: When releasing, beachball publish (triggered via CI or manually) performs the following atomic operations:
      • Deletes all processed change files.
      • Bumps package versions, commits them locally, and pushes them to the remote repository.
      • Publishes the npm packages to a registry.

    This cycle ensures that your git repository, changelogs, and npm registry remain in sync.

  7. Understand shouldPublish behavior in v3

    main

    The shouldPublish option is largely redundant with setting private: true in package.json. In v3, packages with shouldPublish: false are full participants in the workflow except for the final npm publish (or pack) step.

    Behavior for shouldPublish: false packages:

    • Change files are generated and required.
    • Version bumps, git tags, and changelogs are produced.
    • The final npm publish step is skipped.
    • If a published package has a shouldPublish: false package in its production dependencies, Beachball will exit with an error.

    Note: beachball migrate will report shouldPublish: false as an error to encourage using private: true instead.

  8. Storage Account and Managed Identity Details

    main

    The staging setup uses a storage account with specific configurations for security and automation:

    Containers

    • staging: Temporarily hosts zipped layers. Blobs are cleaned up by a lifecycle policy after 3 days (or immediately after successful release).
    • release-state: Persists retry state so ADO pipeline retries can resume. Blobs are cleaned up after 90 days.

    Required RBAC Roles

    The User-Assigned Managed Identity must be assigned the following data-plane roles at the storage account scope. Control-plane roles like Contributor are not sufficient:

    1. Storage Blob Data Contributor: Allows listing, reading, writing, and deleting blobs in staging and release-state.
    2. Storage Blob Delegator: Allows the identity to mint short-lived user-delegation SAS tokens used by ESRP to download artifacts.

    Note: RBAC propagation can take several minutes. If you encounter 403 errors immediately after setup, wait a few minutes and retry.

    Security Compliance

    Storage account keys and public blob access are disabled. Access is managed via Entra ID authentication and short-lived user delegation SAS URLs, complying with Microsoft's Safe Secrets Standard (SFI-ID4.2.1).

  9. What are change files in beachball?

    main

    Unlike tools that rely on commit messages for versioning, beachball uses change files to manage package versioning and changelog generation.

    Change files are .json files located in the /change directory of your repository. They contain metadata about a change, including a description, the change type (e.g., minor), the package name, and the author's email.

    Advantages:

    • Reviewability: Change files provide clear visual diffs in Pull Requests, allowing reviewers to verify the change type and message easily.
    • Flexibility: Authors can modify a change file to correct a change type without needing to amend git history.

    In a monorepo, you can enable groupChanges: true in your beachball configuration to consolidate change information for all changed packages on a branch into a single change file.

    {
      "comment": "Upgrading React to 16.8.x to use hooks",
      "type": "minor",
      "packageName": "my-amazing-app",
      "email": "me@me.me"
    }
  10. Generate a markdown changelog with proper-changelog

    main
    The proper-changelog tool is used to generate a single, unified markdown changelog by reading GitHub releases. This is useful for tracking changes across multiple versions or identifying when specific changes were introduced, which can be difficult when relying solely on individual GitHub releases.
  11. Scope package consideration

    main

    The scope option limits which packages Beachball considers. This can be set in the repository configuration or via the command line.

    • Configuration: Accepts a list of patterns matched against package paths. Patterns are relative to the monorepo root and use forward slashes. Unlike ignorePatterns, negations are supported (similar to .gitignore).
    • CLI: Use --scope 'pattern' for each pattern you want to include or exclude.

    Example: To only consider packages under packages/foo but exclude packages/foo/bar:

    {
      "scope": ["packages/foo/*", "!packages/foo/bar"]
    }

    Note: If you use multiple different scopes in a repository, groupChanges is not supported.

  12. Authenticate with the GitHub API in proper-changelog

    main

    To avoid GitHub API rate limits, provide authentication. The tool checks for a token in the following order:

    1. The --token <token> CLI option.
    2. The GITHUB_TOKEN or GH_TOKEN environment variables.
    3. The output of gh auth token (if the GitHub CLI is installed and authenticated).

    If no token is found, the tool will print a warning and attempt to continue unauthenticated.