Check the latest version using `git ls-remote`

which is being used to list the latest tag starting with `v`.
Print a warning if it's different than the current version being used.
This commit is contained in:
Eric Nielsen 2020-01-13 13:14:31 -05:00
parent dab4b87a29
commit be2be83560
No known key found for this signature in database
GPG Key ID: 47D1DBFA0765A1FB
6 changed files with 37 additions and 24 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- `help` and `version` actions. - `help` and `version` actions.
- `-v` verbose option. Normal mode output is now cleaner and more focused. - `-v` verbose option. Normal mode output is now cleaner and more focused.
- Check the latest version using `git ls-remote`.
### Changed ### Changed
- When upgrading, download latest release asset instead of raw file from the - When upgrading, download latest release asset instead of raw file from the

View File

@ -1,5 +1,5 @@
autoload -Uz is-at-least && if ! is-at-least <%= min_zsh_version %>; then autoload -Uz is-at-least && if ! is-at-least <%= min_zsh_version %>; then
print -u2 -R "${0}: Error starting Zim. You're using Zsh version ${ZSH_VERSION} and versions < <%= min_zsh_version %> are not supported. Update your Zsh." print -u2 -PR "%F{red}${0}: Error starting Zim. You're using Zsh version %B${ZSH_VERSION}%b and versions < %B<%= min_zsh_version %>%b are not supported. Upgrade your Zsh.%f"
return 1 return 1
fi fi

View File

@ -1,6 +1,5 @@
zmodule() { zmodule() {
local -r zusage=" local -r zusage="Usage: %B${0}%b <url> [%B-n%b|%B--name%b <module_name>] [options]
Usage: %B${0}%b <url> [%B-n%b|%B--name%b <module_name>] [options]
Repository options: Repository options:
%B-b%b|%B--branch%b <branch_name> Use specified branch when installing and updating the module %B-b%b|%B--branch%b <branch_name> Use specified branch when installing and updating the module
@ -14,7 +13,7 @@ Startup options:
%B-d%b|%B--disabled%b Don't use or uninstall the module %B-d%b|%B--disabled%b Don't use or uninstall the module
" "
if [[ ${${funcfiletrace[1]%:*}:t} != .zimrc ]]; then if [[ ${${funcfiletrace[1]%:*}:t} != .zimrc ]]; then
print -u2 -PR "%F{red}${0}: Must be called from %B<%= home %>/.zimrc%b%f"$'\n'${zusage} print -u2 -PR "%F{red}${0}: Must be called from %B<%= home %>/.zimrc%b%f"$'\n\n'${zusage}
return 1 return 1
fi fi
if (( ! # )); then if (( ! # )); then

View File

@ -1,5 +1,5 @@
_zimfw_info() { _zimfw_info() {
print 'Zim version: <%= version %> (previous commit is <%= `git rev-parse --short HEAD | tr -d '\r\n'` %>)' print -R 'Zim version: '${_zversion}' (previous commit is <%= `git rev-parse --short HEAD | tr -d '\r\n'` %>)'
print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'ZIM_HOME: '${ZIM_HOME}
print -R 'Zsh version: '${ZSH_VERSION} print -R 'Zsh version: '${ZSH_VERSION}
print -R 'System info: '$(command uname -a) print -R 'System info: '$(command uname -a)

View File

@ -1,6 +1,6 @@
zimfw() { zimfw() {
local -r zusage=" local -r _zversion='<%= version %>'
Usage: %B${0}%b <action> [%B-q%b|%B-v%b] local -r zusage="Usage: %B${0}%b <action> [%B-q%b|%B-v%b]
Actions: Actions:
%Bbuild%b Build init.zsh and login_init.zsh %Bbuild%b Build init.zsh and login_init.zsh
@ -24,19 +24,26 @@ Options:
local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts
local -i _zprintlevel=1 local -i _zprintlevel=1
if (( # > 2 )); then if (( # > 2 )); then
print -u2 -PR "%F{red}${0}: Too many options%f"$'\n'${zusage} print -u2 -PR "%F{red}${0}: Too many options%f"$'\n\n'${zusage}
return 1 return 1
elif (( # > 1 )); then elif (( # > 1 )); then
case ${2} in case ${2} in
-q) _zprintlevel=0 ;; -q) _zprintlevel=0 ;;
-v) _zprintlevel=2 ;; -v) _zprintlevel=2 ;;
*) *)
print -u2 -PR "%F{red}${0}: Unknown option ${2}%f"$'\n'${zusage} print -u2 -PR "%F{red}${0}: Unknown option ${2}%f"$'\n\n'${zusage}
return 1 return 1
;; ;;
esac esac
fi fi
if (( _zprintlevel > 0 )); then
local -r zlatestversion=$(command git ls-remote --tags --refs https://github.com/zimfw/zimfw.git 'v*' | sed 's?^.*/v??' | sort -n -t. -k1,1 -k2,2 -k3,3 | tail -n1)
if [[ ${_zversion} != ${zlatestversion} ]]; then
print -PR "%F{yellow}Latest zimfw version is %B${zlatestversion}%b. You're using version %B${_zversion}%b. Run %Bzimfw upgrade%b to upgrade.%f"$'\n'
fi
fi
case ${1} in case ${1} in
install) install)
ztool="<%= render_escaped("src/tools/install.zsh.erb") %>" ztool="<%= render_escaped("src/tools/install.zsh.erb") %>"
@ -57,7 +64,7 @@ Options:
clean-compiled) _zimfw_clean_compiled ;; clean-compiled) _zimfw_clean_compiled ;;
clean-dumpfile) _zimfw_clean_dumpfile ;; clean-dumpfile) _zimfw_clean_dumpfile ;;
compile) _zimfw_build_login_init && _zimfw_compile ;; compile) _zimfw_build_login_init && _zimfw_compile ;;
help) print -P ${zusage} ;; help) print -PR ${zusage} ;;
info) _zimfw_info ;; info) _zimfw_info ;;
install|update) install|update)
_zimfw_source_zimrc 1 || return 1 _zimfw_source_zimrc 1 || return 1
@ -72,9 +79,9 @@ Options:
(( _zprintlevel-- )) (( _zprintlevel-- ))
_zimfw_build_login_init && _zimfw_compile _zimfw_build_login_init && _zimfw_compile
;; ;;
version) print '<%= version %>' ;; version) print -PR ${_zversion} ;;
*) *)
print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n\n'${zusage}
return 1 return 1
;; ;;
esac esac

View File

@ -25,7 +25,7 @@
# SOFTWARE. # SOFTWARE.
autoload -Uz is-at-least && if ! is-at-least 5.2; then autoload -Uz is-at-least && if ! is-at-least 5.2; then
print -u2 -R "${0}: Error starting Zim. You're using Zsh version ${ZSH_VERSION} and versions < 5.2 are not supported. Update your Zsh." print -u2 -PR "%F{red}${0}: Error starting Zim. You're using Zsh version %B${ZSH_VERSION}%b and versions < %B5.2%b are not supported. Upgrade your Zsh.%f"
return 1 return 1
fi fi
@ -101,8 +101,7 @@ _zimfw_build() {
} }
zmodule() { zmodule() {
local -r zusage=" local -r zusage="Usage: %B${0}%b <url> [%B-n%b|%B--name%b <module_name>] [options]
Usage: %B${0}%b <url> [%B-n%b|%B--name%b <module_name>] [options]
Repository options: Repository options:
%B-b%b|%B--branch%b <branch_name> Use specified branch when installing and updating the module %B-b%b|%B--branch%b <branch_name> Use specified branch when installing and updating the module
@ -116,7 +115,7 @@ Startup options:
%B-d%b|%B--disabled%b Don't use or uninstall the module %B-d%b|%B--disabled%b Don't use or uninstall the module
" "
if [[ ${${funcfiletrace[1]%:*}:t} != .zimrc ]]; then if [[ ${${funcfiletrace[1]%:*}:t} != .zimrc ]]; then
print -u2 -PR "%F{red}${0}: Must be called from %B${ZDOTDIR:-${HOME}}/.zimrc%b%f"$'\n'${zusage} print -u2 -PR "%F{red}${0}: Must be called from %B${ZDOTDIR:-${HOME}}/.zimrc%b%f"$'\n\n'${zusage}
return 1 return 1
fi fi
if (( ! # )); then if (( ! # )); then
@ -260,7 +259,7 @@ _zimfw_compile() {
} }
_zimfw_info() { _zimfw_info() {
print 'Zim version: 1.1.0-SNAPSHOT (previous commit is 6806bea)' print -R 'Zim version: '${_zversion}' (previous commit is dab4b87)'
print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'ZIM_HOME: '${ZIM_HOME}
print -R 'Zsh version: '${ZSH_VERSION} print -R 'Zsh version: '${ZSH_VERSION}
print -R 'System info: '$(command uname -a) print -R 'System info: '$(command uname -a)
@ -301,8 +300,8 @@ _zimfw_upgrade() {
} }
zimfw() { zimfw() {
local -r zusage=" local -r _zversion='1.1.0-SNAPSHOT'
Usage: %B${0}%b <action> [%B-q%b|%B-v%b] local -r zusage="Usage: %B${0}%b <action> [%B-q%b|%B-v%b]
Actions: Actions:
%Bbuild%b Build init.zsh and login_init.zsh %Bbuild%b Build init.zsh and login_init.zsh
@ -326,19 +325,26 @@ Options:
local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts
local -i _zprintlevel=1 local -i _zprintlevel=1
if (( # > 2 )); then if (( # > 2 )); then
print -u2 -PR "%F{red}${0}: Too many options%f"$'\n'${zusage} print -u2 -PR "%F{red}${0}: Too many options%f"$'\n\n'${zusage}
return 1 return 1
elif (( # > 1 )); then elif (( # > 1 )); then
case ${2} in case ${2} in
-q) _zprintlevel=0 ;; -q) _zprintlevel=0 ;;
-v) _zprintlevel=2 ;; -v) _zprintlevel=2 ;;
*) *)
print -u2 -PR "%F{red}${0}: Unknown option ${2}%f"$'\n'${zusage} print -u2 -PR "%F{red}${0}: Unknown option ${2}%f"$'\n\n'${zusage}
return 1 return 1
;; ;;
esac esac
fi fi
if (( _zprintlevel > 0 )); then
local -r zlatestversion=$(command git ls-remote --tags --refs https://github.com/zimfw/zimfw.git 'v*' | sed 's?^.*/v??' | sort -n -t. -k1,1 -k2,2 -k3,3 | tail -n1)
if [[ ${_zversion} != ${zlatestversion} ]]; then
print -PR "%F{yellow}Latest zimfw version is %B${zlatestversion}%b. You're using version %B${_zversion}%b. Run %Bzimfw upgrade%b to upgrade.%f"$'\n'
fi
fi
case ${1} in case ${1} in
install) install)
ztool="# This runs in a new shell ztool="# This runs in a new shell
@ -439,7 +445,7 @@ fi
clean-compiled) _zimfw_clean_compiled ;; clean-compiled) _zimfw_clean_compiled ;;
clean-dumpfile) _zimfw_clean_dumpfile ;; clean-dumpfile) _zimfw_clean_dumpfile ;;
compile) _zimfw_build_login_init && _zimfw_compile ;; compile) _zimfw_build_login_init && _zimfw_compile ;;
help) print -P ${zusage} ;; help) print -PR ${zusage} ;;
info) _zimfw_info ;; info) _zimfw_info ;;
install|update) install|update)
_zimfw_source_zimrc 1 || return 1 _zimfw_source_zimrc 1 || return 1
@ -454,9 +460,9 @@ fi
(( _zprintlevel-- )) (( _zprintlevel-- ))
_zimfw_build_login_init && _zimfw_compile _zimfw_build_login_init && _zimfw_compile
;; ;;
version) print '1.1.0-SNAPSHOT' ;; version) print -PR ${_zversion} ;;
*) *)
print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n\n'${zusage}
return 1 return 1
;; ;;
esac esac