Skip to content

fix(release): scope fallback to project history for new packages#35323

Open
zanlucathiago wants to merge 1 commit intonrwl:masterfrom
zanlucathiago:fix/release-first-project-commit-fallback
Open

fix(release): scope fallback to project history for new packages#35323
zanlucathiago wants to merge 1 commit intonrwl:masterfrom
zanlucathiago:fix/release-first-project-commit-fallback

Conversation

@zanlucathiago
Copy link
Copy Markdown

@zanlucathiago zanlucathiago commented Apr 17, 2026

Current Behavior

Closes #35327

When a project has no release tags (e.g., newly added to a monorepo), nx release falls back to getFirstGitCommit() — the very first commit in the entire repository. This means git log <first-commit>..HEAD scans every commit ever made, regardless of whether they are relevant to the new project.

In large monorepos this causes:

  1. Severe performance degradation — the release step can take 5+ minutes just scanning irrelevant history
  2. Noisy warnings"The affected projects might have not been identified properly. The package(s) X were not found" for every old/renamed/removed package referenced in ancient commits
  3. CI timeouts — the cumulative overhead can push pipelines past their timeout limits

Reproduction

  1. Create a monorepo with release.changelog.automaticFromRef: true and release.version.conventionalCommits: true
  2. Have a long git history (1000+ commits) with commits referencing packages that no longer exist
  3. Add a new package to the workspace
  4. Run nx release --skip-publish
  5. Observe it scanning the entire git history and logging warnings for every unresolvable package reference

Expected Behavior

For new packages without release tags, nx release should only scan commits since the project was first introduced — not the entire repository history.

Implementation

Adds getFirstProjectCommit(projectRoot) in utils/git.ts:

git rev-list --reverse HEAD --first-parent -- <projectRoot>/package.json

This finds the first commit that touched the project's package.json and returns its parent, so that from..HEAD ranges include the creation commit itself.

The function is used as the fallback in two places:

Location Before After
deriveSpecifierFromConventionalCommits getFirstGitCommit() getFirstProjectCommit(projectRoot)
resolveChangelogFromSHA getFirstGitCommit() getFirstProjectCommit(projectRoot) when projectRoot is provided

For workspace-level and fixed release group changelogs (where there's no single project root), the existing getFirstGitCommit() behavior is preserved.

Fallback safety

If getFirstProjectCommit fails for any reason (e.g., the project root doesn't contain a package.json, or the git command fails), it gracefully falls back to getFirstGitCommit() — maintaining backward compatibility.

Impact

For a real-world monorepo with ~1200 commits and 4 new packages:

Metric Before After
Commits scanned per new package ~1200 Only commits since package was added
"Package not found" warnings ~30 per run 0
Release step time 5+ minutes Seconds

…for new packages

When a project has no release tags (e.g., newly added to a monorepo),
`nx release` falls back to `getFirstGitCommit()` which scans the
entire repository history. In large monorepos with thousands of commits,
this causes:

1. Severe performance degradation (5+ minutes for the release step)
2. Noisy "package not found" warnings for packages referenced in old
   commits that no longer exist in the workspace

This commit introduces `getFirstProjectCommit(projectRoot)` which
finds the first commit that touched the project's `package.json`,
scoping the conventional commits analysis to only the relevant
portion of git history.

The fallback is applied in two places:
- `deriveSpecifierFromConventionalCommits` (version bumps)
- `resolveChangelogFromSHA` (changelog generation)

For workspace-level and fixed release group changelogs, the existing
`getFirstGitCommit()` behavior is preserved since there is no single
project root to scope to.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zanlucathiago zanlucathiago requested a review from a team as a code owner April 17, 2026 11:40
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 17, 2026

Deploy Preview for nx-docs canceled.

Name Link
🔨 Latest commit 356fce2
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69e21c488ab7fe00087ee606

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 17, 2026

Deploy Preview for nx-dev canceled.

Name Link
🔨 Latest commit 356fce2
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69e21c486970180008044add

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

Labels

priority: medium Medium Priority (not high, not low priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nx release scans entire git history for new packages without release tags

3 participants