Git Product home page Git Product logo

versup's Introduction

versup

License: MIT Documentation Status PyPI version Python application Coverage Status Code style: black

Bump your project version, update version numbers in your files, create a changelog, make a commit, and tag it, all in one easy step. versup is also quite configurable.

Install

Install with either poetry

poetry install

or pip

pip install .

Quick start

To get started all versup needs to know is the new version increment or number. You can provide it with a valid semantic version increase such as patch, minor, major etc, or an entirely new semantic version like 1.2.5.

If you specifiy a version number, then versup will take that version and apply it to the current project as is. If you provide an increment, it will get the last version number from either the latest git tag that has a valid version, or from the default version in the config file.

Configuration

Versup has a default configuration which is shown below

{
    "force": False,  # Force the command without prompting the user
    "silent": False,  # Minimize the amount of logs
    "files": {},  # A map of `relativeFilePath: [regex, replacement, regexFlags?] | [regex, replacement, regexFlags?][]`
    "version": {
        "enabled": True,  # Bump the version number
        "initial": "0.0.0",  # Initial version
        "increments": [
            "major",
            "minor",
            "patch",
            "prerelease",
            "build",
        ],  # List of available increments to pick from
    },
    "changelog": {
        "enabled": True,  # Enable changelog auto-updates
        "create": False,  # Create the changelog file if it doesn"t exist
        "open": True,  # Open the changelog file after bumping
        "file": "CHANGELOG.md",  # Name of the changelog file
        "version": "### Version [version]",  # Template for the version line
        "commit": "- [message]",  # Template for the commit line
        "separator": "\n",  # Template for the separator between versions sections
    },
    "commit": {
        "enabled": True,  # Commit the changes automatically
        "message": "Update version to [version]",  # Template for the commit message
        "mainbranch": "master",  # name of the main development or release branch
    },
    "tag": {
        "enabled": True,  # Tag the bump commit
        "name": "v[version]",  # Template for the name of the tag in the tag message
    },
    "tokens": {
        "date": {
            "format": "%Y-%m-%d"  # Python datetime format to use when generating the `[date]` token
        },
        "version_date": {
            "format": "%Y-%m-%d"  # Python datetime format to use when generating the `[version_date]` token
        },
    },
    "scripts": {
        "prebump": "",  # Script to execute before bumping the version
        "postbump": "",  # Script to execute after bumping the version
        "prechangelog": "",  # Script to execute before updating the changelog
        "postchangelog": "",  # Script to execute after updating the changelog
        "precommit": "",  # Script to execute before committing
        "postcommit": "",  # Script to execute after committing
        "pretag": "",  # Script to execute before tagging
        "posttag": "",  # Script to execute after tagging
    },
}

If you want to override any settings, you can do this by creating a ~/.config/versup.json file or a .versup.json in your local project. Versup will read its default settings, then merge in the global config (~/.config/versup.json), and finally merge in the project level config.

Template tags

In various places you can define what text to use for commit messages, or tags etc. These support tag fields that are replaced with relevant information. Known fields are:

  • version: The new version
  • message: The new commit message
  • date: Today's date formatted according to tokens/date/format in the config
  • version_date: Today's date formatted according to tokens/version_date/format in the config
  • hash: The new commit hash, full length
  • hash4: The new commit hash, first four characters
  • hash7: The new commit hash, first seven characters
  • hash8: The new commit hash, first eight characters
  • author_name: The author name from the git config
  • author_email: The author email from the git config

Updating files

versup can update versions in files. The way this works is by configuring a regex for each file that you want to update. So for example:

"files": {
    "README.rst": [
      ["Version ([\\d\\.]+) ", "Version [version] "],
      ["Version is ([\\d\\.]+)", "Version is [version]"]
    ]
  },

Here the file README.rst is updated by matching a regex Version ([\\d\\.]+) which will match any text like Version 1.3 or Version 1.3.7. They are standard regular expressions. The text that is matched is then replaced with the next argument Version [version] where [version] is the new version. You can regex and replace on anything really.

The supported increments are those supported by Python Semver

  • major
  • minor
  • patch
  • prerelease
  • build

Scripts

There are a number of pre and post scripts that can be executed at various stages of the bump process. These are under the scripts section. They are called as-is and receive the new version number as the only argument. They can be anything, shell scripts, python scripts, etc, but they must be executable in a regular shell, as they will be invoked as such.

Full Read The Docs can be found at https://versup.readthedocs.io

versup's People

Contributors

buddly27 avatar svenito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

buddly27

versup's Issues

Improve documentation

Documentation needs to be fleshed out with more details on config settings and command line usage

Ask user for confirmation on branch

It would be great to ask user for confirmation if versup is being executed on a branch.

> version minor
You are tagging branch 'foo', continue? [Yn]

New config options need to be merged into the global config

Right now the global config is merged with the default config so that any new settings are present in the config. This does not change the default config on disk however.

Should the merge be written back to the main config, so that new settings are written to disk?

Command name incorrect when running python -m versup

When running the command via python -m, we get:

>>> python -m versup -h
Usage: __main__.py [OPTIONS] COMMAND [ARGS]...

This is because click default to sys.args[0] if the name is not explicitly given:

It would be great to update versup.command_line.main() to:

def main():
    cli(prog_name="versup")

Option to not update a file except for release

In some cases (changelogs etc) users may not want to update a file with new versions when running a pre-release versup. In that case we'd only want to run the file update on release, patch, minor, major

Add `prepatch`, `preminor`, and `premajor` support

these will add the rc.x to the end and increment the relevant version position also

  • 0.0.1 -> prepatch -> 0.0.2-rc.1
  • 0.0.1 -> preminor -> 0.1.0-rc.1
  • 0.0.1 -> premajor -> 1.0.0-rc.1

A prerelease would update the rc number only, and a new patch, minor, major would keep the version as is and drop the rc (and build if present?)

Option "-h" doesn't work

It would be nice to be able to get the help with -h:

> versup -h
Usage: versup [OPTIONS] COMMAND [ARGS]...
Try 'versup --help' for help.

Error: no such option: -h

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.