Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): programmatic API for nx release #20371

Merged
merged 6 commits into from
Nov 23, 2023

Conversation

JamesHenry
Copy link
Collaborator

@JamesHenry JamesHenry commented Nov 22, 2023

Current Behavior

nx release is intended for CLI usage only, and seamlessly stitching together version and changelog can be challenging.

Expected Behavior

There is a first-class programmatic API for all three nx release commands, and it is straightforward to create scripts which pass data through from version to changelog.

This will also make it much easier to create a meta CLI command in a follow up for easier adoption/smoother DX


Full example of how someone might build on top of this API:

import {
  releaseChangelog,
  releasePublish,
  releaseVersion,
} from "nx/src/command-line/release";
import * as yargs from 'yargs';

(async () => {
  const options = await yargs
    .version(false) // don't use the default meaning of version in yargs
    .option('version', {
      description:
        'Explicit version specifier to use, if overriding conventional commits',
      type: 'string',
    })
    .option('dryRun', {
      alias: 'd',
      description:
        'Whether or not to perform a dry-run of the release process, defaults to true',
      type: 'boolean',
      default: true,
    })
    .option('verbose', {
      description:
        'Whether or not to enable verbose logging, defaults to false',
      type: 'boolean',
      default: false,
    })
    .parseAsync();

  const { workspaceVersion, projectsVersionData } =
    await releaseVersion({
      specifier: options.version,
      // stage package.json updates to be committed later by the changelog command
      stageChanges: true,
      dryRun: options.dryRun,
      verbose: options.verbose,
    });

  await releaseChangelog({
    versionData: projectsVersionData,
    version: workspaceVersion,
    interactive: 'workspace',
    dryRun: options.dryRun,
    verbose: options.verbose,
  });

  await releasePublish({
    dryRun: options.dryRun,
    verbose: options.verbose,
  });

  process.exit(0);
})();

Copy link

vercel bot commented Nov 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Nov 23, 2023 8:21pm

packages/nx/src/devkit-exports.ts Outdated Show resolved Hide resolved
@JamesHenry JamesHenry merged commit 1a994c7 into nrwl:master Nov 23, 2023
6 checks passed
@JamesHenry JamesHenry deleted the nx-release-programmatic branch November 23, 2023 20:50
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants