nrwl / nx

Smart Monorepos Β· Fast CI
https://nx.dev
MIT License
23.38k stars 2.33k forks source link

nx release not pushing the changes to source-control #22073

Open zoran995 opened 7 months ago

zoran995 commented 7 months ago

Current Behavior

When running nx release in ci without creating a new github release nx won't push the changes to source-control meaning the version change won't be reflected in repo/project package.json, and the commit won't be properly tagged in a git. On subsequent runs of nx release it will try to publish the same version again but it won't be able to overwrite the version on npm. This leads to an entirely broken CI process for us as it is not possible to release new versions, as a workaround we can add git push and git push --tags but that isn't written anywhere in the documentation. Only place mentioning pushing changes is next to the changelog config

Generate a changelog for one or more projects, and optionally push to Github it doesn't mention anything about specific cases in which push will happen

If we set "createRelease": "github" it will push the changes to repo but that works only with github

Expected Behavior

After nx release is run and the new version is generated changes should be pushed to the source control and it should matter if we configured it to generate a changelog or GitHub release, of course, those should be grouped in one commit but the one shouldn't have to think if something is going to break since version change and the tag wasn't pushed to the source control.

Also, I would argue that there shouldn't be a need to configure the user name and email for git, but that should be handled through configuration and set up on ci if not defined already

GitHub Repo

No response

Steps to Reproduce

  1. Create new nx based project
  2. Create a package set the version to i.e. 1.0.0 and commit the changes
  3. Setup the nx release i.e. I used this
    "release": {
    "releaseTagPattern": "release/{version}",
    "projects": ["*", "!private"],
    "version": {
      "conventionalCommits": true
    },
    "git": {
      "commit": true,
      "tag": true,
      "commitMessage": "chore(release): {version} [skip ci]"
    },
    "changelog": {
      "workspaceChangelog": false,
      "projectChangelogs": {
        "renderOptions": {
          "authors": false
        }
      }
    }
    },
  4. run the first release
  5. configure ci to run nx release i.e. I used this to publish to GitHub packages
    jobs:
    main:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v3
        with:
          node-version: 20
          cache: 'npm'
          registry-url: https://npm.pkg.github.com/
      - run: npm ci
      - uses: nrwl/nx-set-shas@v3
      - run: npx nx format:check
      - run: npx nx affected -t build
      - run: git config --global user.email "release-bot<>"
      - run: git config --global user.name "Release bot"
      - run: npx nx release -y --verbose
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
  6. commit the changes as feature commit, feat: configure ci
  7. push the change, it will run the ci which will publish version 1.1.0
  8. observe that there is no push commit anywhere in ci log, also check the source control and notice that there is no commit chore(release): 1.1.0 [skip ci]
  9. create a new fix commit and push the changes
  10. ci is started once again, but now it publishes version 1.1.0 again although we would expect version 1.1.1

Nx Report

Node   : 20.9.0
OS     : darwin-arm64
npm    : 10.1.0

nx                 : 18.0.5
@nx/js             : 18.0.5
@nx/jest           : 18.0.5
@nx/linter         : 18.0.5
@nx/eslint         : 18.0.5
@nx/workspace      : 18.0.5
@nx/devkit         : 18.0.5
@nx/eslint-plugin  : 18.0.5
@nx/react          : 18.0.5
@nrwl/tao          : 18.0.5
@nx/web            : 18.0.5
@nx/webpack        : 18.0.5
typescript         : 5.3.3

Failure Logs

the first run
 NX   Running release version for project: org

org πŸ” Reading data for package "@zoran995/nx-playground-org" from apps/org/package.json
org πŸ“„ Resolved the current version as 1.10.0 from git tag "release/1.10.0".
org πŸ“„ Resolved the specifier as "minor" using git history and the conventional commits standard.
org ✍️  New version 1.11.0 written to apps/org/package.json

UPDATE apps/org/package.json

    "name": "@zoran995/nx-playground-org",
-   "version": "1.10.0",
+   "version": "1.11.0",
    "repository": {

 NX   Updating npm lock file

Updating package-lock.json with the following command:
npm install --package-lock-only

 NX   Staging changed files with git

Staging files in git with the following command:
git add apps/org/package.json package-lock.json

 NX   Generating an entry in apps/org/CHANGELOG.md for release/1.11.0

UPDATE apps/org/CHANGELOG.md

+ ## 1.11.0 (2024-02-29)
+
+
+ ### πŸš€ Features
+
+ - add console.log again1111
+
+
+ ### 🩹 Fixes
+
+ - remove manual push from ci
+
+ - add console.log again
+
+ - removing console.log
+
  ## 1.10.0 (2024-02-29)

the second run 

 NX   Running release version for project: org

org πŸ” Reading data for package "@zoran995/nx-playground-org" from apps/org/package.json
org πŸ“„ Resolved the current version as 1.10.0 from git tag "release/1.10.0".
org πŸ“„ Resolved the specifier as "minor" using git history and the conventional commits standard.
org ✍️  New version 1.11.0 written to apps/org/package.json

UPDATE apps/org/package.json

    "name": "@zoran995/nx-playground-org",
-   "version": "1.10.0",
+   "version": "1.11.0",
    "repository": {

 NX   Updating npm lock file

Updating package-lock.json with the following command:
npm install --package-lock-only

 NX   Staging changed files with git

Staging files in git with the following command:
git add apps/org/package.json package-lock.json

 NX   Generating an entry in apps/org/CHANGELOG.md for release/1.11.0

UPDATE apps/org/CHANGELOG.md

+ ## 1.11.0 (2024-02-29)
+
+
+ ### πŸš€ Features
+
+ - add console.log again1111
+
+
+ ### 🩹 Fixes
+
+ - remove manual push from ci
+
+ - add console.log again
+
+ - removing console.log
+
+ - change console.log message
+
  ## 1.10.0 (2024-02-29)

Package Manager Version

No response

Operating System

Additional Information

No response

melishev commented 5 months ago

This is really very unexpected behavior for me, as someone who just started migrating all repositories: 6 nest.js and vue.js applications and 5 packages for them.

Before that I used semantic-release library in github action for each of the repositories and was happy, here I was expecting to see something similar, but I didn't find an adequate solution in the end.

It seems to me that the nx publish command should have a --CI option, which will automate all the processes described above, and replicate the semantic-release functionality at the expense of the nx functions

jbsouvestre commented 3 months ago

Hello, this is an issue for us because we're on gitlab so we can't set the github release option

Here's the relevant snippet : https://github.com/nrwl/nx/blob/master/packages/nx/src/command-line/release/release.ts#L205-L225

Seems like the gitPush() could be lifted outside the condition of checking if you should create a workspace release (if (shouldCreateWorkspaceRelease && changelogResult.workspaceChangelog) )

Are you accepting PRs regarding this issue ?

lorenyaSICKAG commented 2 months ago

Same problem here.

ccreusat commented 1 week ago

Same here πŸ˜ͺ

aPinix commented 3 days ago

Do you happen to have any news on this? This is a must, and it seems it's not working for some months πŸ˜… Can you please fix this? Thanks in advance

tuga49 commented 3 days ago

Any updates regarding this issue? Thanks