Giter VIP home page Giter VIP logo

jv-k / ver-bump Goto Github PK

View Code? Open in Web Editor NEW
22.0 4.0 4.0 714 KB

๐Ÿ“ฆ A really fast & lightweight CLI utility that takes care of releasing Git software projects, put together purely with bash scripting.

Home Page: https://www.npmjs.com/package/ver-bump

License: MIT License

Shell 100.00%
versioning changelog automation package publish release semver release-automation git-branch-develop ver-bump

ver-bump's Introduction

ver-bump

A fully automated handy CLI utility that takes care of releasing GitHub software projects, written in 100% pure bash.

!#/bin/bash CI CodeFactor npm version License: MIT

Highlights ๐Ÿ“ฆ๐Ÿš€

It does several things that are typically required for releasing a Git repository:

  • Create a release branch from your current branch (should be a feature or develop branch, following the Git branch-based workflow, and tags the release
  • Enforces Semantic Versioning specification
  • Avoid potential mistakes associated with manual releases, such as forgetting a step
  • Create and update a changelog file automatically
  • Pushes release to a remote
  • Leaves merging the release branch to the development branch to the user

Table of Contents

Details

Release Steps ๐Ÿ‘ฃ

The command ver-bump will execute the following steps:

Verify + Prepare Release

  • Verify some commits exist
  • Selects a semantic version number for the release branch & tag
  • Increments / suggests a semantic version number for the release and its tag
    • Checks to see a tagged release with the chosen version already exists

Create Release

  • Bump version number in package.json
  • Write CHANGELOG.md
  • Create release branch
  • Commit changes to files made by this script
  • Create a Git tag
  • Push release branch + tag to remote

Release Steps: In detail ๐Ÿ”Ž

Step Description
Verify + Prepare Release Process user arguments Check and store CLI arguments supplied by user for later processing.
Check commits Verify some commits exist for release.
Determine Release Version If <package.json> doesn't exist, warn + exit.

If -v option is specified, set version from that.

Or, grab from version from package.json.

Suggest incremented version number in the form of MAJOR.MINOR.PATCH (incrementing PATCH), as per Semver 2.0.0.

Give the user the option to modify/confirm suggested version bump.
Check branch exist Ensure a release branch with the chosen version number doesn't already exist, if so exit.
Check tag exists Ensure a tag with the chosen version number doesn't exist, and exit if it does.
Create Release Bump version number Update semantic version number in package.json + stages changes.
Generate changelog Commits since the last release are automatically added to CHANGELOG.md, as well as new commit messages for files modified by this script itself. Stages changes for commit action later.
Create release branch Create a branch with the name release-MAJOR.MINOR.PATCH and switch to it (following the Git branch-based workflow).
Commit changed files Commits changes to package.json and CHANGELOG.md` (staged in the previous steps) to the release branch.
Create Git tag Create a Git tag referencing the new release version.
Push Optionally, push the release branch to origin.

Requirements

In order to use ver-bump you need:

  • To host your project code in a Git repository
  • Have Git installed in your environment
  • Have npm and node installed

Installation

Install the script globally via npm, and use it in any local Git repository to release your project:

$ npm install -g ver-bump

Usage

Pre-requisites

  • Make sure you have package.json file in your project and it contains a "version": "x.x.x" parameter
  • You have done some work and have some existing commits
  • You have the ability to push to your Git remote via the Git CLI

CLI

$ ver-bump [-v <version no.>] [-m <release message>] [-j <file1>] [-j <file2>].. [-n] [-p] [-b] [-h]

Options

-v <version number>     Specify a manual version number
-m <release message>    Custom release message
-f <filename.json>      Update version number inside JSON files.
                            * For multiple files, add a separate -f option for each one,
                            * For example:
                              ./ver-bump.sh -f src/plugin/package.json -f composer.json
-p <repository alias>   Push commits to remote repository, eg `-p Origin`
-n                      Turns off automatic commit
                            * You may want to do that yourself, for example.
-b                      Don't create automatic `release-<version>` branch.
-c                      Disable updating CHANGELOG.md automatically with new commits
                        since last release tag.
-l                      Pause enabled for amending CHANGELOG.md
-h                      Show help message.

Example

This example assumes that a package.json contains version: "1.0.0", and the user is working in the branch to be released with pre-existing un-released commits.

  1. This will create a new Git branch called release-1.0.1 and a Git tag named v1.0.1:

    $ ver-bump

    Output:

    Current version read from <package.json> file: 1.0.0
    
    Enter a new version number or press <enter> to use [1.0.1]: <pressed enter>
    
    โ€“โ€“โ€“โ€“โ€“โ€“
    
    โœ… Updated file <package.json> from 1.0.0 -> 1.0.1
    
    โœ… Updated [CHANGELOG.md] file
    
    Make adjustments to [CHANGELOG.md] if required now. Press <enter> to continue.
    
    Creating new release branch...
    
    โœ… Switched to branch 'release-1.0.1'
    M CHANGELOG.md
    M package.json
    
    Committing...
    
    โœ… [release-1.0.1 ace8b1e] Updated package.json, Updated CHANGELOG.md, Bumped 1.0.0 โ€“> 1.0.1
    2 files changed, 9 insertions(+), 1 deletion(-)
    
    โœ… Added GIT tag
    
    Push tags to <origin>? [N/y]: n
    
    โ€“โ€“โ€“โ€“โ€“โ€“
    
    โœ… Bumped 1.0.0 โ€“> 1.0.1
    
    ๐Ÿ Done!
    
  2. After checking out the changes in the branch and confirming them, test the release, and push the release branch to your remote if you didn't choose to push it automatically. Alternatively, use $ ver-bump -p origin to bypass the prompt and push the release branch anyway to the remote automatically.

  3. If your code checks out, then open a Pull Request to merge the release branch into your develop or main branch.

    You can merge the release branch into your development branch or main branch like this, without fast-forwarding so that the branch topology is preseved as you're merging in a release branch that hasn't diverged (apart from new changes to CHANGELOG.md and package.json) and you want to ensure it's clearly evident when reading the history that a merge was performed, as opposed to a fast-forward merge, where new commits performed by the merge will become descendents of the last commit before the merge.

    A release branch shouldn't normally diverge from the branch it was created during the time ver-bump is operating, so a non-fastforward should be possible instead of a normal merge, which would simply looks like a new commit was made to the main or development branch.

    $ git checkout develop # Switch to development branch from the new release branch
    
    $ git merge --no-ff release-1.0.1 # Merge the new release branch to your development branch

Tests

This project uses bats to test the functionality of ver-bump.

To run the tests, first install the pre-requisites:

Linux/MacOS:

$ npm run tests:install

Windows:

$ npm run tests:install:windows

And finally, run the test suite:

$ npm run tests:run

Output:

ver-bump.bats
 โœ“ can run script
 โœ“ process-arguments: -h: display help message
 โœ“ process-arguments: -v: fail when not supplying version
 โœ“ process-arguments: -v x.x.x: succeed when supplying version
 โœ“ process-arguments: -m: fail when not supplying release note
 โœ“ process-arguments: -m <note>: succeed when supplying release note
 โœ“ process-arguments: -f: fail when not supplying filenames
 โœ“ process-arguments: -f <filename.json>: succeed with multiple filenames
 โœ“ process-arguments: -p: fail when not supplying push destination
 โœ“ process-arguments: -p <repo destination>: succeed when supplying a destination
 โœ“ process-arguments: -n: set flag to prevent committing at the end
 โœ“ process-arguments: -b: set flag to disable creating a release branch
 โœ“ process-arguments: -c: set flag to disable creating/updating CHANGELOG.md
 โœ“ process-arguments: -l: set flag to enable pausing after CHANGELOG.md is created
 โœ“ process-arguments: fail on not-existing argument
 โœ“ set-v-suggest: increments version
 โœ“ set-v-suggest: fails to increments non SemVer version
 โœ“ process-version: fail on entering non-SemVer input
 โœ“ process-version: patch of the version from json file should be bumped +1
 โœ“ do-packagefile-bump: can bump version in package.json + lock file
 โœ“ bump-json-files: can bump version in a json file
 โœ“ bump-json-files: can fail bumping a json file when a version already exists in file
 โœ“ bump-json-files: can fail bumping a json file when no version found inside it
 โœ“ check-branch-notexist: can detect branch DOES exist
 โœ“ check-branch-notexist: can confirm branch DOES'NT exist
 โœ“ do-branch: can create a release branch
 โœ“ do-tag: create a tag
 โœ“ check-tag-exists: check doesn't exist
 โœ“ check-tag-exists: check it exists
 โœ“ do-changelog: can create a CHANGELOG.md

30 tests, 0 failures

Contributing

I'd love you to contribute to @jv-k/ver-bump, pull requests are welcome for submitting issues and bugs!

License

The scripts and documentation in this project are released under the MIT license.

ver-bump's People

Contributors

jv-k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ver-bump's Issues

.md

ver-bump/CHANGELOG.md

Lines 4 to 9 in 27318ba

- Update TODO.md
- Changed webhook for action
- Added build tast
- Publish to GitHub Package Registry and NPM
- Merge branch 'develop' into main
- Merge branch 'release-1.0.1' into develop


This issue was generated by todo based on a TODO comment in 27318ba when #10 was merged. cc @jv-k.

option to bypass changelog edit

Hello, thanks for this great tool. In order to speed up the workflow I would like to bypass the "Make adjustments to [CHANGELOG.md] if required now" enter hit

Is it possible to add an option (similar to -p) so that user is not asked to hit enter anymore?

Thanks!

Version number in `package-lock.json` not bumped

Version number in package-lock.json not bumped

ver-bump: v1.0.1

To Reproduce
Steps to reproduce the behaviour:

npm i -g ver-bump # install ver-bump globally

mkdir test-repo && cd test-repo

git init # init empty repo

# accept all default values (version is 1.0.0)
npm init # create package.json

# install at least one package to create a package-lock.json file
npm i semver -s

# provide a commit for ver-bump to release 
git add -A && git commit -m "First commit"

$ ver-bump -v 1.0.1

Open package.json, and you see the old version number "version": "1.0.0"

Only package.json shows 1.0.1.

Expected behavior
Both package.json and package-lock.json should be bumped to 1.0.1

npm ERR! Git working directory not clean.

When running ver-bump when there are uncommitted changes in the folder, stashing or committing the changes are unintentionally forced, as the following error is produced from the internal call to npm version x.x.x:

npm ERR! Git working directory not clean.

Releasing a version without bumping version number fails

Describe the bug
Releasing a version without bumping version number fails, even though this version hasn't been released yet (ie the tags and release branch don't exist already). For example, the first time releasing a repo we want the initial version to be 0.1.0, and we don't want to increase the semantic version number that's already in package.json. However, this (common) scenario fails.

To Reproduce
Steps to reproduce the behaviour:

  1. mkdir test-repo
  2. git init && npm init
  3. git add package.json && git commit -m "first commit"
  4. Run ver-bump in this folder with default options, except leave the version number the same as the existing one in package.json

Expected behavior
ver-bump should add a tag v1.0.0 (or whatever the local git's default starting version number is etc), create a release branch, and not increment the version number in package.json

Instead it fails with:
๐Ÿšซ Error updating <package.json> and/or <package-lock.json>

No option to automate a release

Is your feature request related to a problem? Please describe.

Releasing a GitHub project from a tagged commit done using ver-bump involves a few extra steps, either required to be performed on the web interface, or locally with a CLI tool like gh release. Since this tool is for automating/simplifying tagging/release git projects, then it makes sense to keep this all in the CLI and let the one tool take care of it all (after all, it was the point of this project to help me in my own workflow for this very reason).

Describe the solution you'd like

  • Implement the feature to release as an option.

  • Should be configured either interactively, or by extra switches to make it fully automated.

  • Add option to write the changelog since the last release as the release notes.

  • Add unit/integration tests for it with bats-core too.

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.