From 149f619634bfe2d77468bc2d8bc6be3cfabed5dd Mon Sep 17 00:00:00 2001 From: Ivan Ilves Date: Wed, 15 Nov 2017 07:38:53 +0200 Subject: [PATCH 1/2] Add wrapper to get the latest app. ALWAYS --- Makefile | 6 ++++++ README.md | 9 ++++++++ scripts/wrapper.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100755 scripts/wrapper.sh diff --git a/Makefile b/Makefile index 78515cf..13c8e1e 100644 --- a/Makefile +++ b/Makefile @@ -132,3 +132,9 @@ docker: DOCKER_REPO:=ivanilves/lstags docker: RELEASE_TAG:=latest docker: @docker image build -t ${DOCKER_REPO}:${RELEASE_TAG} . + +wrapper: PREFIX=/usr/local +wrapper: + install -o root -g root -m755 scripts/wrapper.sh ${PREFIX}/bin/lstags + +install: wrapper diff --git a/README.md b/README.md index bc12295..9f15115 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,15 @@ You can either: ## Install: Binaries https://github.com/ivanilves/lstags/releases +## Install: Wrapper +```sh +git clone git@github.com:ivanilves/lstags.git +cd lstags +sudo make wrapper +lstags -h +``` +A special wrapper script will be installed to manage `lstags` invocation and updates. :sunglasses: + ## Install: From source ```sh git clone git@github.com:ivanilves/lstags.git diff --git a/scripts/wrapper.sh b/scripts/wrapper.sh new file mode 100755 index 0000000..f502806 --- /dev/null +++ b/scripts/wrapper.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# +[[ "${DEBUG}" == "true" || "${DEBUG}" == "yes" ]] && set -x + +set -uo pipefail + +declare -r -i CACHE_TTL_MINUTES=2880 + +declare -r LOCAL_PATH=${HOME}/.lstags; mkdir -p "${LOCAL_PATH}" || exit 2 +declare -r LSTAGS=${LOCAL_PATH}/lstags +declare -r UPDATE_MARKER="${LOCAL_PATH}/update" + +declare -r LATEST_RELEASE_URL=https://api.github.com/repos/ivanilves/lstags/releases/latest +declare -r DOWNLOAD_URL=https://github.com/ivanilves/lstags/releases/download + +CHECK_FOR_UPDATE=false +if [[ ! -x "${LSTAGS}" || ! -f "${UPDATE_MARKER}" ]]; then + CHECK_FOR_UPDATE=true +elif [[ -n "$(find ${UPDATE_MARKER} -type f -cmin +${CACHE_TTL_MINUTES})" ]]; then + CHECK_FOR_UPDATE=true +fi + +PERFORM_UPDATE=false +if [[ "${CHECK_FOR_UPDATE}" == "true" ]]; then + declare -r LATEST_VERSION=$(curl --connect-timeout 5 -m10 -s -f -H "Content-Type:application/json" "${LATEST_RELEASE_URL}" | jq -r '.name') + declare -r LATEST_TAG=${LATEST_VERSION/-*/} + declare -r LATEST_VERSION_URL=${DOWNLOAD_URL}/${LATEST_TAG}/lstags-$(uname -s | tr [A-Z] [a-z])-${LATEST_VERSION}.tar.gz + + if [[ -x "${LSTAGS}" && -n "${LATEST_VERSION}" ]]; then + LOCAL_VERSION=$(${LSTAGS} --version | cut -d' ' -f2) + if [[ "${LOCAL_VERSION}" != "${LATEST_VERSION}" ]]; then + echo "Local version: ${LOCAL_VERSION} / Will download new one: ${LATEST_VERSION}" + PERFORM_UPDATE=true + else + echo "You already have the latest version: ${LOCAL_VERSION}" + fi + elif [[ -n "${LATEST_VERSION}" ]]; then + echo "No binary found, will download latest version: ${LATEST_VERSION}" + PERFORM_UPDATE=true + else + echo "Failed to check for update!" >>/dev/stderr + fi + + echo '-' +fi + +if [[ "${PERFORM_UPDATE}" == "true" ]]; then + curl --connect-timeout 5 -m30 -s -f "${LATEST_VERSION_URL}" -L | tar -C "${LOCAL_PATH}" -xz +fi + +touch "${UPDATE_MARKER}" + +exec ${LSTAGS} ${@} From fcf9550e15822461180903f4ab4f0ae5b76b1c37 Mon Sep 17 00:00:00 2001 From: Ivan Ilves Date: Wed, 15 Nov 2017 18:40:46 +0100 Subject: [PATCH 2/2] Scout rule: More logic to Travis --- .travis.yml | 4 ++-- Makefile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b033d96..5f9e69d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,8 +22,8 @@ script: - make lint - make vet -after_success: - - if [[ "${TRAVIS_PULL_REQUEST}" == "false" ]]; then make release; fi +before_deploy: + - make release deploy: provider: script diff --git a/Makefile b/Makefile index 13c8e1e..ad51170 100644 --- a/Makefile +++ b/Makefile @@ -113,7 +113,7 @@ release: validate-release: test -s ./dist/release/TAG && test -s ./dist/release/NAME - egrep "^\* " ./dist/release/CHANGELOG.md + test -f ./dist/release/CHANGELOG.md [[ `find dist/assets -mindepth 2 -type f | wc -l` -ge 2 ]] deploy: validate-release