Skip to content

feat(release): revamped nx release version implementation #30418

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

Merged
merged 14 commits into from
Apr 8, 2025

Conversation

JamesHenry
Copy link
Collaborator

@JamesHenry JamesHenry commented Mar 18, 2025

This PR provides a new implementation for the versioning stage of nx release which brings a ton of benefits.

Previously unsupported/impossible features now available:

  • It is possible to have dependencies which flow across release group boundaries, therefore updateDependents will work across group boundaries as well.
  • It is possible to update multiple manifests (such as package.json) for a single versioning execution. For example, updating the version and dependencies in both your source and dist package.json for a project.

Massively improved extensibility for non-JS languages/ecosystems:

  • The ReleaseVersionGenerator abstraction was distinctly suboptimal because it required each plugin to reimplement a bunch of core business logic related to resolving tags from git, combining current versions and specifiers to produce new semver values, deleting version plans after use etc.
    • It is now been replaced by the VersionActions class, which exclusively deals with the aspects that make that language/ecosystem unique, such as reading and writing from a manifest file (such as package.json/Cargo.toml etc) if applicable, reading from a remote registry etc.
    • No core business logic about releases is handled within a VersionActions implementation.
    • You can check out the implementation for JS projects here: packages/js/src/generators/release-version/version-actions.ts

Other benefits:

  • More performant
  • Much better IDE experience for version configuration because of the untyped generatorOptions going away, and most options moving to the top level of release.version config in nx.json.
  • More informative logs during versioning, e.g.
    • BEFORE: Resolved the specifier as "minor" using version plans.
    • AFTER: Applied semver relative bump "minor", read from version plan .nx/version-plans/bump-mixed1.md, to get new version 0.2.0
  • Lays the groundwork for application releases becoming a first-class use-case as part of our 2025 Roadmap.
  • preserveLocalDependencyProtocols is now true by default and can be omitted from end user configs.

Notes on rollout

  • In Nx v20, it is opt-in via setting "useLegacyVersioning": false in release.version in nx.json.
  • It will be enabled by default in Nx v21, with opt-out still possible via setting the flag explicitly to true.
  • We will provide an automated migration to the new configuration as part of Nx v21
  • The legacy versioning can now be considered "frozen". Some bugs should be fixed by moving to the new versioning, and any future fixes will be applied there.
  • In Nx v22, the legacy versioning will be entirely removed.
  • Documentation updates will take place in a follow up PR which documents both approaches, whilst making it clear that the legacy versioning is being replaced.

You can see how straightforward it was to manually apply using the PR release from this branch on a real world project here: angular-eslint/angular-eslint#2329


Fixes #21458
Fixes #21466
Fixes #26444
Fixes #27823
Fixes #28049
Fixes #28695
Fixes #30363

Copy link

vercel bot commented Mar 18, 2025

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

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview Apr 8, 2025 0:56am

Copy link
Contributor

nx-cloud bot commented Mar 18, 2025

View your CI Pipeline Execution ↗ for commit 15a27dc.

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 5m 44s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 19s View ↗
nx-cloud record -- nx format:check --base=2fd96... ✅ Succeeded 4s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 3s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗
nx documentation ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-04-08 14:00:57 UTC

@nrwl nrwl deleted a comment from github-actions bot Mar 24, 2025
@JamesHenry JamesHenry marked this pull request as ready for review March 24, 2025 12:49
@JamesHenry JamesHenry requested review from meeroslav, vsavkin, mandarini and a team as code owners March 24, 2025 12:49
export default class JsVersionActions extends VersionActions {
manifestFilename = 'package.json';

static createAfterAllProjectsVersionedCallback(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not a fan of this method name. Is postVersioning callback a better name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is now an exported function as discussed. I couldn't help feeling like afterAllProjectsVersioned is a clearer name because it's not after all of the version logic runs (it's before git for example), so postVersion felt a little ambiguous

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I have indeed been able to flatten it now too and avoid the higher order function

@nrwl nrwl deleted a comment from github-actions bot Mar 27, 2025
@nrwl nrwl deleted a comment from github-actions bot Mar 27, 2025
Copy link
Contributor

🐳 We have a release for that!

This PR has a release associated with it. You can try it out using this command:

npx [email protected] my-workspace

Or just copy this version and use it in your own command:

0.0.0-pr-30418-80f02f7
Release details 📑
Published version 0.0.0-pr-30418-80f02f7
Triggered by @JamesHenry
Branch nx-release-v-v2
Commit 80f02f7
Workflow run 14115494427

To request a new release for this pull request, mention someone from the Nx team or the @nrwl/nx-pipelines-reviewers.

@nrwl nrwl deleted a comment from github-actions bot Mar 27, 2025
Copy link
Contributor

🐳 We have a release for that!

This PR has a release associated with it. You can try it out using this command:

npx [email protected] my-workspace

Or just copy this version and use it in your own command:

0.0.0-pr-30418-6fbe6c1
Release details 📑
Published version 0.0.0-pr-30418-6fbe6c1
Triggered by @JamesHenry
Branch nx-release-v-v2
Commit 6fbe6c1
Workflow run 14135844180

To request a new release for this pull request, mention someone from the Nx team or the @nrwl/nx-pipelines-reviewers.

@CatsMiaow
Copy link

hello.
Could this PR also provide a setting to add a force option to gitPush? Maybe by adding a gitPushArgs option?

image The above error can be solved with force push, but there is no push option provided.

const commandArgs = [
'push',
// NOTE: It's important we use --follow-tags, and not --tags, so that we are precise about what we are pushing
'--follow-tags',
'--no-verify',
'--atomic',
// Set custom git remote if provided
...(gitRemote ? [gitRemote] : []),
];

Scripted, it would look like this
Currently, we have the gitCommitArgs and gitTagsArgs options, but not the gitPushArgs option.

import { releaseVersion } from 'nx/release';

const version = await releaseVersion({
  verbose: true,
  gitTag: true,
  gitTagArgs: [],
  gitCommit: true,
  gitCommitArgs: [],
  gitPush: true,
  gitPushArgs: ['-f'], // or gitPushForce: true
  gitRemote: 'origin',
  firstRelease: true,
});

Copy link
Contributor

github-actions bot commented Apr 8, 2025

🐳 We have a release for that!

This PR has a release associated with it. You can try it out using this command:

npx [email protected] my-workspace

Or just copy this version and use it in your own command:

0.0.0-pr-30418-d6cd6b6
Release details 📑
Published version 0.0.0-pr-30418-d6cd6b6
Triggered by @JamesHenry
Branch nx-release-v-v2
Commit d6cd6b6
Workflow run 14333346914

To request a new release for this pull request, mention someone from the Nx team or the @nrwl/nx-pipelines-reviewers.

@JamesHenry JamesHenry merged commit 7b85d91 into master Apr 8, 2025
12 checks passed
@JamesHenry JamesHenry deleted the nx-release-v-v2 branch April 8, 2025 14:17
Copy link
Contributor

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 Apr 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants