From 6806bea72e1c0ce5bf158c8b4b0229eabff338eb Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Sat, 11 Jan 2020 17:17:09 -0500 Subject: [PATCH] Download latest release instead of from master Using GitHub URL to latest release asset as described in https://help.github.com/en/github/administering-a-repository/linking-to-releases#linking-to-the-latest-release There's a counter of release assets downloads, which is nice. Download zimfw.zsh when installing, and zimfw.zsh.gz when upgrading, so we can have separate counts. --- CHANGELOG.md | 2 ++ README.md | 2 +- src/stage2/50_zimfw_upgrade.zsh.erb | 8 ++++---- zimfw.zsh | 10 +++++----- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8750f99..c9a1095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `-v` verbose option. Normal mode output is now cleaner and more focused. ### Changed +- When upgrading, download latest release asset instead of raw file from the + master branch. - `curl` is preferred over `wget`. - `wget`'s output is only shown in verbose mode. diff --git a/README.md b/README.md index ec9feb0..78f51f4 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ If you have a different shell framework installed (like oh-my-zsh or prezto), chsh -s =zsh -3. Copy https://raw.githubusercontent.com/zimfw/zimfw/master/zimfw.zsh to +3. Copy https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh to `~/.zim/zimfw.zsh`. 4. Add the lines in the following templates to the respective dot files: diff --git a/src/stage2/50_zimfw_upgrade.zsh.erb b/src/stage2/50_zimfw_upgrade.zsh.erb index 7c994f4..ada08cd 100644 --- a/src/stage2/50_zimfw_upgrade.zsh.erb +++ b/src/stage2/50_zimfw_upgrade.zsh.erb @@ -1,17 +1,17 @@ _zimfw_upgrade() { local -r ztarget=${ZIM_HOME}/zimfw.zsh - local -r zurl=https://raw.githubusercontent.com/zimfw/zimfw/master/zimfw.zsh + local -r zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz { + setopt LOCAL_OPTIONS PIPE_FAIL if (( ${+commands[curl]} )); then - command curl -fsSL -o ${ztarget}.new ${zurl} || return 1 + command curl -fsSL ${zurl} | command gunzip > ${ztarget}.new || return 1 else local zopt (( _zprintlevel <= 1 )) && zopt='-q' - if ! command wget -nv ${zopt} -O ${ztarget}.new ${zurl}; then + if ! command wget -nv ${zopt} -O - ${zurl} | command gunzip > ${ztarget}.new; then (( _zprintlevel <= 1 )) && print -u2 -PR "%F{red}<%= error %>Error downloading %B${zurl}%b. Use %B-v%b option to see details.%f" return 1 fi - else fi _zimfw_mv ${ztarget}{.new,} && _zimfw_print -P '<%= done %>Done with upgrade.' } always { diff --git a/zimfw.zsh b/zimfw.zsh index bc194c1..1b4cfd8 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -260,7 +260,7 @@ _zimfw_compile() { } _zimfw_info() { - print 'Zim version: 1.1.0-SNAPSHOT (previous commit is ee99fe8)' + print 'Zim version: 1.1.0-SNAPSHOT (previous commit is f6f7815)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) @@ -281,18 +281,18 @@ _zimfw_uninstall() { _zimfw_upgrade() { local -r ztarget=${ZIM_HOME}/zimfw.zsh - local -r zurl=https://raw.githubusercontent.com/zimfw/zimfw/master/zimfw.zsh + local -r zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz { + setopt LOCAL_OPTIONS PIPE_FAIL if (( ${+commands[curl]} )); then - command curl -fsSL -o ${ztarget}.new ${zurl} || return 1 + command curl -fsSL ${zurl} | command gunzip > ${ztarget}.new || return 1 else local zopt (( _zprintlevel <= 1 )) && zopt='-q' - if ! command wget -nv ${zopt} -O ${ztarget}.new ${zurl}; then + if ! command wget -nv ${zopt} -O - ${zurl} | command gunzip > ${ztarget}.new; then (( _zprintlevel <= 1 )) && print -u2 -PR "%F{red}x Error downloading %B${zurl}%b. Use %B-v%b option to see details.%f" return 1 fi - else fi _zimfw_mv ${ztarget}{.new,} && _zimfw_print -P 'Done with upgrade.' } always {