Skip to content

Commit df8947c

Browse files
committed
docs: document custom YAML schemes
1 parent b6fe9e4 commit df8947c

3 files changed

Lines changed: 123 additions & 0 deletions

File tree

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,70 @@ refactor!: drop support for Node 6
141141

142142
If no keywords are specified a **Patch** bump is applied.
143143

144+
### Scheme: Custom (YAML)
145+
146+
A user-defined scheme can be supplied via a YAML file using the `--scheme-file` flag. This is
147+
useful when neither the autotag nor Conventional Commits scheme fits your project's commit
148+
conventions.
149+
150+
`--scheme-file` is mutually exclusive with an explicitly non-default `--scheme`: pass one or the
151+
other. Ready-to-copy reference schemes are available under
152+
[`examples/schemes/`](examples/schemes/).
153+
154+
#### YAML schema
155+
156+
```yaml
157+
name: my-custom-scheme # required: identifier used in logs
158+
description: Optional summary. # optional: free-form
159+
160+
# Rules are evaluated in declaration order. The first rule whose regex matches
161+
# the commit message determines the bump. Remaining rules are not consulted.
162+
rules:
163+
- name: breaking-footer # optional: shown in validation errors
164+
match: '(?m)^BREAKING CHANGE:'
165+
bump: major
166+
- name: feat
167+
match: '^feat(\([^)]*\))?:'
168+
bump: minor
169+
- name: patch-types
170+
match: '^(fix|chore|docs|refactor)(\([^)]*\))?:'
171+
bump: patch
172+
173+
# Required. What to do when no rule matches a commit.
174+
# Allowed values: major | minor | patch | none
175+
default: patch
176+
```
177+
178+
- `match` is a Go [regexp](https://pkg.go.dev/regexp/syntax) pattern.
179+
- `bump` and `default` must be one of `major`, `minor`, `patch`, or `none`.
180+
- A rule with `bump: none` matches the commit but contributes no version change — useful for
181+
explicitly ignoring commits (e.g., merge commits) without falling through to the default.
182+
- `default: none` combined with `--strict-match` will cause unmatched commits to error out instead
183+
of being silently ignored.
184+
185+
All validation (regex compilation, allowed bump values, required fields, unknown keys) happens at
186+
load time, so a malformed scheme fails fast with a clear error before any commits are parsed.
187+
188+
#### Example
189+
190+
Given a scheme file `./my-scheme.yaml`:
191+
192+
```yaml
193+
name: my-scheme
194+
rules:
195+
- match: '(?m)^BREAKING CHANGE:'
196+
bump: major
197+
- match: '^feat:'
198+
bump: minor
199+
default: patch
200+
```
201+
202+
Invoke autotag with:
203+
204+
```sh
205+
autotag --scheme-file ./my-scheme.yaml
206+
```
207+
144208
### Strict Match Option
145209

146210
The `--strict-match` option enforces that commit messages must strictly adhere to the specified commit message scheme.
@@ -164,6 +228,13 @@ When the `--strict-match` option is enabled, the behavior of the commit message
164228
- With `--strict-match`: Commit messages that do not follow the conventional commit format will result in an
165229
error, and the commit will not be processed.
166230

231+
- **Custom (YAML) Scheme**:
232+
- Without `--strict-match`: Unmatched commits use the scheme's `default` value. When `default:
233+
none`, those commits contribute no version change.
234+
- With `--strict-match`: Unmatched commits (no rule matches **and** the scheme declares `default:
235+
none`) result in an error. If the scheme's `default` is `major`, `minor`, or `patch`, the
236+
fallback is always taken and strict-match never fires.
237+
167238
#### Usage
168239

169240
To use the strict match option, add the `--strict-match` flag when running the autotag tool:

examples/schemes/autotag.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Reproduces the built-in "autotag" scheme as a --scheme-file.
2+
# Use this as a starting point when customizing the bracket/hash keyword style.
3+
name: autotag
4+
description: Bump based on [major]/[minor]/[patch] or #major/#minor/#patch markers.
5+
6+
rules:
7+
- name: major
8+
match: '(?i)\[major\]|#major'
9+
bump: major
10+
- name: minor
11+
match: '(?i)\[minor\]|#minor'
12+
bump: minor
13+
- name: patch
14+
match: '(?i)\[patch\]|#patch'
15+
bump: patch
16+
17+
# The built-in autotag scheme falls back to a patch bump when no marker is
18+
# present. Use `default: none` if you'd rather unmatched commits contribute
19+
# nothing (combine with --strict-match to turn them into errors).
20+
default: patch

examples/schemes/conventional.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Reproduces the built-in "conventional" scheme (in non-strict mode) as a
2+
# --scheme-file. Use this as a starting point when customizing which commit
3+
# types bump which version segment.
4+
name: conventional
5+
description: Conventional Commits v1.0.0 — https://www.conventionalcommits.org/en/v1.0.0/
6+
7+
rules:
8+
# A footer starting with "BREAKING CHANGE:" anywhere in the commit body
9+
# forces a major bump, even when the header type is unknown.
10+
- name: breaking-footer
11+
match: '(?m)^BREAKING CHANGE:'
12+
bump: major
13+
14+
# A trailing '!' after the type or type(scope) also marks a breaking change.
15+
- name: breaking-bang
16+
match: '^\w+(\([^)]*\))?!:'
17+
bump: major
18+
19+
# A new feature — minor bump.
20+
- name: feat
21+
match: '^feat(\([^)]*\))?:'
22+
bump: minor
23+
24+
# The remaining well-known types all map to a patch bump.
25+
- name: patch-types
26+
match: '^(fix|build|chore|ci|docs|perf|refactor|revert|style|test)(\([^)]*\))?:'
27+
bump: patch
28+
29+
# Commits that don't match any rule contribute no version change. This matches
30+
# the built-in conventional scheme's behavior: non-conforming commits are
31+
# silently ignored unless --strict-match is enabled, in which case they error.
32+
default: none

0 commit comments

Comments
 (0)