From 2c4c532dfffc9d886afd3228c38db318d816cac3 Mon Sep 17 00:00:00 2001 From: Florian Brinker Date: Wed, 21 Apr 2021 23:39:23 +0200 Subject: [PATCH] Add published version/tag check to skip docker builds --- .drone.yml | 6 +++--- build.sh | 27 +++++++++++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) mode change 100644 => 100755 build.sh diff --git a/.drone.yml b/.drone.yml index c223d28..ce25073 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,11 +7,11 @@ steps: - name: build image: alpine commands: - - apk update && apk add bash grep sed curl unzip + - apk update && apk add bash grep sed curl unzip jq - chmod +x ./build.sh - ./build.sh -- name: docker +- name: docker image: plugins/docker settings: repo: fbrinker/tileboard @@ -19,7 +19,7 @@ steps: from_secret: docker_username password: from_secret: docker_password - + trigger: branch: - master \ No newline at end of file diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 index b314fdd..696f499 --- a/build.sh +++ b/build.sh @@ -10,20 +10,35 @@ getVersionFromLatestRelease() { } downloadLatestRelease() { - URL=`curl -s "https://api.github.com/repos/resoai/TileBoard/releases/latest" \ + url=`curl -s "https://api.github.com/repos/resoai/TileBoard/releases/latest" \ | grep "browser_download_url" \ | cut -d '"' -f 4` - echo "Url: $URL" + echo "Url: $url" - curl -sL -o $1 ${URL} + curl -sL -o $1 ${url} } -LATEST=`getVersionFromLatestRelease` -SEMVER=( ${LATEST//./ } ) +getLatestPublishedTag() { + latest_tag=`curl -s "https://hub.docker.com/v2/repositories/fbrinker/tileboard/tags?page_size=1" \ + | jq -r ".results[0].name"` + echo "$latest_tag" +} + +LATEST_RELEASE=`getVersionFromLatestRelease` +LATEST_TAG=`getLatestPublishedTag` + +if [ "$LATEST_RELEASE" = "$LATEST_TAG" ]; then + echo "Nothing to do. Versions already match." + echo "Release: $LATEST_RELEASE" + echo "Tag: $LATEST_TAG" + exit 78 # drone.io exit code to stop but success the pipeline +fi + +SEMVER=( ${LATEST_RELEASE//./ } ) MAJOR=${SEMVER[0]} MINOR=${SEMVER[0]}.${SEMVER[1]} -PATCH=$LATEST +PATCH=$LATEST_RELEASE echo "latest,$MAJOR,$MINOR,$PATCH" > .tags