calver
A lightweight command-line tool for effortless Calendar Versioning increments.
📖 Overview
CalVer is a simple yet powerful tool that generates calendar-based version numbers. It automatically creates version identifiers using the current date and manages patch increments intelligently, making it perfect for automated builds, daily releases, and development snapshots.
✨ Key Features
- 🗓️ Date-based versioning using current UTC time
- 🔢 Automatic patch increment from previous versions
- 🎨 Customizable formats for date and separators
- 🌍 Environment variable support for CI/CD integration
- ⚡ Zero configuration - works out of the box
- 🛡️ Robust error handling with proper exit codes
📊 Use Cases
- 🔄 Continuous Integration: Automatic version generation in CI/CD pipelines
- 📦 Daily Builds: Version daily snapshots and releases
- 🏷️ Git Tagging: Generate consistent tags for repository management
- 🐳 Container Images: Tag Docker images with date-based versions
- 📂 Artifact Management: Version build artifacts and deployments
- 🔍 Development Tracking: Track development progress with dated versions
🚀 Quick Start
📦 Installation
-
Binary file installation on Linux via the GitLab package registry of the project:
- 2 architectures:
- calver-x86_64-linux-<gnu|musl>.tar.gz : x86_64 (Intel, AMD).
- calver-aarch64-linux-<gnu|musl>.tar.gz : arm64
- 2 C standard library with no dependencies:
- calver-<x86_64|aarch64>-linux-gnu.tar.gz : glibc for Debian, Ubuntu, Fedora...
- calver-<x86_64|aarch64>-linux-musl.tar.gz : musl libc for Alpine
- 2 architectures:
-
Docker (coming soon)
# From Dockerhub
docker run -it --rm jfxs/calver calver help
# From Quay.io
docker run -it --rm quay.io/ifxs/calver calver help
- With a Rust environment, running this command will globally install the calver binary from crates.io:
cargo install calver
🎯 Basic Usage
# Basic usage with defaults
# Custom format and separator
# Explicit patch number
# Auto-increment from last version
# Using environment variables
📋 Usage
Command Syntax
Options
| Option | Short | Environment Variable | Description | Default |
|---|---|---|---|---|
--format |
-f |
CALVER_FORMAT |
Date format string | %Y.%m.%d |
--separator |
-s |
CALVER_SEPARATOR |
Separator between date and patch | - |
--patch |
-p |
CALVER_PATCH |
Explicit patch number (conflicts with --last) | 0 |
--last |
-l |
CALVER_LAST |
Previous version for auto-increment | None |
Date Format Examples
| Format | Output | Description |
|---|---|---|
%Y.%m.%d |
2025.09.15 |
Year.Month.Day (default) |
%Y%m%d |
20250915 |
Compact YYYYMMDD |
%y.%m.%d |
25.09.15 |
Short year format |
%Y-%m-%d |
2025-09-15 |
ISO date format |
%Y.%j |
2025.258 |
Year and day of year |
Separator Examples
| Separator | Output | Description |
|---|---|---|
- |
2025.09.15-0 |
Hyphen (default) |
_ |
2025.09.15_0 |
Underscore |
. |
2025.09.15.0 |
Dot |
_v |
2025.09.15_v0 |
Version prefix |
🔄 Auto-Increment Logic
The --last parameter enables intelligent patch increment:
-
Same date: Extracts and increments the patch number
calver bump --last "2025.09.15-3" # Output: 2025.09.15-4 -
Different date: Resets patch to 0
calver bump --last "2025.09.14-10" # Output: 2025.09.15-0 -
Invalid format: Ignores and uses default patch
calver bump --last "invalid-version" # Output: 2025.09.15-0
🌍 Environment Variables
Set default values using environment variables:
export CALVER_FORMAT="%Y%m%d"
export CALVER_SEPARATOR="_v"
export CALVER_PATCH="1"
calver bump
# Output: 20250915_v1
For CI/CD pipelines:
export CALVER_LAST=$(git tag -l --sort=-version:refname | head -n1)
calver bump
💡 Examples
Daily Releases
# Monday 2025.09.15
calver bump --last "2025.09.12-5"
# Output: 2025.09.15-0 (new day, reset patch)
# Later same day
calver bump --last "2025.09.15-0"
# Output: 2025.09.15-1
Custom Versioning Scheme
# Compact format for internal builds
calver bump --format "%y%m%d" --separator "."
# Output: 250915.0
CI/CD Integration
# GitHub Actions example
- name: Generate Version
run: |
LAST_VERSION=$(git tag -l --sort=-version:refname | head -n1)
NEW_VERSION=$(calver bump --last "$LAST_VERSION")
echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV
echo "Generated version: $NEW_VERSION"
Build Scripts
#!/bin/bash
# build.sh - Automated build with versioning
# Get last version from a file
LAST_VERSION=
# Generate new version
NEW_VERSION=
# Save for next build
# Build with version
⚠️ Error Handling
CalVer provides clear error messages and appropriate exit codes:
Exit Codes
0: Success1: Error (patch overflow, invalid input)
Common Errors
# Patch overflow
# Error: The patch calculated exceeds the maximum allowed value (65535)
# Exit code: 1
# Success case
# Output: 2025.09.15-0
# Exit code: 0
🔧 Development
-
Clone the source repository:
git clone https://gitlab.com/op_so/projects/calver.git -
To format and lint:
cargo fmt # cargo fmt -- --check
cargo clippy # Rust linter
- To test:
cargo build && cargo test # Unit and integration tests
cargo tarpaulin --ignore-tests # Code coverage
cargo audit # Security audit
cargo bench # Statistics-driven benchmarking
-
To run:
cargo run -
To build:
cargo build # Debug binary target/debug/calver
cargo build --release # Release binary target/release/calver
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Guidelines
- Code Style: Follow
rustfmtandclippyrecommendations - Testing: Add tests for new features
- Documentation: Update README and code docs
- Commits: Use commitizen commit messages
👥 Authors
- FX Soubirou - Initial work - GitLab repositories
🙏 Acknowledgments
- clap for excellent CLI parsing
- chrono for robust date/time handling
- Calendar Versioning specification for inspiration
🔗 Links
📄 License
This program is free software: you can redistribute it and/or modify it under the terms of the MIT License (MIT). See the LICENSE for details.