From 68d5f29876f0ac76aeaa132e215e6d091648a4bf Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 7 Mar 2022 20:25:41 +0100 Subject: [PATCH 1/2] feat: get rid of poetry dependency in version checker --- setup.cfg | 4 ++-- update_version.sh | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7ac0b27..08bf39e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [metadata] name = custom_hooks -version = 1.2.1 -description = Some random custom hooks. +version = 1.3.0 +description = Just some hooks that help save some time ...and nerves. long_description = file: README.md long_description_content_type = text/markdown url = https://github.com/OriginalUtkin/custom-hooks diff --git a/update_version.sh b/update_version.sh index f2e6190..3798185 100755 --- a/update_version.sh +++ b/update_version.sh @@ -1,31 +1,31 @@ #!/usr/bin/env bash -if [[ ("$2" == "poetry") || (("$2" == "") && ( -f pyproject.toml)) ]]; then +if [[ ("$1" == "poetry") ]]; then version_file="pyproject.toml" - command="poetry version -s" -elif [[ ("$2" == "version_file") || (("$2" == "") && ( -f VERSION)) ]]; then + command="grep -E '^version'|sed 's/\"//g'|sed -E 's/version[[:blank:]]?=[[:blank:]]?//g'" + +elif [[ ("$1" == "version_file") ]]; then version_file="VERSION" - command="cat VERSION" + command="grep -E '[0-9.]+'" + else - echo "Version type '$2' not supported" + echo "Version type '$1' not supported" exit 1 fi -tfile=$(mktemp $version_file.XXXXXXXXX) -mv $version_file $tfile +version_in_branch=$(eval "cat $version_file | $command") + git fetch -q origin master -git checkout master -q -- $version_file -version_in_master=$($command) -mv $tfile $version_file -version_in_branch=$($command) + +version_in_master=$(eval "git show origin/master:$version_file | $command") echo "Version in branch:" $version_in_branch echo "Version in master:" $version_in_master -changed_files=$(git diff origin/master --summary --name-only | grep -E $1) +changed_files=$(git diff origin/master --summary --name-only | grep -E $2) if [[ ("$version_in_branch" == "$version_in_master") && (! -z $changed_files)]] then - echo "VERSION file is not updated" + echo "Version in $version_file file is not updated" exit 1 fi \ No newline at end of file From 3835a76c00b0209550a6f05d233855cf9b13a777 Mon Sep 17 00:00:00 2001 From: Kirill Date: Wed, 9 Mar 2022 21:00:09 +0100 Subject: [PATCH 2/2] Add output commands check --- update_version.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/update_version.sh b/update_version.sh index 3798185..f1bdc12 100755 --- a/update_version.sh +++ b/update_version.sh @@ -1,8 +1,20 @@ #!/usr/bin/env bash +function is_output_valid() { + line_numbers=$(eval "echo $1 | wc -l") + is_version_correct=$(eval "echo $1 | grep -E '[0-9.]?'") + + if [[ ($line_numbers -eq 1) && (! -z $is_version_correct)]]; then + return 0 + else + return 1 + fi + +} + if [[ ("$1" == "poetry") ]]; then version_file="pyproject.toml" - command="grep -E '^version'|sed 's/\"//g'|sed -E 's/version[[:blank:]]?=[[:blank:]]?//g'" + command="sed 's/[\ \"]*//g' | grep -E '(^\[tool\.poetry\])|(^version)' | sed -E 's/\[tool.poetry\]//g' | sed -E 's/version[[:blank:]]?=[[:blank:]]?//g'" elif [[ ("$1" == "version_file") ]]; then version_file="VERSION" @@ -13,12 +25,18 @@ else exit 1 fi + version_in_branch=$(eval "cat $version_file | $command") git fetch -q origin master version_in_master=$(eval "git show origin/master:$version_file | $command") +if (! is_output_valid $version_in_branch) || (! is_output_valid $version_in_master); then + echo "Version update is not correct" + exit 1 +fi + echo "Version in branch:" $version_in_branch echo "Version in master:" $version_in_master @@ -28,4 +46,4 @@ if [[ ("$version_in_branch" == "$version_in_master") && (! -z $changed_files)]] then echo "Version in $version_file file is not updated" exit 1 -fi \ No newline at end of file +fi