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

How to handle release/prerelease with nx release ? #28362

Open
1 of 4 tasks
ccreusat opened this issue Oct 8, 2024 · 3 comments
Open
1 of 4 tasks

How to handle release/prerelease with nx release ? #28362

ccreusat opened this issue Oct 8, 2024 · 3 comments

Comments

@ccreusat
Copy link

ccreusat commented Oct 8, 2024

Current Behavior

I'm trying to manage a monorepo and release packages with nx release.
While it's working very well locally (on my machine), I can't easily manage the version/publish in CI/CD.

There is no documentation in the recipes (Recipes > nx release) and my attempts are not so great.

My current nx.json config for release is:

"release": {
    "projects": [
      "packages/*"
    ],
    "releaseTagPattern": "{version}",
    "git": {
      "commitMessage": "chore: version and publish v{version}",
      "commit": true,
      "tag": true,
      "push": true
    },
    "changelog": {
      "workspaceChangelog": {
        "createRelease": "github",
        "file": false
      }
    },
    "version": {
      "preVersionCommand": "pnpm dlx nx run-many -t build",
      "generatorOptions": {
        "packageRoot": "packages/{projectName}/dist",
        "currentVersionResolver": "git-tag",
        "skipLockFileUpdate": true,
        "specifierSource": "conventional-commits"
      }
    }
  },

and I have this github workflow to version and publish

if [ ${{ github.ref_name }} = "main" ]; then
          echo "This is the main branch."
          pnpm nx release --first-release --skip-publish
          pnpm nx release publish --output-style=stream
        else
          echo "This is not the main branch."
          pnpm nx release --skip-publish
          pnpm nx release publish --tag ${{ github.ref_name }} --output-style=stream
  • If there is nothing to version, nx release publish will try to publish and I get an error -> seems right
  • If there are changes, a new version is created and publishing is working correctly -> seems right too

But I have some issues so:

  • How can I version in CI/CD following conventional commits and publish ONLY IF there is a change ?
  • How release/prerelease should be done with nx release in CI/CD ?

For example:

  • I need release on the main branch and prerelease on the develop branch
  • If I merge develop into main, nx release doesn't detect changes
my-lib 🔍 Reading data for package "@ccreusat/my-lib" from packages/my-lib/dist/package.json
my-lib 📄 Using the current version 0.3.2-develop.6 already resolved from git tag "0.3.2-develop.6".
my-lib 🚫 Skipping versioning "@ccreusat/my-lib" as no changes were detected.

Expected Behavior

What I am expecting is:

  • If there is nothing to version, nx release publish should not be triggered
    • I can version with nx release version --specifier prerelease but for some reason, git tags are not pushed to remote.
  • If there are changes, a new version is created and publishing is working correctly
  • If I'm doing a prerelease on the develop branch, when I'm merging into main, CI/CD should trigger a version and a publish with a stable/latest version

We should have something like semantic release to configure in nx.json (or maybe there is already a solution)

{
  branches: [
    { name: "main" },
    { name: "develop", prerelease: true }
  ];
}

GitHub Repo

https://github.com/ccreusat/ccreusat-package-based

Steps to Reproduce

  1. Clone the repo
  2. Use nx release --dry-run on the main branch
  3. No changes are detected on the main branch, nx will find tag coming from develop
my-lib 🔍 Reading data for package "@ccreusat/my-lib" from packages/my-lib/dist/package.json
my-lib 📄 Using the current version 0.3.2-develop.6 already resolved from git tag "0.3.2-develop.6".
my-lib 🚫 Skipping versioning "@ccreusat/my-lib" as no changes were detected.
  1. Add a new component in one of the react packages
  2. Commit changes with fix | feat type
  3. Use nx release --dry-run on the main branch
  4. Detect changes with conventional commit but will tag 0.3.2-develop.7 instead of 0.3.2

Nx Report

 NX   Report complete - copy this into the issue template

Node           : 20.12.1
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 9.4.0

nx (global)        : 19.8.0
nx                 : 19.8.4
@nx/js             : 19.8.4
@nx/eslint         : 19.8.4
@nx/eslint-plugin  : 19.8.4
@nx/react          : 19.8.4
@nrwl/tao          : 19.8.0
@nx/vite           : 19.8.4
@nx/web            : 19.8.4
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/vite/plugin
---------------------------------------

Failure Logs

No response

Package Manager Version

[email protected]

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@jaysoo jaysoo removed their assignment Oct 14, 2024
@yonitou
Copy link

yonitou commented Jan 6, 2025

Completely aligned with it. NX Release doesn't work if having for example a staging branch for prerelease and a production branch for release. No changes are detected when merging one into another and it's blocking us migrating from semantic-release
@jaysoo, do you think it will be possible to have it someday ?

@BrendanThysse
Copy link

Any feedback on this as I want to migrate to nx release from @jscutlery/semver:version but unfortunately need to prerelease per feature branch and production release for master/main branch

@sk-tjdownes
Copy link

Completely agree here. Versioning in nx and @jscutlery/semver both base versioning and releases from tags. Tags are not a dependable source of versioning, because they can change easily. It also makes a next/main versioning process impossible, and least in my understanding.

Taking a page from https://github.com/semantic-release
semantic-release, my firm belief is that versioning should be done by using git history, with conventional commits being the driver.

I'd like to understand why Nx doesn't use the git history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants