Skip to content

Commit

Permalink
Add make target to prepare a relase (#345)
Browse files Browse the repository at this point in the history
It will bump version and prepare description with commits, after
that version/description has to be manually edited to fix TODOs.

New make targets:
make prepare-patch
make prepare-minor
make prepare-major

Signed-off-by: Quique Llorente <[email protected]>
  • Loading branch information
qinqon authored Feb 3, 2020
1 parent 176f29a commit 5e9e0c3
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ the command `make release` do all this automatically, the version is at
`version/version.go` and the description at `version/description`.

So the step would be:
- Change version/version.go and versions/description
- Prepare a release calling `make prepare-(patch|minor|major)`
- Edit version/description to set a description and order commits
- Create a PR to review it
- Merge it to master
- Call `make release` from master
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ $(description): version/description
sed "s#HANDLER_IMAGE#$(HANDLER_IMAGE)#" \
version/description > $@

prepare-patch:
./hack/prepare-release.sh patch
prepare-minor:
./hack/prepare-release.sh minor
prepare-major:
./hack/prepare-release.sh major

# This uses target specific variables [1] so we can use push-handler as a
# dependency and change the SUFFIX with the correct version so no need for
# calling make on make is needed.
Expand Down
32 changes: 32 additions & 0 deletions hack/bump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash -e

expected_types="(major|minor|patch)"
current_type=$1

bump() {
version=$(hack/version.sh)
version_part=$(echo $version |sed $1)
version_part=$((++version_part))
version=$(echo $version | sed $2 | sed "s/version_part/$version_part/g")
./hack/version.sh $version
}

bump_major() {
bump "s/^v\(.*\)[.].*[.].*$/\1/g" "s/^v\(.*\)[.]\(.*\)[.]\(.*\)$/version_part.\2.\3/g"
}

bump_minor() {
bump "s/^v.*[.]\(.*\)[.].*$/\1/g" "s/^v\(.*\)[.]\(.*\)[.]\(.*\)$/\1.version_part.\3/g"
}

bump_patch() {
bump "s/^v.*[.].*[.]\(.*\)$/\1/g" "s/^v\(.*\)[.]\(.*\)[.]\(.*\)$/\1.\2.version_part/g"
}

if [[ ! $current_type =~ $expected_types ]]; then
echo "Usage: $0 $expected_types"
exit 1
fi

bump_$current_type
hack/version.sh
34 changes: 34 additions & 0 deletions hack/prepare-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash -e
version_type=$1
old_version=$(hack/version.sh)
new_version=$(hack/bump-version.sh $version_type)
commits=$(git log --pretty=format:"* %s" $old_version..HEAD)


cat << EOF > version/description
$new_version
TODO: Add description here
TODO: keep at every category the
commits that make sense
Features:
$commits
Bugs:
$commits
Docs:
$commits
\`\`\`
docker pull HANDLER_IMAGE
\`\`\`
EOF

${EDITOR:-vi} version/description

git checkout -b release-$new_version
git commit -a -s -m "Release $new_version"
9 changes: 8 additions & 1 deletion hack/version.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
#!/bin/bash -e
grep = version/version.go | sed -r 's/.*= \"(.*)"$$/v\1/g'
version_file=version/version.go
# If we don't pass a version just show current one
if [ -z "$1" ]; then
grep = $version_file | sed -r 's/.*= \"(.*)"$$/v\1/g'
# else change it
else
sed -i "s/= \".*\"$/= \"$1\"/g" $version_file
fi

0 comments on commit 5e9e0c3

Please sign in to comment.