From 3e6b7b2327f1b13e4dbd2b83f0e77197ddb02b1b Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Mon, 18 Mar 2019 16:35:44 -0300 Subject: [PATCH 01/12] Added setup.py updater plugin --- plugins/setuppy_update.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 plugins/setuppy_update.sh diff --git a/plugins/setuppy_update.sh b/plugins/setuppy_update.sh new file mode 100755 index 0000000..4ae5474 --- /dev/null +++ b/plugins/setuppy_update.sh @@ -0,0 +1,34 @@ +#!/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) + 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 36edd912204cef91ce4c4358ee9fbb2025d556a4 Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Mon, 18 Mar 2019 16:35:52 -0300 Subject: [PATCH 02/12] Updated documentation --- PLUGINS.md | 6 ++++++ 1 file changed, 6 insertions(+) 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/`. From e95ba5b75fa7cba696a6862acdbab88f9b480532 Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Tue, 26 Mar 2019 19:12:53 -0300 Subject: [PATCH 03/12] Add plugin sorting before execution --- git-semver.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git-semver.sh b/git-semver.sh index 51cbfc6..848a653 100755 --- a/git-semver.sh +++ b/git-semver.sh @@ -63,7 +63,10 @@ plugin-list() { plugin_dir="${dirs[${i}]}/.git-semver/plugins" if [ -d "${plugin_dir}" ] then - find "${plugin_dir}" -maxdepth 1 -type f -exec echo "${plugin_type},{}" \; + for plugin in $(find "${plugin_dir}" -maxdepth 1 -type f | sort -k 1.1n,1.2n) + do + echo "${plugin_type},${plugin}" + done fi done } From 0687d9dd5e0998ecc376d583a18aff17336ac11e Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Wed, 27 Mar 2019 15:51:05 -0300 Subject: [PATCH 04/12] Add major and minor version plugin --- plugins/90-major_and_minor_tag.sh | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 plugins/90-major_and_minor_tag.sh diff --git a/plugins/90-major_and_minor_tag.sh b/plugins/90-major_and_minor_tag.sh new file mode 100644 index 0000000..7349773 --- /dev/null +++ b/plugins/90-major_and_minor_tag.sh @@ -0,0 +1,39 @@ +#!/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) + + if git tag --list | grep -xq "$major_number"".""$minor_number" + then + echo "Recreating minor tag ""$major_number"".""$minor_number" + git tag delete "$major_number"".""$minor_number" + else + echo "Creating minor tag ""$major_number"".""$minor_number" + fi + git tag "$major_number"".""$minor_number" + + 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" + + return 0 +} + +case "${1}" in + --about) + echo -n "Example plugin." + ;; + *) + run "$@" + ;; +esac + From 126f65fe0b08d691c4c6823e8d36e14d0cf0df62 Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Wed, 27 Mar 2019 15:52:49 -0300 Subject: [PATCH 05/12] Ranamed plugin to ensure execution order --- plugins/{setuppy_update.sh => 10-setuppy_update.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename plugins/{setuppy_update.sh => 10-setuppy_update.sh} (100%) diff --git a/plugins/setuppy_update.sh b/plugins/10-setuppy_update.sh similarity index 100% rename from plugins/setuppy_update.sh rename to plugins/10-setuppy_update.sh From 9e7f17406ad4a77ffe885ebce869d178ae63302f Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Mon, 1 Apr 2019 12:36:47 -0300 Subject: [PATCH 06/12] Fixed delete argument --- plugins/90-major_and_minor_tag.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/90-major_and_minor_tag.sh b/plugins/90-major_and_minor_tag.sh index 7349773..8297079 100644 --- a/plugins/90-major_and_minor_tag.sh +++ b/plugins/90-major_and_minor_tag.sh @@ -10,7 +10,7 @@ function run() { if git tag --list | grep -xq "$major_number"".""$minor_number" then echo "Recreating minor tag ""$major_number"".""$minor_number" - git tag delete "$major_number"".""$minor_number" + git tag --delete "$major_number"".""$minor_number" else echo "Creating minor tag ""$major_number"".""$minor_number" fi @@ -19,7 +19,7 @@ function run() { if git tag --list | grep -xq "$major_number" then echo "Recreating major tag ""$major_number" - git tag delete "$major_number" + git tag --delete "$major_number" else echo "Creating major tag ""$major_number" fi From 97ccfe8abc2bb5569788ad817f98cfe90c04a147 Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Mon, 1 Apr 2019 12:40:00 -0300 Subject: [PATCH 07/12] Force tag instead of delteting --- plugins/90-major_and_minor_tag.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/90-major_and_minor_tag.sh b/plugins/90-major_and_minor_tag.sh index 8297079..76dceb8 100644 --- a/plugins/90-major_and_minor_tag.sh +++ b/plugins/90-major_and_minor_tag.sh @@ -10,20 +10,18 @@ function run() { if git tag --list | grep -xq "$major_number"".""$minor_number" then echo "Recreating minor tag ""$major_number"".""$minor_number" - git tag --delete "$major_number"".""$minor_number" else echo "Creating minor tag ""$major_number"".""$minor_number" fi - git tag "$major_number"".""$minor_number" + git tag --force "$major_number"".""$minor_number" 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" + git tag --force "$major_number" return 0 } From 3443bae1488369811a29593fc13db1f154dc11af Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Thu, 18 Apr 2019 19:37:04 -0300 Subject: [PATCH 08/12] Add quiet option --- git-semver.sh | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/git-semver.sh b/git-semver.sh index 848a653..4647a89 100755 --- a/git-semver.sh +++ b/git-semver.sh @@ -3,7 +3,10 @@ # Usage ######################################## +exec 6>&1 + usage() { + exec 1>&6 6>&- cat <<-EOF Usage: $(basename-git "$0") [command] @@ -12,13 +15,17 @@ usage() { See https://github.com/markchalloner/git-semver for more detail. Commands - 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 + get Gets the current version (tag) + major [--quiet] [--dryrun] [-p ] [-b ] Generates a tag for the next major version and echos to the screen + minor [--quiet] [--dryrun] [-p [ [-b ] Generates a tag for the next minor version and echos to the screen + patch|next [--quiet] [--dryrun] [-p ] [-b ] Generates a tag for the next patch version and echos to the screen + pre-release [--quiet] [--dryrun] -p [-b ] Generates a tag for a pre-release version and echos to the screen + build [--quiet] [--dryrun] -b Generates a tag for a build and echos to the screen + help This message + + Options + -q, --quiet Only output the final version echo to stdout + -d, --dryrun Echo the version that would've been tagged, skip running plugins EOF exit @@ -218,6 +225,7 @@ version-get() { then return 1 else + exec 1>&6 6>&- echo "${version}" fi } @@ -328,10 +336,15 @@ version-do() { fi if [ $dryrun == 1 ] then + exec 1>&6 6>&- echo "$new" elif plugin-run "$new" "$version" then - $cmd "$new" && echo "$new" + if $cmd "$new" + then + exec 1>&6 6>&- + echo "$new" + fi fi } @@ -391,6 +404,12 @@ do shift validate-pre-release "$pre_release" ;; + -q) + exec > /dev/null + ;; + --quiet) + exec > /dev/null + ;; ?*) action=$1 ;; From aa7e29aacfa246dd61d5c6c24d25ba52943dc5b4 Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Thu, 18 Apr 2019 20:00:24 -0300 Subject: [PATCH 09/12] Fixed wrong redirection --- git-semver.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-semver.sh b/git-semver.sh index 4647a89..8939dd0 100755 --- a/git-semver.sh +++ b/git-semver.sh @@ -225,7 +225,6 @@ version-get() { then return 1 else - exec 1>&6 6>&- echo "${version}" fi } @@ -422,6 +421,7 @@ done case "$action" in get) + exec 1>&6 6>&- version-get ;; major) From 6bf24352e9f36170fff4d7a0637b5a58d42c7597 Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Thu, 18 Apr 2019 20:00:45 -0300 Subject: [PATCH 10/12] Added error behaibour to help --- git-semver.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-semver.sh b/git-semver.sh index 8939dd0..66e78be 100755 --- a/git-semver.sh +++ b/git-semver.sh @@ -24,7 +24,7 @@ usage() { help This message Options - -q, --quiet Only output the final version echo to stdout + -q, --quiet Only output the final version echo to stdout, or noting on error -d, --dryrun Echo the version that would've been tagged, skip running plugins EOF From d773b1d1694b344eb28d285932579d9ce132b06a Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Thu, 18 Apr 2019 20:44:39 -0300 Subject: [PATCH 11/12] Removed code from wrong commit branch --- git-semver.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/git-semver.sh b/git-semver.sh index 66e78be..5b16568 100755 --- a/git-semver.sh +++ b/git-semver.sh @@ -70,10 +70,7 @@ plugin-list() { plugin_dir="${dirs[${i}]}/.git-semver/plugins" if [ -d "${plugin_dir}" ] then - for plugin in $(find "${plugin_dir}" -maxdepth 1 -type f | sort -k 1.1n,1.2n) - do - echo "${plugin_type},${plugin}" - done + find "${plugin_dir}" -maxdepth 1 -type f -exec echo "${plugin_type},{}" \; fi done } From 14d7ed71ed2fe4385bf9fded821ddaf43e7c9021 Mon Sep 17 00:00:00 2001 From: Fernando Collova Date: Thu, 18 Apr 2019 20:45:32 -0300 Subject: [PATCH 12/12] Removed space --- git-semver.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-semver.sh b/git-semver.sh index 5b16568..4ed5d73 100755 --- a/git-semver.sh +++ b/git-semver.sh @@ -70,7 +70,7 @@ plugin-list() { plugin_dir="${dirs[${i}]}/.git-semver/plugins" if [ -d "${plugin_dir}" ] then - find "${plugin_dir}" -maxdepth 1 -type f -exec echo "${plugin_type},{}" \; + find "${plugin_dir}" -maxdepth 1 -type f -exec echo "${plugin_type},{}" \; fi done }