Skip to content

Conversation

@BYK
Copy link
Member

@BYK BYK commented Dec 9, 2025

Summary

Add automatic semantic version calculation and version bump types, triggered by:

  • craft prepare auto - determine version from conventional commit analysis
  • craft prepare major - bump major version
  • craft prepare minor - bump minor version
  • craft prepare patch - bump patch version

All options require minVersion: '2.14.0' (or higher) in .craft.yml.

Key changes

  • Add semver field to release config categories (major/minor/patch)
  • Update DEFAULT_RELEASE_CONFIG with conventional commit semver mappings:
    • Breaking Changes → major
    • New Features → minor
    • Bug Fixes, Documentation, Build/internal → patch
  • Create autoVersion.ts with BumpType enum for efficient max comparison and early exit
  • Add requiresMinVersion() helper to gate feature
  • Update prepare command to accept auto and bump type keywords
  • Update README with comprehensive documentation

Behavior

Auto-versioning: Finds the highest bump type across matched commits with early exit when a major bump is found. Throws an error if no commits match categories with semver fields defined.

Version bump types: Gets the latest tag and applies the specified bump (major/minor/patch) using the semver library.

Usage

# Automatic version from commit analysis
craft prepare auto

# Explicit version bumps
craft prepare major   # 1.2.3 -> 2.0.0
craft prepare minor   # 1.2.3 -> 1.3.0
craft prepare patch   # 1.2.3 -> 1.2.4

Requires minVersion: '2.14.0' (or higher) in .craft.yml.

BYK added 5 commits December 9, 2025 23:22
Add automatic semantic version calculation triggered by `craft prepare auto`.
Analyzes commits since the last tag using release config categories with a new
`semver` field to determine the appropriate version bump (major/minor/patch).

Key changes:
- Add `semver` field to release config categories (major/minor/patch)
- Update DEFAULT_RELEASE_CONFIG with conventional commit semver mappings
- Create autoVersion.ts with BumpType enum for efficient max comparison
- Add requiresMinVersion() helper to gate feature (requires minVersion >= 2.14.0)
- Update prepare command to accept "auto" keyword

The system finds the highest bump type across matched commits with early exit
when a major bump is found. Throws an error if no commits match categories
with semver fields defined.
Implement the previously stubbed version bump types feature. Users can now run:
- `craft prepare major` - bump major version
- `craft prepare minor` - bump minor version
- `craft prepare patch` - bump patch version

Like auto-versioning, this requires minVersion >= 2.14.0 in .craft.yml.

Also update README with comprehensive documentation for all version
specification options including auto-versioning and bump types.
Refactor getAutoVersion to getAutoBumpType which returns a BumpType enum
instead of the computed version string. This allows prepareMain to handle
both "auto" and explicit bump types (major/minor/patch) with unified logic:

1. Get latest tag
2. Determine bump type (from arg or commit analysis)
3. Calculate new version using calculateNextVersion

This increases code reuse and simplifies the prepare command logic.
Replace BumpType enum with simple string literal type and BUMP_TYPES
array ordered by priority (major > minor > patch). This allows:

1. Direct use as semver.inc() argument (no mapping needed)
2. Priority lookup via array index (first found = highest priority)
3. Single source of truth for bump types shared between autoVersion and prepare

The analyzeCommitsForBump function now:
- Collects found bump types in a Set during commit iteration
- Early exits on 'major' (no need to check more)
- Returns first match from BUMP_TYPES array (highest priority)
…ate work

Previously, auto-versioning and changelog generation each independently:
- Fetched commits since the last tag
- Made GitHub API calls to get PR/label metadata
- Iterated through commits to categorize them

This was wasteful when both features are used together.

Changes:
- Move BUMP_TYPES and BumpType to changelog.ts (single source of truth)
- Have generateChangesetFromGit return ChangelogResult with both:
  - changelog: the formatted changelog string
  - bumpType: the highest version bump determined from commits
- Add matchCommitToCategory (exported) returning full NormalizedCategory
- Simplify autoVersion.ts to just re-export types and provide:
  - calculateNextVersion: semver calculation
  - getChangelogWithBumpType: wrapper that validates and returns result
- Update prepareMain to cache changelog result when using auto-versioning
  and pass it to prepareChangelog to avoid regenerating

This eliminates duplicate GitHub API calls when using 'craft prepare auto'
with changelog generation enabled.
BYK added 2 commits December 10, 2025 23:14
- BUMP_TYPES: Use object with numeric priorities instead of array
- Use min() for bump type comparison instead of Set
- Fix matchedCommitsWithSemver to track actual count
- Memoize generateChangesetFromGit (caches promise for concurrent calls)
- ValidatedChangelogResult type with non-null bumpType
- Remove useless BUMP_TYPES tests
- Fix logger: currentVersion can never be empty
- Define BumpType first, then BUMP_TYPES as Map<BumpType, number>
- Use .has() and .get() instead of 'in' operator (avoids prototype issues)
- Add clearChangesetCache() for testing memoization
- getChangelogWithBumpType no longer throws - returns null bumpType instead
- Added validateBumpType() for callers that need to enforce bump type
- Changed changesetCache to Map for proper cleanup
- Added isBumpType() type guard for safe BumpType checks
- Clear memoization cache in tests to prevent stale results
@BYK BYK marked this pull request as ready for review December 10, 2025 23:40
@BYK BYK requested review from Lms24 and sentrivana December 10, 2025 23:40
@BYK BYK enabled auto-merge (squash) December 10, 2025 23:40
@BYK BYK merged commit 061f9fa into master Dec 11, 2025
14 checks passed
@BYK BYK deleted the feat/auto-version branch December 11, 2025 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants