Compare commits

...

7 commits

Author SHA1 Message Date
Paul Hatcherian
f29500c9d6 fix: package build
Some checks failed
CI / Build and Test (push) Has been cancelled
CI / Create Version Tag (push) Has been cancelled
CI / Publish Release (push) Has been cancelled
2026-01-24 17:57:50 -06:00
Paul Hatcherian
a879aef8a8
Merge pull request #188 from BodrickLight/feature/scopes
feat: change minor pattern to support optional conventional commit scopes
2026-01-24 17:45:37 -06:00
Paul Hatcherian
78c5ef57e8 ci: build updates, update cli names 2026-01-24 12:56:28 -06:00
Dom Light
e71c2c074d
fix: remove anchor 2026-01-23 09:55:54 +00:00
Dom Light
36de0820fc
fix: escaping 2026-01-23 09:48:57 +00:00
Dom Light
f0e68a4f66
docs: update docs 2026-01-23 09:24:20 +00:00
Dom Light
67c95513f8
feat: change minor pattern to support optional conventional commit scopes
The Conventional Commits spec allows optional scopes to be present after the change type, e.g. `feat(scope):`. The current minor pattern will only bump the minor version number if the pattern exactly matches `feat:`. This change is backwards compatible and adds support for these scopes.
2026-01-23 09:21:26 +00:00
11 changed files with 49 additions and 18 deletions

View file

@ -57,7 +57,7 @@ jobs:
create-tag:
name: Create Version Tag
needs: build
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
permissions:
contents: write

View file

@ -31,7 +31,7 @@ inputs:
minor_pattern:
description: "A string which, if present in a git commit, indicates that a change represents a minor (feature) change. Wrap with '/' to match using a regular expression."
required: true
default: "/feat:/"
default: "/feat(\\(.+\\))?:/"
minor_regexp_flags:
description: "A string which indicates the flags used by the `minor_pattern` regular expression. Supported flags: idgs"
required: false

24
dist/index.js vendored
View file

@ -705,6 +705,7 @@ function run() {
userFormatType: core.getInput("user_format_type"),
enablePrereleaseMode: toBool(core.getInput("enable_prerelease_mode")),
bumpEachCommitPatchPattern: core.getInput("bump_each_commit_patch_pattern"),
ignoreCommitsPattern: core.getInput("ignore_commits_pattern"),
debug: toBool(core.getInput("debug")),
replay: "",
};
@ -760,13 +761,14 @@ class BumpAlwaysVersionClassifier extends DefaultVersionClassifier_1.DefaultVers
if (lastRelease.currentPatch !== null) {
return new VersionClassification_1.VersionClassification(VersionType_1.VersionType.None, 0, false, lastRelease.currentMajor, lastRelease.currentMinor, lastRelease.currentPatch);
}
const filteredCommitSet = this.filterIgnoredCommits(commitSet);
let { major, minor, patch } = lastRelease;
let type = VersionType_1.VersionType.None;
let increment = 0;
if (commitSet.commits.length === 0) {
if (filteredCommitSet.commits.length === 0) {
return new VersionClassification_1.VersionClassification(type, 0, false, major, minor, patch);
}
for (let commit of commitSet.commits.reverse()) {
for (let commit of filteredCommitSet.commits.reverse()) {
if (this.majorPattern(commit)) {
type = VersionType_1.VersionType.Major;
}
@ -1158,6 +1160,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DefaultVersionClassifier = void 0;
const CommitInfoSet_1 = __nccwpck_require__(8546);
const VersionClassification_1 = __nccwpck_require__(3797);
const VersionType_1 = __nccwpck_require__(8945);
class DefaultVersionClassifier {
@ -1165,9 +1168,23 @@ class DefaultVersionClassifier {
const searchBody = config.searchCommitBody;
this.majorPattern = this.parsePattern(config.majorPattern, config.majorFlags, searchBody);
this.minorPattern = this.parsePattern(config.minorPattern, config.minorFlags, searchBody);
this.ignorePattern = config.ignoreCommitsPattern
? this.parsePattern(config.ignoreCommitsPattern, "", searchBody)
: null;
this.enablePrereleaseMode = config.enablePrereleaseMode;
}
filterIgnoredCommits(commitSet) {
if (!this.ignorePattern) {
return commitSet;
}
const filteredCommits = commitSet.commits.filter((commit) => !this.ignorePattern(commit));
const changed = filteredCommits.length > 0 ? commitSet.changed : false;
return new CommitInfoSet_1.CommitInfoSet(changed, filteredCommits);
}
parsePattern(pattern, flags, searchBody) {
if (pattern === "") {
return (_commit) => false;
}
if (/^\/.+\/[i]*$/.test(pattern)) {
const regexEnd = pattern.lastIndexOf("/");
const parsedFlags = pattern.slice(pattern.lastIndexOf("/") + 1);
@ -1266,7 +1283,8 @@ class DefaultVersionClassifier {
}
ClassifyAsync(lastRelease, commitSet) {
return __awaiter(this, void 0, void 0, function* () {
const { type, increment, changed } = this.resolveCommitType(commitSet);
const filteredCommitSet = this.filterIgnoredCommits(commitSet);
const { type, increment, changed } = this.resolveCommitType(filteredCommitSet);
const { major, minor, patch } = this.getNextVersion(lastRelease, type);
if (lastRelease.currentPatch !== null) {
// If the current commit is tagged, we must use that version. Here we check if the version we have resolved from the

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -100,7 +100,7 @@ If your project contains multiple services which you wish to version independent
| Value | Description |
| --- | --- |
| `tag_prefix` | The prefix to use for the tag. Defaults to `v`, generally you will use either `v` or an empty string. Note that the tag format is distinct from the version. Tags used for versioning must always follow the pattern `{tag_prefix}{major}.{minor}.{patch}` with and optional `-{namespace}` suffix. |
| `major_pattern` and `minor_pattern` | These strings are used to determine the type of version to create. If any commit message since matches the `major_pattern` the major version will be incremented, if it matches the `minor_pattern` the minor version will be incremented. If neither pattern matches, the patch version will be incremented. These can be specified either as strings or as regular expression by wrapping the expression in `/`. The defaults follow [Conventional Commits](https://www.conventionalcommits.org/): `/!:|BREAKING CHANGE:/` for major and `/feat:/` for minor. |
| `major_pattern` and `minor_pattern` | These strings are used to determine the type of version to create. If any commit message since matches the `major_pattern` the major version will be incremented, if it matches the `minor_pattern` the minor version will be incremented. If neither pattern matches, the patch version will be incremented. These can be specified either as strings or as regular expression by wrapping the expression in `/`. The defaults follow [Conventional Commits](https://www.conventionalcommits.org/): `/!:|BREAKING CHANGE:/` for major and `/feat(\(.+\))?:/` for minor. |
| `version_format` | A value such as `${major}.${minor}.${patch}-prerelease${increment}` that will be used to format the version value of the output, **formatting this value is the only effect of this input parameter!** It is not used for parsing or any other purpose. It is a convenient alternative to formatting the output in a subsequent step. |
| `user_format_type` | Indicates the format of the `authors` output. Can be `json` or `yaml`. |
| `enable_prerelease_mode` | If true, major changes to versions starting with 0 will result in a minor change, preventing ths initial version `1.0.0`` from being created automatically by someone checking in a commit with the major pattern. |

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "@semanticversion/cli",
"version": "0.0.0",
"version": "6.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@semanticversion/cli",
"version": "0.0.0",
"version": "6.0.0",
"license": "MIT",
"dependencies": {
"@actions/core": "^2.0.2",

View file

@ -1,11 +1,10 @@
{
"name": "@semanticversion/cli",
"version": "0.0.0",
"description": "Automated semantic versioning based on git history - CLI tool and GitHub Action",
"main": "lib/main.js",
"bin": {
"git-sv": "lib/cli.js",
"git-semantic-version": "lib/cli.js"
"sv": "lib/cli.js",
"semver": "lib/cli.js"
},
"files": [
"lib/**/*.js",

View file

@ -14,8 +14,8 @@ release. To accomplish this, the next version number is calculated along with
a commit increment indicating the number of commits for this version. The
commit messages are inspected to determine the type of version change the next
version represents. By default, this action follows [Conventional Commits](https://www.conventionalcommits.org/)
patterns: commits with `feat:` trigger minor version bumps, and commits with a `!` suffix
(e.g., `feat!:`, `fix!:`) or containing `BREAKING CHANGE:` trigger major version bumps.
patterns: commits with `feat:` or `feat(scope):` trigger minor version bumps, and commits with a `!` suffix
(e.g., `feat!:`, `fix!:`, `refactor(scope)!:`) or containing `BREAKING CHANGE:` trigger major version bumps.
# Background
@ -51,7 +51,7 @@ _Unless the current commit is already tagged, the version produced by this actio
## Major and Minor Versions
The commit messages for the span of commits from the last tag are checked for the
presence of version bump patterns. By default, `feat:` triggers a minor version bump,
presence of version bump patterns. By default, `feat:` or `feat(scope):` trigger a minor version bump,
while `!:` (e.g., `feat!:`, `fix!:`) or `BREAKING CHANGE:` triggers a major version bump. If a pattern
is encountered that commit is treated as the start of a major or minor version
instead of the default patch level. As with normal commits the implied version
@ -85,7 +85,7 @@ it will be given the new version if the build were to be retriggered, for exampl
# A string which indicates the flags used by the `major_pattern` regular expression. Supported flags: idgs
major_regexp_flags: ""
# Same as above except indicating a minor change, supports regular expressions wrapped with '/'
minor_pattern: "/feat:/"
minor_pattern: "/feat(\\(.+\\))?:/"
# A string which indicates the flags used by the `minor_pattern` regular expression. Supported flags: idgs
minor_regexp_flags: ""
# A string to determine the format of the version output

View file

@ -13,7 +13,7 @@ export class ActionConfig {
/** A string which indicates the flags used by the `majorPattern` regular expression. */
public majorFlags: string = "";
/** A string which, if present in a git commit, indicates that a change represents a minor (feature) change. Wrap with '/' to match using a regular expression. */
public minorPattern: string = "/feat:/";
public minorPattern: string = "/feat(\\(.+\\))?:/";
/** A string which indicates the flags used by the `minorPattern` regular expression. */
public minorFlags: string = "";
/** Pattern to use when formatting output version */

View file

@ -33,7 +33,7 @@ program
.option(
"-m, --minor-pattern <pattern>",
"Regex pattern for minor version bumps",
"/feat:/",
"/feat(\\(.+\\))?:/",
)
.option("--minor-flags <flags>", "Flags for minor pattern regex", "")
.option(

View file

@ -217,6 +217,20 @@ testInterfaces.forEach((testInterface) => {
timeout,
);
test(
"Minor commits with conventional commit scopes bump minor version",
async () => {
const repo = createTestRepo(testRunner); // 0.0.0+0
repo.makeCommit("Initial Commit"); // 0.0.1+0
repo.makeCommit("feat(scope): Second Commit"); // 0.1.0+0
const result = await repo.runAction();
expect(result.formattedVersion).toBe("0.1.0+0");
},
timeout,
);
test(
"Tags start new version",
async () => {