-
Notifications
You must be signed in to change notification settings - Fork 1
feat: get rid of poetry dependency in version checker #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,49 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| if [[ ("$2" == "poetry") || (("$2" == "") && ( -f pyproject.toml)) ]]; then | ||
| function is_output_valid() { | ||
| line_numbers=$(eval "echo $1 | wc -l") | ||
| is_version_correct=$(eval "echo $1 | grep -E '[0-9.]?'") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that |
||
|
|
||
| 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="poetry version -s" | ||
| elif [[ ("$2" == "version_file") || (("$2" == "") && ( -f VERSION)) ]]; then | ||
| command="sed 's/[\ \"]*//g' | grep -E '(^\[tool\.poetry\])|(^version)' | sed -E 's/\[tool.poetry\]//g' | sed -E 's/version[[:blank:]]?=[[:blank:]]?//g'" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please consider using functions instead of string command: function cmd1() { echo "cmd1" }
function cmd2() { echo "cmd2" }
alias chosen_command='cmd1'
chosen_command # calls cmd1
``
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also I think it is possible to pipe output of previous command as the input of the function, please check https://stackoverflow.com/a/11454477/1768976 |
||
|
|
||
| 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") | ||
|
|
||
| if (! is_output_valid $version_in_branch) || (! is_output_valid $version_in_master); then | ||
| echo "Version update is not correct" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it may be beneficial to provide what is the version - in case of error it can be something else than what is in master/current branch.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree, can be done by moving echo commands ("Version in branch", "Version in master") before that if |
||
| exit 1 | ||
| fi | ||
|
|
||
| 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 | ||
| fi | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably no need to use eval here