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(release): add conventional commits configurability for version and changelog #22004

Merged
merged 26 commits into from Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1552a77
feat(release): add conventional commits props to nxJson config
fahslaj Feb 25, 2024
a91972c
Merge branch 'master' into feat/conventional-commits-config
fahslaj Feb 26, 2024
8eaf11b
chore(release): update nx-schema
fahslaj Feb 26, 2024
1a73168
fix(release): reorder filling unspecified props
fahslaj Feb 26, 2024
dc51bf2
fix(release): preserve defaults if they exist
fahslaj Feb 26, 2024
ba4befa
Merge branch 'master' into feat/conventional-commits-config
fahslaj Feb 27, 2024
097ff3c
Merge branch 'master' into feat/conventional-commits-config
fahslaj Feb 27, 2024
33bd461
Merge branch 'master' into feat/conventional-commits-config
fahslaj Feb 27, 2024
8f40cd3
Merge branch 'master' into feat/conventional-commits-config
fahslaj Feb 28, 2024
c9fcbbf
Merge branch 'master' into feat/conventional-commits-config
fahslaj Feb 28, 2024
600f7a3
Merge branch 'master' into feat/conventional-commits-config
fahslaj Feb 28, 2024
4410360
Merge branch 'master' into feat/conventional-commits-config
fahslaj Feb 29, 2024
d5c6891
chore(release): update code comment
fahslaj Mar 1, 2024
31cfabf
docs(release): add recipe for conventional commit type customization
fahslaj Mar 1, 2024
dd804eb
Merge branch 'master' into feat/conventional-commits-config
fahslaj Mar 1, 2024
b299510
Merge branch 'master' into feat/conventional-commits-config
fahslaj Mar 4, 2024
078fefc
Merge branch 'master' into feat/conventional-commits-config
fahslaj Mar 4, 2024
8c058d3
Merge branch 'master' into feat/conventional-commits-config
fahslaj Mar 6, 2024
4f3b6b3
chore(release): update registry url in snapshot
fahslaj Mar 6, 2024
25d49c1
chore(release): update config test snapshots
fahslaj Mar 6, 2024
f8a2e33
Merge branch 'master' into feat/conventional-commits-config
fahslaj Mar 8, 2024
b144373
Merge branch 'master' into feat/conventional-commits-config
fahslaj Mar 8, 2024
a5d08ab
feat(release): support true as shorthand for enabling with defaults
fahslaj Mar 8, 2024
8a13ce3
Merge branch 'master' into feat/conventional-commits-config
fahslaj Mar 12, 2024
390ef38
docs(release): apply suggestions from review
fahslaj Mar 13, 2024
777c361
Merge branch 'master' into feat/conventional-commits-config
fahslaj Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/generated/manifests/menus.json
Expand Up @@ -2331,6 +2331,14 @@
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Customize Conventional Commit Types",
"path": "/recipes/nx-release/customize-conventional-commit-types",
"id": "customize-conventional-commit-types",
"isExternal": false,
"children": [],
"disableCollapsible": false
}
],
"disableCollapsible": false
Expand Down Expand Up @@ -4163,6 +4171,14 @@
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Customize Conventional Commit Types",
"path": "/recipes/nx-release/customize-conventional-commit-types",
"id": "customize-conventional-commit-types",
"isExternal": false,
"children": [],
"disableCollapsible": false
}
],
"disableCollapsible": false
Expand Down Expand Up @@ -4223,6 +4239,14 @@
"children": [],
"disableCollapsible": false
},
{
"name": "Customize Conventional Commit Types",
"path": "/recipes/nx-release/customize-conventional-commit-types",
"id": "customize-conventional-commit-types",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Other",
"path": "/recipes/other",
Expand Down
33 changes: 33 additions & 0 deletions docs/generated/manifests/nx.json
Expand Up @@ -3188,6 +3188,17 @@
"isExternal": false,
"path": "/recipes/nx-release/update-local-registry-setup",
"tags": ["nx-release"]
},
{
"id": "customize-conventional-commit-types",
"name": "Customize Conventional Commit Types",
"description": "",
"mediaImage": "",
"file": "shared/recipes/nx-release/customize-conventional-commit-types",
"itemList": [],
"isExternal": false,
"path": "/recipes/nx-release/customize-conventional-commit-types",
"tags": ["nx-release"]
}
],
"isExternal": false,
Expand Down Expand Up @@ -5700,6 +5711,17 @@
"isExternal": false,
"path": "/recipes/nx-release/update-local-registry-setup",
"tags": ["nx-release"]
},
{
"id": "customize-conventional-commit-types",
"name": "Customize Conventional Commit Types",
"description": "",
"mediaImage": "",
"file": "shared/recipes/nx-release/customize-conventional-commit-types",
"itemList": [],
"isExternal": false,
"path": "/recipes/nx-release/customize-conventional-commit-types",
"tags": ["nx-release"]
}
],
"isExternal": false,
Expand Down Expand Up @@ -5783,6 +5805,17 @@
"path": "/recipes/nx-release/update-local-registry-setup",
"tags": ["nx-release"]
},
"/recipes/nx-release/customize-conventional-commit-types": {
"id": "customize-conventional-commit-types",
"name": "Customize Conventional Commit Types",
"description": "",
"mediaImage": "",
"file": "shared/recipes/nx-release/customize-conventional-commit-types",
"itemList": [],
"isExternal": false,
"path": "/recipes/nx-release/customize-conventional-commit-types",
"tags": ["nx-release"]
},
"/recipes/other": {
"id": "other",
"name": "Other",
Expand Down
7 changes: 7 additions & 0 deletions docs/generated/manifests/tags.json
Expand Up @@ -1036,6 +1036,13 @@
"id": "update-local-registry-setup",
"name": "Update Your Local Registry Setup to use Nx Release",
"path": "/recipes/nx-release/update-local-registry-setup"
},
{
"description": "",
"file": "shared/recipes/nx-release/customize-conventional-commit-types",
"id": "customize-conventional-commit-types",
"name": "Customize Conventional Commit Types",
"path": "/recipes/nx-release/customize-conventional-commit-types"
}
],
"database": [
Expand Down
6 changes: 6 additions & 0 deletions docs/map.json
Expand Up @@ -1155,6 +1155,12 @@
"id": "update-local-registry-setup",
"tags": ["nx-release"],
"file": "shared/recipes/nx-release/update-local-registry-setup"
},
{
"name": "Customize Conventional Commit Types",
"id": "customize-conventional-commit-types",
"tags": ["nx-release"],
"file": "shared/recipes/nx-release/customize-conventional-commit-types"
}
]
},
Expand Down
Expand Up @@ -32,7 +32,7 @@ For example, if the git history looks like this:
- chore(release): 1.0.0
```

then Nx Release will select the `minor` version bump and elect to release version 1.1.0. This is because there is a `feat` commit since the last release of 1.0.0.
then Nx Release will select the `minor` version bump and elect to release version 1.1.0. This is because there is a `feat` commit since the last release of 1.0.0. To customize the version bump for different types of commits, or to trigger a version bump with custom commit types, see the [Customize Conventional Commit Types](/recipes/nx-release/customize-conventional-commit-types) recipe.

{% callout type="info" title="No changes detected" %}
If Nx Release does not find any relevant commits since the last release, it will skip releasing a new version. This works with [independent releases](/recipes/nx-release/release-projects-independently) as well, allowing for only some projects to be released and some to be skipped.
Expand Down
@@ -0,0 +1,92 @@
# Customize Conventional Commit Types

Nx Release can defer to the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standard to automatically determine the next version to release. To enable this behavior for versioning, see [Automatically Version with Conventional Commits](/recipes/nx-release/automatically-version-with-conventional-commits).

This recipe will cover how to customize the types of commits that trigger version bumps, how to customize the version bump for each type, and how to customize the changelog entry for each commit type.

## Conventional Commits Usage within Nx Release

The conventional commits configuration is used in two different places within Nx Release - once in the version step for determining the version bump, and once when generating changelogs.

### Determine the Version Bump

When `release.version.conventionalCommits` is `true` in `nx.json`, Nx Release will use the commit messages since the last release to determine the version bump. It will look at the type of each commit and determine the highest version bump from the following list:

- 'feat' -> minor
fahslaj marked this conversation as resolved.
Show resolved Hide resolved
- 'fix' -> patch

For example, if the git history looks like this:

```
- fix(pkg-1): fix something
- feat(pkg-2): add a new feature
- chore(pkg-3): update docs
- chore(release): 1.0.0
```

then Nx Release will select the `minor` version bump and elect to release version 1.1.0. This is because there is a `feat` commit since the last release of 1.0.0. To customize the version bump for different types of commits, or to trigger a version bump with custom commit types, see the [Configure Commit Types](#configure-commit-types) section below.

{% callout type="info" title="No changes detected" %}
If Nx Release does not find any relevant commits since the last release, it will skip releasing a new version. This works with [independent releases](/recipes/nx-release/release-projects-independently) as well, allowing for only some projects to be released and some to be skipped.
{% /callout %}

### Generate Changelog Sections

Nx Release sorts changes within changelogs into sections based on the type of commit. By default, `fix`, `feat`, and `perf` commits will be included in the changelog. To customize the headers of changelog sections, include other commit types, or exclude the default commit types, see the [Configure Commit Types](#configure-commit-types) section below.

See the [Nx repo](https://github.com/nrwl/nx/releases) for examples of a changelogs generated with Nx Release.
fahslaj marked this conversation as resolved.
Show resolved Hide resolved

## Configure Commit Types

Commit types are configured in the `release.conventionalCommits.types` property in `nx.json`:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like it to be made clearer that this is an advanced case and that most folks are perfectly fine/happy with the default behavior and no configuration should be required for most people (i.e. should just be "conventionalCommits": true

Copy link
Contributor Author

@fahslaj fahslaj Mar 8, 2024

Choose a reason for hiding this comment

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

I can add something about this being an advanced use case, but I want to point out that the release.conventionalCommits property they are setting here is different than the existing release.version.conventionalCommits property that is frequently set to true to enable it for versioning. Most users will never set release.conventionalCommits, as its only valid value is an advanced config option outlined in this doc. It is invalid (and meaningless) for release.conventionalCommits to be set to true.

The reason there are two different properties is because this new one affects both version and changelog commands, so it didn't make sense to extend the existing release.version.conventionalCommits property to accept a configuration object.


```json nx.json
fahslaj marked this conversation as resolved.
Show resolved Hide resolved
{
"release": {
"conventionalCommits": {
"types": {
// disable the fix type for versioning and in the changelog
"fix": false,
"docs": {
"semverBump": "patch",
"changelog": {
"hidden": false,
"title": "Documentation Changes"
}
},
"perf": {
"semverBump": "none",
// omitting "hidden" will default it to false
"changelog": {
"title": "Performance Improvements"
}
},
"deps": {
"semverBump": "minor",
// omitting "hidden" will default it to false
"changelog": {
"title": "Dependency Updates"
}
},
// unspecified semverBump will default to "patch"
"chore": {
// "changelog.hidden" defaults to true, but setting changelog: false
// is a shortcut for setting "changelog.hidden" to false.
"changelog": false
},
// unspecified semverBump will default to "patch"
"styles": {}
}
}
}
}
```

In this example, the following types are configured:

- The `fix` type has been fully disabled, so `fix` commits will not trigger a version bump and will not be included in the changelog.
- The `docs` type will now trigger a `patch` version bump and will have the "Documentation Changes" title in the changelog.
fahslaj marked this conversation as resolved.
Show resolved Hide resolved
- The `perf` type will NOT trigger a version bump and will have the "Performance Improvements" title in the changelog.
- The `deps` type will trigger a `minor` version bump and will have the "Dependency Updates" title in the changelog.
- The `chore` type will trigger a `patch` version bump, which is the default for if `versionBump` is not specified, and will not be included in the changelog.
- The `styles` type will trigger a `patch` version bump, which is the default for if `versionBump` is not specified, and will be included in the changelog with the corresponding default title.
1 change: 1 addition & 0 deletions docs/shared/reference/sitemap.md
Expand Up @@ -184,6 +184,7 @@
- [Automate GitHub Releases](/recipes/nx-release/automate-github-releases)
- [Publish Rust Crates](/recipes/nx-release/publish-rust-crates)
- [Update Your Local Registry Setup to use Nx Release](/recipes/nx-release/update-local-registry-setup)
- [Customize Conventional Commit Types](/recipes/nx-release/customize-conventional-commit-types)
- [Other](/recipes/other)
- [Rescope Packages from @nrwl to @nx](/recipes/other/rescope)
- [Showcase](/showcase)
Expand Down