should bump to version specified by --new-version if present (#3)

* update Cargo.lock

* better error message when failed to get current version from config

* should bump to version specified by --new-version if present

* fix: update docs && add CI

---------

Co-authored-by: 莫仲华 <mozhonghua@qiyi.com>
This commit is contained in:
Mo Zhonghua 2024-11-14 11:56:12 +08:00 committed by GitHub
parent 2b75ff6ce4
commit 017a228f6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 99 additions and 57 deletions

11
.github/dependabot.yml vendored Normal file
View file

@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "cargo" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

22
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,22 @@
name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

28
.github/workflows/clippy.yml vendored Executable file
View file

@ -0,0 +1,28 @@
name: Rust Clippy Check
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
CARGO_TERM_COLOR: always
jobs:
clippy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy
- name: Run clippy
run: cargo clippy -- -D warnings

28
.github/workflows/rustfmt.yml vendored Executable file
View file

@ -0,0 +1,28 @@
name: Rust Format Check
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
CARGO_TERM_COLOR: always
jobs:
rustfmt:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt
- name: Run rustfmt
run: cargo fmt -- --check

2
Cargo.lock generated
View file

@ -61,7 +61,7 @@ dependencies = [
[[package]]
name = "bump2version"
version = "0.1.1"
version = "0.1.3"
dependencies = [
"clap",
"regex",

View file

@ -1,57 +1,5 @@
//! # ⬆️ Bump2version
//!
//! Bump2version is a command-line tool for managing version numbers in your projects.
//! Easily update version strings, create commits, and manage version control tags.
//!
//! ## Features
//!
//! - **Incremental Versioning:** Bump major, minor, or patch versions with ease.
//! - **Configurability:** Use a configuration file or command-line options to customize behavior.
//! - **Git Integration:** Create commits and tags in your version control system.
//!
//! ## Quick Start
//!
//! Get started with the `bump2version` CLI by following these simple steps:
//!
//! 1. Install the `bump2version` tool using Cargo:
//!
//! ```bash
//! cargo install bump2version
//! ```
//!
//! 2. Use the following options to manage version numbers and customize the behavior:
//!
//! ```bash
//! bump2version --current-version 1.2.3 --bump patch
//! ```
//!
//! ## Options
//!
//! | Option | Description |
//! |------------------------|-------------------------------------------------------------------|
//! | `--config-file` | Config file to read most of the variables from. |
//! | `--current-version` | Version that needs to be updated. |
//! | `--bump` | Part of the version to be bumped (default: patch). |
//! | `--parse` | Regex parsing the version string (default: \d+\.\d+\.\d+). |
//! | `--serialize` | How to format what is parsed back to a version (default: {major}.{minor}.{patch}). |
//! | `--dry-run` | Don't write any files, just pretend. |
//! | `--new-version` | New version that should be in the files. |
//! | `--commit` | Create a commit in version control (default: true). |
//! | `--tag` | Create a tag in version control. |
//! | `--message` | Commit message (default: Bump version: {current_version} → {new_version}). |
//! | `file` | Files to change. |
//!
//! ## GitHub Repository
//!
//! You can access the source code for this CLI tool on [GitHub](https://github.com/wiseaidev/bump2version).
//!
//! ## Contributing
//!
//! Contributions and feedback are welcome! If you'd like to contribute, report an issue, or suggest an enhancement,
//! please engage with the project on [GitHub](https://github.com/wiseaidev/bump2version).
//! Your contributions help improve this CLI tool for the community.
//!
//! **Manage your project versions with ease! 🚀**
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
pub mod cli;
pub mod utils;

View file

@ -14,14 +14,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Cli::parse();
let config_file = args.config_file.clone();
let config_content = fs::read_to_string(args.config_file.clone()).unwrap();
let config_version = get_current_version_from_config(&config_content).ok_or("")?;
let config_version = get_current_version_from_config(&config_content)
.ok_or("failed to get current version from config")?;
let current_version = args
.current_version
.clone()
.unwrap_or(config_version)
.clone();
let attempted_new_version = attempt_version_bump(args.clone());
let attempted_new_version = if let Some(version) = args.new_version {
Some(version)
} else {
attempt_version_bump(args.clone())
};
if attempted_new_version.is_some() {
let new_version = attempted_new_version.clone().unwrap();