From b85b7284724177053b2e12e638cc8ba6d092a7d0 Mon Sep 17 00:00:00 2001 From: Mark Challoner Date: Tue, 23 Oct 2018 06:53:14 +0100 Subject: [PATCH 1/8] Add pre-release and build options. (#27) --- .git-semver/plugins/keepachangelog.sh | 6 + CHANGELOG.md | 10 +- CONTRIBUTING.md | 6 + README.md | 49 +++++-- git-semver.sh | 187 +++++++++++++++++++++++--- plugins/keepachangelog.sh | 6 + 6 files changed, 229 insertions(+), 35 deletions(-) diff --git a/.git-semver/plugins/keepachangelog.sh b/.git-semver/plugins/keepachangelog.sh index 302b4b5..e7f2d4c 100755 --- a/.git-semver/plugins/keepachangelog.sh +++ b/.git-semver/plugins/keepachangelog.sh @@ -22,6 +22,12 @@ function run() { local version_new_actual="[${version_new}]" local version_previous= + # If the new version just has build information then skip the check + if [ "${version_new%+*}" == "${version_current%+*}" ] + then + return ${status} + fi + # If there is no existing version relax rules slightly if [ "" == "${version_current}" ] then diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d4fc2a..51eb2b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. -This project adheres to [Semantic Versioning](http://semver.org/). -This file uses change log convention from [Keep a CHANGELOG](http://keepachangelog.com). +This project adheres to [Semantic Versioning]. +This file uses change log convention from [Keep a CHANGELOG]. ## [Unreleased][unreleased] +### Added +- Added pre-release and build options. Note: the [keepachangelog.sh plugin] this will need to be updated to +ignore versions which only differ in build metadata. ## [3.0.1] - 2018-07-13 ### Fixed @@ -89,8 +92,11 @@ This file uses change log convention from [Keep a CHANGELOG](http://keepachangel [CHANGELOG.md]: CHANGELOG.md [CONTRIBUTING.md]: CONTRIBUTING.md +[keepachangelog.sh plugin]: plugins/keepachangelog.sh +[Keep a CHANGELOG]: http://keepachangelog.com [LICENCE.md]: LICENCE.md [README.md]: README.md +[Semantic Versioning]: http://semver.org/ [xdg_basedirs]: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html [unreleased]: https://github.com/markchalloner/git-semver/compare/3.0.1...HEAD diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2a50346..24a9cdc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,8 +6,14 @@ We accept contributions via Pull Requests on [Github](https://github.com/markcha ## Contributers +### Users with merges + - https://github.com/markchalloner/git-semver/graphs/contributors +### Others + +- [@jaapio](https://github.com/jaapio) ([#26](https://github.com/markchalloner/git-semver/pull/26)) + ## Pull Requests - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. diff --git a/README.md b/README.md index f9527f2..45aef99 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ The installer will not overwrite any existing [configuration](#configuration) or ## Usage -### Get latest version tag +### Get highest version tag ``` bash git semver get @@ -65,38 +65,61 @@ Will return empty if no version has been created. Versions are created as tags and are generated using: ``` bash -git semver [major|minor|patch|next] +git semver [major|minor|patch|next|pre-release|build] [-p ] [-b ] ``` -#### Patch (Next) +#### Major -Increment the patch component (0.1.0 -> 0.1.1) +Increment the major component (0.1.0 -> 1.0.0), optionally adding a pre-release version and build metadata. ``` bash -git semver patch|next +git semver major [-p ] [-b ] ``` -If no version has been created, the initial version will be: **0.1.0** +If no version has been created, the initial version will be: **1.0.0\[-\]\[+\]** #### Minor -Increment the minor component (0.1.0 -> 0.2.0) +Increment the minor component (0.1.0 -> 0.2.0), optionally adding a pre-release version and build metadata. ``` bash -git semver minor +git semver minor [-p ] [-b ] ``` -If no version has been created, the initial version will be: **0.1.0** +If no version has been created, the initial version will be: **0.1.0\[-\]\[+\]** -#### Major -Increment the major component (0.1.0 -> 1.0.0) +#### Patch (Next) + +Increment the patch component (0.1.0 -> 0.1.1), optionally adding a pre-release version and build metadata. + +``` bash +git semver patch|next [-p ] [-b ] +``` + +If no version has been created, the initial version will be: **0.1.0\[-\]\[+\]** + +#### Pre-release + +Create a new pre-release version based on the next patch version if a release version exists (0.1.0 -> +0.1.1-) or the current patch version (0.1.0-alpha -> 0.1.0-) if it does not, +optionally adding build metadata. + +``` bash +git semver pre-release -p [-b ] +``` + +If no version has been created, the initial version will be: **0.1.0-\[+\]** + +#### Build + +Create a new build based on the current patch version. ``` bash -git semver major +git semver build -b ``` -If no version has been created, the initial version will be: **1.0.0** +If no version has been created, the initial version will be: **0.1.0+** ### Help diff --git a/git-semver.sh b/git-semver.sh index 437eeac..9372e68 100755 --- a/git-semver.sh +++ b/git-semver.sh @@ -12,10 +12,12 @@ usage() { See https://github.com/markchalloner/git-semver for more detail. Commands - get Gets the current version (tag) - major Generates a tag for the next major version and echos it to the screen - minor Generates a tag for the next minor version and echos it to the screen - patch|next Generates a tag for the next patch version and echos it to the screen + get Gets the current version (tag) + major [-p ] [-b ] Generates a tag for the next major version and echos to the screen + minor [-p [ [-b ] Generates a tag for the next minor version and echos to the screen + patch|next [-p ] [-b ] Generates a tag for the next patch version and echos to the screen + pre-release -p [-b ] Generates a tag for a pre-release version and echos to the screen + build -b Generates a tag for a build and echos to the screen help This message EOF @@ -124,12 +126,35 @@ plugin-debug() { plugin-run "$new" "$version" } +validate-pre-release() { + local pre_release=$1 + if ! [[ "$pre_release" =~ ^[0-9A-Za-z.-]*$ ]] || # Not alphanumeric, `-` and `.` + [[ "$pre_release" =~ (^|\.)\. ]] || # Empty identifiers + [[ "$pre_release" =~ \.(\.|$) ]] || # Empty identifiers + [[ "$pre_release" =~ \.0[0-9] ]] # Leading zeros + then + echo "Error: pre-release is not valid." + exit 1 + fi +} + +validate-build() { + local build=$1 + if ! [[ "$build" =~ ^[0-9A-Za-z.-]*$ ]] || # Not alphanumeric, `-` and `.` + [[ "$build" =~ (^|\.)\. ]] || # Empty identifiers + [[ "$build" =~ \.(\.|$) ]] # Empty identifiers + then + echo "Error: build metadata is not valid." + exit 1 + fi +} + ######################################## # Version functions ######################################## version-parse-major() { - echo "$1" | cut -d "." -f1 + echo "$1" | cut -d "." -f1 | sed 's/^${VERSION_PREFIX}//g' } version-parse-minor() { @@ -137,12 +162,55 @@ version-parse-minor() { } version-parse-patch() { - echo "$1" | cut -d "." -f3 + echo "$1" | cut -d "." -f3 | sed 's/[-+].*$//g' +} + +version-parse-pre-release() { + echo "$1" | cut -d "." -f3 | grep -o '\-[0-9A-Za-z.]\+' } version-get() { - # shellcheck disable=SC2155 - local version=$(git tag | grep "^${VERSION_PREFIX}[0-9]\+\.[0-9]\+\.[0-9]\+$" | sed "s/^${VERSION_PREFIX}//" | sort -t. -k 1,1n -k 2,2n -k 3,3n | tail -1) + local sort_args version version_pre_releases pre_release_id_count pre_release_id_index + local tags=$(git tag) + local version_pre_release=$( + local version_main=$( + echo "$tags" | + grep "^${VERSION_PREFIX}[0-9]\+\.[0-9]\+\.[0-9]\+" | + awk -F '[-+]' '{ print $1 }' | + uniq | + sort -t '.' -k 1,1n -k 2,2n -k 3,3n | + tail -n 1 + ) + local version_pre_releases=$( + echo "$tags" | + grep "^${version_main//./\\.}" | + awk -F '-' '{ print $2 }' + ) + local pre_release_id_count=$( + echo "$version_pre_releases" | tr -d -c ".\n" | + awk 'BEGIN{ max = 0 } + { if (max < length) { max = length } } + END{ if ( max == 0 ) { print 0 } else { print max + 1 } }' + ) + local sort_args='-t.' + for ((pre_release_id_index=1; pre_release_id_index<=$pre_release_id_count; pre_release_id_index++)) + do + chars="$(echo "$version_pre_releases" | awk -F '.' '{ print $'$pre_release_id_index' }' | tr -d $'\n')" + if [[ "$chars" =~ ^[0-9]*$ ]] + then + sort_key_type=n + else + sort_key_type= + fi + sort_args="$sort_args -k$pre_release_id_index,$pre_release_id_index$sort_key_type" + done + echo "$version_pre_releases" | + eval sort $sort_args | + awk '{ if (length == 0) { print "'$version_main'" } else { print "'$version_main'-"$1 } }' | + tail -n 1 + ) + # Get the version with the build number + version=$(echo "$tags" | grep "^${version_pre_release//./\\.}" | tail -n 1) if [ "" == "${version}" ] then return 1 @@ -152,20 +220,24 @@ version-get() { } version-major() { + local pre_release=${1:+-$1} + local build=${2:++$2} # shellcheck disable=SC2155 local version=$(version-get) # shellcheck disable=SC2155 local major=$(version-parse-major "${version}") if [ "" == "$version" ] then - local new=${VERSION_PREFIX}1.0.0 + local new=${VERSION_PREFIX}1.0.0${pre_release}${build} else - local new=${VERSION_PREFIX}$((major+1)).0.0 + local new=${VERSION_PREFIX}$((major+1)).0.0${pre_release}${build} fi version-do "$new" "$version" } version-minor() { + local pre_release=${1:+-$1} + local build=${2:++$2} # shellcheck disable=SC2155 local version=$(version-get) # shellcheck disable=SC2155 @@ -174,14 +246,36 @@ version-minor() { local minor=$(version-parse-minor "${version}") if [ "" == "$version" ] then - local new=${VERSION_PREFIX}0.1.0 + local new=${VERSION_PREFIX}0.1.0${pre_release}${build} else - local new=${VERSION_PREFIX}${major}.$((minor+1)).0 + local new=${VERSION_PREFIX}${major}.$((minor+1)).0${pre_release}${build} fi version-do "$new" "$version" } version-patch() { + local pre_release=${1:+-$1} + local build=${2:++$2} + # shellcheck disable=SC2155 + local version=$(version-get) + # shellcheck disable=SC2155 + local major=$(version-parse-major "${version}") + # shellcheck disable=SC2155 + local minor=$(version-parse-minor "${version}") + # shellcheck disable=SC2155 + local patch=$(version-parse-patch "${version}") + if [ "" == "$version" ] + then + local new=${VERSION_PREFIX}0.1.0${pre_release}${build} + else + local new=${VERSION_PREFIX}${major}.${minor}.$((patch+1))${pre_release}${build} + fi + version-do "$new" "$version" +} + +version-pre-release() { + local pre_release=$1 + local build=${2:++$2} # shellcheck disable=SC2155 local version=$(version-get) # shellcheck disable=SC2155 @@ -192,9 +286,30 @@ version-patch() { local patch=$(version-parse-patch "${version}") if [ "" == "$version" ] then - local new=${VERSION_PREFIX}0.1.0 + local new=${VERSION_PREFIX}0.1.0-${pre_release}${build} else - local new=${VERSION_PREFIX}${major}.${minor}.$((patch+1)) + local new=${VERSION_PREFIX}${major}.${minor}.${patch}-${pre_release}${build} + fi + version-do "$new" "$version" +} + +version-build() { + local build=$1 + # shellcheck disable=SC2155 + local version=$(version-get) + # shellcheck disable=SC2155 + local major=$(version-parse-major "${version}") + # shellcheck disable=SC2155 + local minor=$(version-parse-minor "${version}") + # shellcheck disable=SC2155 + local patch=$(version-parse-patch "${version}") + # shellcheck disable=SC2155 + local pre_release=$(version-parse-pre-release "${version}") + if [ "" == "$version" ] + then + local new=${VERSION_PREFIX}0.1.0${pre_release}+${build} + else + local new=${VERSION_PREFIX}${major}.${minor}.${patch}${pre_release}+${build} fi version-do "$new" "$version" } @@ -242,21 +357,53 @@ DIR_ROOT="$(git rev-parse --show-toplevel 2> /dev/null)" GIT_HASH="$(git rev-parse HEAD 2> /dev/null)" GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)" -# Set $1 to last argument. -for _; do true; done +# Parse args +action= +build= +pre_release= +while : +do + case "$1" in + -b) + build=$2 + shift + validate-build "$build" + ;; + -p) + pre_release=$2 + shift + validate-pre-release "$pre_release" + ;; + ?*) + action=$1 + ;; + *) + break + ;; + esac + shift +done -case "$1" in +case "$action" in get) version-get ;; major) - version-major + version-major "$pre_release" "$build" ;; minor) - version-minor + version-minor "$pre_release" "$build" ;; patch|next) - version-patch + version-patch "$pre_release" "$build" + ;; + pre-release) + [ -n "$pre_release" ] || usage + version-pre-release "$pre_release" "$build" + ;; + build) + [ -n "$build" ] || usage + version-build "$build" ;; debug) plugin-debug diff --git a/plugins/keepachangelog.sh b/plugins/keepachangelog.sh index 08a5d56..407535f 100755 --- a/plugins/keepachangelog.sh +++ b/plugins/keepachangelog.sh @@ -23,6 +23,12 @@ function run() { local version_new_actual="[${version_new}]" local version_previous= + # If the new version just has build information then skip the check + if [ "${version_new%+*}" == "${version_current%+*}" ] + then + return ${status} + fi + # If there is no existing version relax rules slightly if [ "" == "${version_current}" ] then From 86ebd64ebf3c89be7cbde75488efb074950cff2d Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 22 Oct 2018 22:55:35 -0700 Subject: [PATCH 2/8] Read config from .git-semver in the base of the repository if it exists. (#29) --- README.md | 1 + git-semver.sh | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 45aef99..695f46b 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ git semver [help] Git-semver will check for a configuration file in the following locations (and use the one that exists): +- `$GIT_REPO_ROOT/.git-semver` - `$XDG_CONFIG_HOME/.git-semver/config` - `$HOME/.git-semver/config` diff --git a/git-semver.sh b/git-semver.sh index 9372e68..0074298 100755 --- a/git-semver.sh +++ b/git-semver.sh @@ -340,8 +340,15 @@ readonly DIR_HOME="${HOME}" # (see http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) DIR_CONF="${XDG_CONFIG_HOME:-${HOME}}/.git-semver" +# Set vars +DIR_ROOT="$(git rev-parse --show-toplevel 2> /dev/null)" + # Set (and load) user config -if [ -f "${DIR_CONF}/config" ] +if [ -f "${DIR_ROOT}/.git-semver" ] +then + FILE_CONF="${DIR_ROOT}/.git-semver" + source "${FILE_CONF}" +elif [ -f "${DIR_CONF}/config" ] then FILE_CONF="${DIR_CONF}/config" # shellcheck source=config.example @@ -351,9 +358,6 @@ else FILE_CONF="${DIR_HOME}/.git-semver/config" fi -# Set vars -DIR_ROOT="$(git rev-parse --show-toplevel 2> /dev/null)" - GIT_HASH="$(git rev-parse HEAD 2> /dev/null)" GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)" From 86ce36eccce472a3c834d0b921a864491a483a1a Mon Sep 17 00:00:00 2001 From: Stefan Linke Date: Tue, 23 Oct 2018 07:57:02 +0200 Subject: [PATCH 3/8] Fix links in README and PLUGINS.md (#30) The links in the TOC were broken in both files. --- PLUGINS.md | 4 ++-- README.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 761b4f4..afb870c 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -5,8 +5,8 @@ - [Introduction](#introduction) - [Installation](#installation) - [Plugins](#plugins) - - [Keep A Changelog](#keep-a-changelog) - - [NPM `package.json`](#npm-package-json) + - [Keep A Changelog](#keep-a-changelog---keepachangelogsh) + - [NPM `package.json`](#npm-packagejson---npmpackagejsonsh) - [Contributing](#contributing) ## Introduction diff --git a/README.md b/README.md index 695f46b..62ab35a 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ - [Introduction](#introduction) - [Installation](#installation) -- [Plugins](#plugins) - - [Keep A Changelog](#keep-a-changelog) - - [NPM package.json](#npm-package-json) +- [Plugins](PLUGINS.md) + - [Keep A Changelog](PLUGINS.md#keep-a-changelog---keepachangelogsh) + - [NPM package.json](PLUGINS.md#npm-packagejson---npmpackagejsonsh) - [Contributing](#contributing) ## Introduction From c884191302f9137a621423cd7504206d5bbca432 Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 23 Oct 2018 22:25:58 -0700 Subject: [PATCH 4/8] Fix stripping VERSION_PREFIX from major versions to prevent creating versions with double versions. (#33) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I had a `VERSION_PREFIX=v` which caused my versions to have two "v": ``` ➜ fluxcloud git:(master) ✗ git semver --dryrun patch vv0.2.11 ➜ fluxcloud git:(master) ✗ ``` Bash does not interpolate variables inside of single quotes, so this fixes the sed command in version-parse-major to use double quotes so that the VERSION_PREFIX gets properly stripped. --- git-semver.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-semver.sh b/git-semver.sh index 0074298..5fd8549 100755 --- a/git-semver.sh +++ b/git-semver.sh @@ -154,7 +154,7 @@ validate-build() { ######################################## version-parse-major() { - echo "$1" | cut -d "." -f1 | sed 's/^${VERSION_PREFIX}//g' + echo "$1" | cut -d "." -f1 | sed "s/^${VERSION_PREFIX}//g" } version-parse-minor() { From 4a00f79c3023a76359e94b4606e538eab5b2590e Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 23 Oct 2018 22:27:39 -0700 Subject: [PATCH 5/8] Add --dryrun flag to semver commands to allow checking tags without creating them. (#28) --- README.md | 8 +++++++- git-semver.sh | 26 ++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 62ab35a..49331f0 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,13 @@ Will return empty if no version has been created. Versions are created as tags and are generated using: ``` bash -git semver [major|minor|patch|next|pre-release|build] [-p ] [-b ] +git semver [major|minor|patch|next|pre-release|build] [--dryrun] [-p ] [-b ] +``` + +To see what a tag would be without actually creating it, run a dryrun with `-d` or `--dryrun`: + +``` +git semver patch --dryrun ``` #### Major diff --git a/git-semver.sh b/git-semver.sh index 5fd8549..51cbfc6 100755 --- a/git-semver.sh +++ b/git-semver.sh @@ -12,13 +12,13 @@ usage() { See https://github.com/markchalloner/git-semver for more detail. Commands - get Gets the current version (tag) - major [-p ] [-b ] Generates a tag for the next major version and echos to the screen - minor [-p [ [-b ] Generates a tag for the next minor version and echos to the screen - patch|next [-p ] [-b ] Generates a tag for the next patch version and echos to the screen - pre-release -p [-b ] Generates a tag for a pre-release version and echos to the screen - build -b Generates a tag for a build and echos to the screen - help This message + get Gets the current version (tag) + major [--dryrun] [-p ] [-b ] Generates a tag for the next major version and echos to the screen + minor [--dryrun] [-p [ [-b ] Generates a tag for the next minor version and echos to the screen + patch|next [--dryrun] [-p ] [-b ] Generates a tag for the next patch version and echos to the screen + pre-release [--dryrun] -p [-b ] Generates a tag for a pre-release version and echos to the screen + build [--dryrun] -b Generates a tag for a build and echos to the screen + help This message EOF exit @@ -323,7 +323,10 @@ version-do() { then cmd="$cmd -as -m $new" fi - if plugin-run "$new" "$version" + if [ $dryrun == 1 ] + then + echo "$new" + elif plugin-run "$new" "$version" then $cmd "$new" && echo "$new" fi @@ -365,9 +368,16 @@ GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)" action= build= pre_release= +dryrun=0 while : do case "$1" in + -d) + dryrun=1 + ;; + --dryrun) + dryrun=1 + ;; -b) build=$2 shift From 88d180e96fc0c3bdda31bbcb88db124e17a538d8 Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Thu, 4 Apr 2019 01:21:51 -0300 Subject: [PATCH 6/8] Add setup.py version plugin (#37) * Updated documentation * Ranamed plugin to ensure execution order * Fixed sed regex * Added comment about non-extended regex syntax --- PLUGINS.md | 6 ++++++ plugins/10-setuppy_update.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100755 plugins/10-setuppy_update.sh diff --git a/PLUGINS.md b/PLUGINS.md index afb870c..a4187eb 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -76,6 +76,12 @@ The [`package.json`] file is used by [NPM], typically for [Node.js] applications } ``` +### Python `setup.py` - [`setuppy_update.sh`] + +This plugin makes sure you never forget to update your package version. + +When active, it will search for a setup.py file in the root of the project, and change the `version` argument passed to the setup class to the version being tagged. Then, it will commit it with a "Updated setup.py version" message. + ## Contributing A plugin can be any executable file stored in `.git-semver/plugins/`. diff --git a/plugins/10-setuppy_update.sh b/plugins/10-setuppy_update.sh new file mode 100755 index 0000000..85bfc89 --- /dev/null +++ b/plugins/10-setuppy_update.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +function run() { + + local version_new="$1" + local git_root="$5" + + local setuppy_path="${git_root}/setup.py" + + if [ ! -e "${setuppy_path}" ] + then + echo "Could not find setup.py on the project root." + return 112 + fi + + tmpfile=$(mktemp) + # Extended regexs are purposely avoided for Mac OS and Free BSD compatbility. + sed "s/version[[:blank:]]*=[[:blank:]]*[\",'][0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*[\"'][[:blank:]]*,/version=\"${version_new}\",/" < "${git_root}/setup.py" > "${tmpfile}" + cat "${tmpfile}" > "${setuppy_path}" + rm -f "${tmpfile}" + + git add "${setuppy_path}" + git commit "${setuppy_path}" -m "Updated setup.py version" + return 0 + +} + +case "${1}" in + --about) + echo -n "Change the version argument of the project's setup.py to the new created version." + ;; + *) + run "$@" + ;; +esac From 1ef1828c0e8046eaceaaf60dbc50bdfb1247da6e Mon Sep 17 00:00:00 2001 From: Mark Challoner Date: Thu, 4 Apr 2019 05:26:23 +0100 Subject: [PATCH 7/8] Remove errant comma in regex. --- plugins/10-setuppy_update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/10-setuppy_update.sh b/plugins/10-setuppy_update.sh index 85bfc89..9efd95e 100755 --- a/plugins/10-setuppy_update.sh +++ b/plugins/10-setuppy_update.sh @@ -15,7 +15,7 @@ function run() { tmpfile=$(mktemp) # Extended regexs are purposely avoided for Mac OS and Free BSD compatbility. - sed "s/version[[:blank:]]*=[[:blank:]]*[\",'][0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*[\"'][[:blank:]]*,/version=\"${version_new}\",/" < "${git_root}/setup.py" > "${tmpfile}" + sed "s/version[[:blank:]]*=[[:blank:]]*[\"'][0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*[\"'][[:blank:]]*,/version=\"${version_new}\",/" < "${git_root}/setup.py" > "${tmpfile}" cat "${tmpfile}" > "${setuppy_path}" rm -f "${tmpfile}" From 7725e8f1901dd425390ae4833ddd4f9ec5949504 Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Thu, 18 Apr 2019 10:53:01 -0300 Subject: [PATCH 8/8] Major and minor tag plugin (#38) --- PLUGINS.md | 8 ++++++ plugins/90-major_and_minor_tag.sh | 42 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 plugins/90-major_and_minor_tag.sh diff --git a/PLUGINS.md b/PLUGINS.md index a4187eb..f5de7c9 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -76,6 +76,14 @@ The [`package.json`] file is used by [NPM], typically for [Node.js] applications } ``` +### Major and minor tags - [`90-major_and_minor_tag.sh`] + +This plugins creates 2 extra tags each time you `git-semver major` or `git-semver minor`, one with the minor version and other with the major one. + +In other words, if you create a `3.0.0` version, this plugin will also create a `3.0` and `3` tag. Also, if you create a `3.1.0` tag, it will delete the previously created `3` tag, and create it again pointing to the `3.1.0` commit, together with a brand new `3.1` tag. + +This is useful, for example, to maintain multiple versions of an API: If you have a legacy version `1.5.3` API you need to maintain, and a new version `2`, you can use this plugin to maintain a "rolling" `1.5` tag, and always deploy the latest bugfix for your legacy API, and maybe build against a `2` tag for the new one, to get the latest features. + ### Python `setup.py` - [`setuppy_update.sh`] This plugin makes sure you never forget to update your package version. diff --git a/plugins/90-major_and_minor_tag.sh b/plugins/90-major_and_minor_tag.sh new file mode 100644 index 0000000..336a03c --- /dev/null +++ b/plugins/90-major_and_minor_tag.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +function run() { + + local version_new="$1" + + local minor_number=$(echo "$version_new" | cut --delimiter="." --fields=2) + local major_number=$(echo "$version_new" | cut --delimiter="." --fields=1) + + minor_tag="$major_number"."$minor_number" + if git tag --list | grep -xq "$minor_tag" + then + echo "Recreating minor tag $minor_tag" + git tag --delete "$minor_tag" + else + echo "Creating minor tag $minor_tag" + fi + git tag "$minor_tag" + + if git tag --list | grep -xq "$major_number" + then + echo "Recreating major tag $major_number" + git tag --delete "$major_number" + else + echo "Creating major tag ""$major_number" + fi + git tag "$major_number" + + echo + + return 0 +} + +case "${1}" in + --about) + echo -n "Create or recreate a minor and major tag on each version bump." + ;; + *) + run "$@" + ;; +esac +