From d03583c04334925a5ab75faed6814817ea54fa4b Mon Sep 17 00:00:00 2001 From: Hilary Holz Date: Sun, 14 Jul 2019 17:56:21 -0700 Subject: [PATCH 1/2] add version script --- scripts/version.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 scripts/version.sh diff --git a/scripts/version.sh b/scripts/version.sh new file mode 100755 index 000000000..8b7cb812a --- /dev/null +++ b/scripts/version.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -eou pipefail + +version=`git fetch --tags &>/dev/null | git tag -l | sort --version-sort | tail -n1 | cut -c 2-` + +num_changes=`git status --porcelain | wc -l` + +if [[ $num_changes -ne 0 ]]; then + commit=`git rev-parse --short HEAD` + version=${version}-${commit} +fi + +echo $version From 58628fdd3e97f8feaf7cac5a1519f2f9bae92ee4 Mon Sep 17 00:00:00 2001 From: Hilary Holz Date: Sun, 14 Jul 2019 18:26:59 -0700 Subject: [PATCH 2/2] extract version logic into a script and be comprehensive about it --- scripts/version.sh | 6 +++++- snap/snapcraft.yaml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/version.sh b/scripts/version.sh index 8b7cb812a..97e248764 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -4,8 +4,12 @@ set -eou pipefail version=`git fetch --tags &>/dev/null | git tag -l | sort --version-sort | tail -n1 | cut -c 2-` -num_changes=`git status --porcelain | wc -l` +branch=`git rev-parse --abbrev-ref HEAD` +if [[ $branch != 'master' ]]; then + version=${version}-${branch} +fi +num_changes=`git status --porcelain | wc -l` if [[ $num_changes -ne 0 ]]; then commit=`git rev-parse --short HEAD` version=${version}-${commit} diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 4357e8dff..3cedde07c 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: doctl -version-script: git fetch --tags &>/dev/null | git tag -l | sort --version-sort | tail -n1 | cut -c 2- +version-script: scripts/version.sh version: git summary: A command line tool for DigitalOcean services description: doctl is a command line tool for DigitalOcean services using the API.