diff --git a/scripts/version.sh b/scripts/version.sh new file mode 100755 index 000000000..97e248764 --- /dev/null +++ b/scripts/version.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -eou pipefail + +version=`git fetch --tags &>/dev/null | git tag -l | sort --version-sort | tail -n1 | cut -c 2-` + +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} +fi + +echo $version 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.