From 017a228f6b676d445bc23eed6351ffad41d631a9 Mon Sep 17 00:00:00 2001 From: Mo Zhonghua Date: Thu, 14 Nov 2024 11:56:12 +0800 Subject: [PATCH] should bump to version specified by --new-version if present (#3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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: 莫仲华 --- .github/dependabot.yml | 11 +++++++ .github/workflows/ci.yml | 22 ++++++++++++++ .github/workflows/clippy.yml | 28 ++++++++++++++++++ .github/workflows/rustfmt.yml | 28 ++++++++++++++++++ Cargo.lock | 2 +- src/lib.rs | 56 ++--------------------------------- src/main.rs | 9 ++++-- 7 files changed, 99 insertions(+), 57 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml create mode 100755 .github/workflows/clippy.yml create mode 100755 .github/workflows/rustfmt.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..e8d486a --- /dev/null +++ b/.github/dependabot.yml @@ -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" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..58d869d --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100755 index 0000000..9f915a8 --- /dev/null +++ b/.github/workflows/clippy.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml new file mode 100755 index 0000000..3f7da8f --- /dev/null +++ b/.github/workflows/rustfmt.yml @@ -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 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 53bc586..8785911 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,7 +61,7 @@ dependencies = [ [[package]] name = "bump2version" -version = "0.1.1" +version = "0.1.3" dependencies = [ "clap", "regex", diff --git a/src/lib.rs b/src/lib.rs index cb53ad7..7f21eee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/main.rs b/src/main.rs index b7dfdee..31fc033 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,14 +14,19 @@ fn main() -> Result<(), Box> { 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();