diff --git a/Makefile b/Makefile index 4eb3dce..5cfe15f 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,6 @@ ZPLUG_ROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) SHOVE_URL := https://github.com/key-amb/shove SHOVE_DIR := $(ZPLUG_ROOT)/.gitignore.d/shove TEST_TARGET ?= test -ACCESS_TOKEN := $$GITHUB_ZPLUG_MAN_ACCESS_TOKEN .DEFAULT_GOAL := help @@ -22,20 +21,7 @@ test: shove ## Unit test for zplug ZPLUG_ROOT=$(ZPLUG_ROOT) $(SHOVE_DIR)/bin/shove -r $(TEST_TARGET) -s zsh release: ## Create new GitHub Releases - curl --data \ - '{ \ - "tag_name": "'$$_ZPLUG_VERSION'", \ - "target_commitish": "master", \ - "name": "'$$_ZPLUG_VERSION'", \ - "body": "Release of version '$$_ZPLUG_VERSION'", \ - "draft": false, \ - "prerelease": false \ - }' \ - "https://api.github.com/repos/zplug/zplug/releases?access_token=$(ACCESS_TOKEN)" - -patch: - git tag -a $$_ZPLUG_VERSION -m $$_ZPLUG_VERSION - git push origin $$_ZPLUG_VERSION + @zsh $(ZPLUG_ROOT)/misc/dev/release.zsh help: ## Self-documented Makefile @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ diff --git a/base/base/base.zsh b/base/base/base.zsh index 7d81c1f..bb03703 100644 --- a/base/base/base.zsh +++ b/base/base/base.zsh @@ -37,24 +37,68 @@ __zplug::base::base::version_requirement() { local -i idx local -a min val + local a="$1" op="$2" b="$3" - [[ $1 == $2 ]] && return 0 + [[ $a == $b ]] && return 0 - val=("${(s:.:)1}") - min=("${(s:.:)2}") + val=("${(s:.:)a}") + min=("${(s:.:)b}") - for (( idx=1; idx <= $#val; idx++ )) - do - if (( val[$idx] > ${min[$idx]:-0} )); then - return 0 - elif (( val[$idx] < ${min[$idx]:-0} )); then - return 1 - fi - done + case "$op" in + ">") + for (( idx=1; idx <= $#val; idx++ )) + do + if (( val[$idx] > ${min[$idx]:-0} )); then + return 0 + elif (( val[$idx] < ${min[$idx]:-0} )); then + return 1 + fi + done + ;; + "<") + for (( idx=1; idx <= $#val; idx++ )) + do + if (( val[$idx] < ${min[$idx]:-0} )); then + return 0 + elif (( val[$idx] > ${min[$idx]:-0} )); then + return 1 + fi + done + ;; + *) + ;; + esac return 1 } +__zplug::base::base::valid_semver() +{ + local prev="$1" next="$2" + if [[ $prev == $next ]]; then + # e.g. NG: prev 2.4.1, next 2.4.1 + return 1 + fi + if __zplug::base::base::version_requirement "$prev" ">" "$next"; then + # e.g. NG: prev 2.4.1, next 2.4.0 + return 1 + fi + prev_elements=("${(s:.:)prev}") + next_elements=("${(s:.:)next}") + if (( $#next_elements != 3 )); then + # e.g. NG: next 2.4 + return 1 + fi + # TODO: more complex + # prev_flat="${prev//./}" + # next_flat="${next//./}" + # if (( $(($next_flat - $prev_flat)) != 1 )); then + # # e.g. NG: prev 2.4.1, next 2.4.3 + # return 1 + # fi + return 0 +} + __zplug::base::base::git_version() { # Return false if git command doesn't exist @@ -63,16 +107,14 @@ __zplug::base::base::git_version() fi __zplug::base::base::version_requirement \ - ${(M)${(z)"$(git --version)"}:#[0-9]*[0-9]} \ - "${@:?}" + ${(M)${(z)"$(git --version)"}:#[0-9]*[0-9]} ">" "${@:?}" return $status } __zplug::base::base::zsh_version() { __zplug::base::base::version_requirement \ - "$ZSH_VERSION" \ - "${@:?}" + "$ZSH_VERSION" ">" "${@:?}" return $status } @@ -80,8 +122,7 @@ __zplug::base::base::osx_version() { (( $+commands[sw_vers] )) || return 1 __zplug::base::base::version_requirement \ - ${${(M)${(@f)"$(sw_vers)"}:#ProductVersion*}[2]} \ - "${@:?}" + ${${(M)${(@f)"$(sw_vers)"}:#ProductVersion*}[2]} ">" "${@:?}" return $status } diff --git a/misc/dev/release.zsh b/misc/dev/release.zsh new file mode 100644 index 0000000..d1e8c83 --- /dev/null +++ b/misc/dev/release.zsh @@ -0,0 +1,117 @@ +#!/bin/zsh + +set -e + +printf "Now zplug version is $_ZPLUG_VERSION\n" +printf "Please let me know new version: " +read next_version +printf "OK? $next_version: [y/n] " +read ok +case "$ok" in + "Y"|"y"|"YES"|"yes"|"OK"|"ok") + # ok + ;; + *) + echo "canceled" >&2 + exit 1 + ;; +esac + +dir="$(git rev-parse --show-toplevel)" +source "$dir/base/base/base.zsh" + +if ! __zplug::base::base::valid_semver "$_ZPLUG_VERSION" "$next_version"; then + printf "$next_version: invalid semver\n" + exit 1 +fi + +if [[ -z $GITHUB_TOKEN ]]; then + printf "GITHUB_TOKEN is missing\n" >&2 + exit 1 +fi + +if [[ -n "$(git status -s)" ]]; then + git status -s + printf "master branch is not clean\n" >&2 + exit 1 +fi + +files=( +"$dir/base/core/core.zsh" +"$dir/README.md" +"$dir/doc/guide/ja/README.md" +) + +# overwrite +echo "$next_version" >| "$dir/doc/VERSION" + +# overwrite +for file in "$files[@]" +do + cat "$file" | (rm "$file"; sed "s/$_ZPLUG_VERSION/$next_version/" > "$file") +done + +# show diff +git diff + +printf "Can I continue to process? [y/n] " +read ok +case "$ok" in + "Y"|"y"|"YES"|"yes"|"OK"|"ok") + # ok + ;; + *) + echo "canceled" >&2 + exit 1 + ;; +esac + +# git ops +set -x +git add -p +git commit -m "New version $next_version" +git push -u origin master +# maybe not necessary thanks to curl post proc +# git tag -a $next_version -m $next_version +# git push origin $next_version +set +x + +body="Release of version '$next_version'" +printf "Do you enter releases message? [y/n] " +read ok +case "$ok" in + "Y"|"y"|"YES"|"yes"|"OK"|"ok") + while true + do + echo "Please let me know release message (kill to type ^D)" + ok= + message="$(cat)" + printf "--- OK? --- [y/n] " + read ok + case "$ok" in + [Yy]*) + break + ;; + [Nn]*) + continue + ;; + * ) echo "Please answer yes or no.";; + esac + done + ;; + *) + # do nothing + ;; +esac + +curl --data \ + '{ \ + "tag_name": "'$next_version'", \ + "target_commitish": "master", \ + "name": "'$next_version'", \ + "body": "'$body'", \ + "draft": false, \ + "prerelease": false \ +}' "https://api.github.com/repos/zplug/zplug/releases?access_token=$GITHUB_TOKEN" + +printf "Completed.\n"