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: Support limiting commits to scopes per package. #262

Merged
merged 2 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions docs/src/config/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ If you have multiple packages, you define them like this:
# package config here
```

```admonish warning
All conventional commits [currently affect all packages](https://github.com/knope-dev/knope/issues/154). Each package can have its own version, but they will all be updated with the same [semantic versioning] rule together.
```

```admonish warning
There used to be an older `[[packages]]` syntax. This is deprecated and will be removed in a future version. Please run `knope --upgrade` to upgrade your configuration automatically.
```
Expand All @@ -33,6 +29,7 @@ Each package, whether it's defined in the `[package]` section or in the `[packag

1. `versioned_files` is an optional array of files you'd like to bump the version of. They all must have the same version—as a package only has one version.
2. `changelog` is the (optional) Markdown file you'd like to add release notes to.
3. `scopes` is an optional array of [conventional commit scopes] which should be considered for the package when running the [`PrepareRelease`] step.

### `versioned_files`

Expand Down Expand Up @@ -115,3 +112,4 @@ See [`PrepareRelease`] and [`Release`] for details on what happens when those st
[`command`]: ./step/Command.md
[request it as a feature]: https://github.com/knope-dev/knope/issues
[semantic versioning]: https://semver.org
[conventional commit scopes]: https://www.conventionalcommits.org/en/v1.0.0/#commit-message-with-scope
79 changes: 75 additions & 4 deletions docs/src/config/step/PrepareRelease.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ The last "version tag" is used as the starting point to read commits—that's th

## Limitations

The CHANGELOG format is pretty strict. Only three sections will be added to the new version, `### Breaking Changes` for anything that conventional commits have marked as breaking, `### Fixes` for anything called `fix:`, and `### Features` for anything with `feat: `. Any other commits (conventional or not) will be left out. A new version will **always** be generated though, even if there are no changes to record.
The CHANGELOG format is pretty strict. Only three sections will be added to the new version, `### Breaking Changes` for anything that conventional commits have marked as breaking, `### Fixes` for anything called `fix:`, and `### Features` for anything with `feat: `. Any other commits (conventional or not) will be left out.

## Commit Scopes

The `PrepareRelease` step can be fine-tuned when working with multiple packages to only apply a commit to a specific package's version & changelog. This is done by adding a `scopes` array to the [packages] config and adding a [conventional commit scope] to the commits that should not apply to all packages. The following rules apply, in order, with respect to conventional commit scopes:

1. If no packages define `scopes` in their config, all commits apply to all packages. Scopes are not considered by `knope`.
2. If a commit does not have a scope, it applies to all packages.
3. If a commit has a scope, and _any_ package has defined a `scopes` array, the commit will only apply to those packages which have that scope defined in their `scopes` array.

## Examples

Expand Down Expand Up @@ -81,15 +89,78 @@ Now you're ready to release 2.0.0—the version that's going to come after 2.0.0
- A bug in the first `rc` that we fixed.
```

### Multiple Packages with Scopes

Here's a `knope` config with two packages: `cli` and `lib`.

```toml
[package.cli]
versioned_files = ["cli/Cargo.toml"]
changelog = "cli/CHANGELOG.md"
scopes = ["cli"]

[package.lib]
versioned_files = ["lib/Cargo.toml"]
changelog = "lib/CHANGELOG.md"
scopes = ["lib"]

[[workflows]]
name = "release"

[[workflows.steps]]
type = "PrepareRelease"
```

The `cli` package depends on the `lib` package, so they will likely change together. Let's say the version of `cli` is 1.0.0 and the version of `lib` is 0.8.9. We add the following commits:

1. `feat(cli): Add a new --help option to display usage and exit`
2. `feat(lib)!: Change the error type of the parse function`
3. `fix: Prevent a crash when parsing invalid input`

The first two commits are scoped—they will only apply to the packages which have those scopes defined in their `scopes` array. The third commit is not scoped, so it will apply to both packages.

```admonish note
Here, the configured scopes are the same a the name of the package. This is common, but not required.
```

When the `release` workflow is run, the `cli` package will be bumped to 1.1.0 and the `lib` package will be bumped to 0.9.0. The changelog for `cli` will look like this:

```md
## 1.1.0

### Features

- Add a new --help option to display usage and exit

### Fixes

- Prevent a crash when parsing invalid input
```

And the changelog for `lib` will look like this:

```md
## 0.9.0

### Breaking Changes

- Change the error type of the parse function

### Fixes

- Prevent a crash when parsing invalid input
```

## Errors

The reasons this can fail:

1. If there is no previous tag to base changes off of.
2. The version could not be bumped for some reason.
3. The [packages] section is not configured correctly.
1. The version could not be bumped for some reason.
2. The [packages] section is not configured correctly.
3. There was nothing to release. In this case it exits immediately so that there aren't problems with later steps.

[semantic versioning]: https://semver.org
[bumpversion]: ./BumpVersion.md
[packages]: ../packages.md
[`release`]: ./Release.md
[conventional commit scope]: https://www.conventionalcommits.org/en/v1.0.0/#commit-message-with-scope
1 change: 1 addition & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ mod test_replace_variables {
versioned_files: vec![PathBuf::from("Cargo.toml").try_into().unwrap()],
changelog: Some(PathBuf::from("CHANGELOG.md").try_into().unwrap()),
name: None,
scopes: None,
}]
}

Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ pub(crate) struct Package {
pub(crate) versioned_files: Vec<PathBuf>,
/// The path to the `CHANGELOG.md` file (if any) to be updated when running [`crate::Step::PrepareRelease`].
pub(crate) changelog: Option<PathBuf>,
/// Optional scopes that can be used to filter commits when running [`crate::Step::PrepareRelease`].
pub(crate) scopes: Option<Vec<String>>,
}

/// Generate a brand new config file for the project in the current directory.
Expand Down
Loading