Skip to content

Commit

Permalink
Merge pull request #515 from hilary/bump-version
Browse files Browse the repository at this point in the history
Bump and tag
  • Loading branch information
hilary authored Jul 24, 2019
2 parents becb6c4 + 8dd417c commit 749efc7
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ _vendor-*

/out

# Build artifacts
Dockerfile-e

# Snapcraft
parts/
prime/
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ You will also need a valid `GITHUB_TOKEN` environment variable with access to th

1. Generate a PR, get it reviewed, and merge

1. Tag the release using `BUMP=[patch|feature|breaking] make bump-and-tag`

1. To build `doctl` for all its platforms, run `scripts/stage.sh major minor patch`
(e.g. `scripts/stage.sh 1 5 0`). This will place all files and their checksums
in `builds/major.minor.patch/release`.
Expand Down
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ help:
@echo ""
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null |\
awk -v RS= -F: \
'/^# File/,/^# Finished Make data base/ {if ($$1 ~ /^[a-zA-Z]/) {printf "%-15s%s\n", $$1, substr($$9, 9, length($$9)-9)}}' |\
'/^# File/,/^# Finished Make data base/ {if ($$1 ~ /^[a-zA-Z]/) {printf "%-20s%s\n", $$1, substr($$9, 9, length($$9)-9)}}' |\
sort

.PHONY: test
Expand Down Expand Up @@ -47,6 +47,21 @@ shellcheck:
@echo "analyze shell scripts"
scripts/shell_check.sh

.PHONY: version
version:
@echo "doctl version"
scripts/version.sh

.PHONY: install-sembump
install-sembump:
@echo "install/update sembump tool"
@GO111MODULE=off go get -u github.com/jessfraz/junk/sembump

.PHONY: bump-and-tag
bump-and-tag: install-sembump
@echo "BUMP=<patch|feature|breaking> bump and tag version"
scripts/bumpversion.sh

my_d = $(shell pwd)
OUT_D = $(shell echo $${OUT_D:-$(my_d)/builds})

Expand Down
28 changes: 28 additions & 0 deletions scripts/bumpversion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -euo pipefail

# Bump defaults to patch. We provide friendly aliases
# for patch, minor and major
BUMP=${BUMP:-patch}
case "$BUMP" in
feature | minor)
BUMP="minor"
;;
breaking | major)
BUMP="major"
;;
*)
BUMP="patch"
;;
esac

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

version="$("$DIR"/../scripts/version.sh -s)"
new_version="v$(sembump --kind "$BUMP" "$version")"

echo "Bumping version from v${version} to ${new_version}"

git tag -m "release ${new_version}" -a "$new_version" && git push --tags

5 changes: 0 additions & 5 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ if [[ -z "$tag" ]]; then
echo "usage: $0 <tag>"
fi

# ensure tags are up to date
git fetch --tags &>/dev/null

git tag -a -m "release ${tag}" "$tag" && git push --tags

gothub release \
--user digitalocean \
--repo doctl \
Expand Down
45 changes: 43 additions & 2 deletions scripts/version.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
#!/usr/bin/env bash

set -eou pipefail
# do NOT use pipefail in this script, as it will cause problems with the version
# line

set -e

me=$(basename "$0")

help_message="\
Usage: $me [<options>]
Display doctl version
Options:
-h, --help Show this help information.
-s, --short major.minor.patch only
"

parse_args() {
while : ; do
if [[ $1 = "-h" || $1 = "--help" ]]; then
echo "$help_message"
return 0
elif [[ $1 = "-s" || $1 = "--short" ]]; then
short=true
shift
else
break
fi
done
}

parse_args "$@"

if ! git diff --exit-code --quiet --cached; then
echo "Aborting due to uncommitted changes in the index" >&2
exit 1
fi

version=$(git fetch --tags &>/dev/null | git tag -l | sort --version-sort | tail -n1 | cut -c 2-)

if [[ $short = true ]]; then
echo "$version"
exit 0
fi

branch=$(git rev-parse --abbrev-ref HEAD)
if [[ $branch != 'master' ]]; then
if [[ $branch != 'master' && $branch != HEAD ]]; then
version=${version}-${branch}
fi

Expand Down

0 comments on commit 749efc7

Please sign in to comment.