Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to publish release and auto generate CHANGELOG #101

Merged
merged 1 commit into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ IMAGE_REPO=infracloud/botkube
TAG=$(shell cut -d'=' -f2- .release)

.DEFAULT_GOAL := build
.PHONY: release git-tag check-git-status build pre-build tag-image publish helm-chart
.PHONY: release git-tag check-git-status build container-image pre-build tag-image publish

#Docker Tasks
#Make a release
release: check-git-status build tag-image publish helm-chart git-tag
release: check-git-status container-image tag-image publish git-tag
@echo "Successfully released version $(TAG)"

#Create a git tag
git-tag:
@echo "Creating a git tag"
@git add .
@git commit -m "Bumped to version $(TAG)" ;
@git add .release helm/botkube deploy-all-in-one.yaml deploy-all-in-one-tls.yaml CHANGELOG.md
@git commit -m "Release $(TAG)" ;
@git tag $(TAG) ;
@git push --tags origin master;
@git push --tags origin develop;
@echo 'Git tag pushed successfully' ;

#Check git status
check-git-status:
@echo "Checking git status"
@if [ -n "$(shell git tag | grep $(TAG))" ] ; then echo 'Tag already exists' && exit 1 ; fi
@if [ -z "$(shell git remote -v)" ] ; then echo 'No remote to push tags to' && exit 1 ; fi
@if [ -z "$(shell git config user.email)" ] ; then echo 'Unable to detect git credentials' && exit 1 ; fi
@if [ -n "$(shell git tag | grep $(TAG))" ] ; then echo 'ERROR: Tag already exists' && exit 1 ; fi
@if [ -z "$(shell git remote -v)" ] ; then echo 'ERROR: No remote to push tags to' && exit 1 ; fi
@if [ -z "$(shell git config user.email)" ] ; then echo 'ERROR: Unable to detect git credentials' && exit 1 ; fi

#Build the binary
build: pre-build
Expand All @@ -38,24 +38,17 @@ container-image: pre-build
#Pre-build checks
pre-build:
@echo "Checking system information"
@if [ -z "$(shell go env GOOS)" ] || [ -z "$(shell go env GOARCH)" ] ; then echo 'Could not determine the system architecture.' && exit 1 ; fi
@if [ -z "$(shell go env GOOS)" ] || [ -z "$(shell go env GOARCH)" ] ; then echo 'ERROR: Could not determine the system architecture.' && exit 1 ; fi


#Tag images
tag-image:
@echo 'Tagging image'
@docker tag $(IMAGE_REPO) $(IMAGE_REPO):$(TAG)
@docker tag $(IMAGE_REPO) $(IMAGE_REPO):latest

#Docker push image
publish:
@echo "Pushing docker image to repository"
@docker login
@docker push $(IMAGE_REPO):$(TAG)
@docker push $(IMAGE_REPO):latest

#Update Helm chart
helm-chart:
@echo "Updating helm charts"
@sed -i 's/version.*/version: $(TAG)/' helm/botkube/Chart.yaml
@sed -i 's/{BOTKUBE_VERSION}/$(TAG)/' deploy-all-in-one.yaml
41 changes: 41 additions & 0 deletions hack/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

set -e

version=$(cut -d'=' -f2- .release)
if [[ -z ${version} ]]; then
echo "Invalid version set in .release";
exit 1
fi

echo "Publishing release ${version}"

generate_changelog() {
local version=$1

# generate changelog from github
github_changelog_generator infracloudio/botkube -t ${GITHUB_TOKEN} --future-release ${version} -o CHANGELOG.md
sed -i '$d' CHANGELOG.md
}

update_chart_yamls() {
local version=$1

sed -i "s/version.*/version: ${version}/" helm/botkube/Chart.yaml
sed -i "s/appVersion.*/appVersion: ${version}/" helm/botkube/Chart.yaml
sed -i "s/\bimage: \"infracloud\/botkube.*\b/image: \"infracloud\/botkube:${version}/g" deploy-all-in-one.yaml
sed -i "s/\bimage: \"infracloud\/botkube.*\b/image: \"infracloud\/botkube:${version}/g" deploy-all-in-one-tls.yaml

oldVersion=$(echo $(awk '/BOTKUBE_VERSION/ {getline; print}' deploy-all-in-one.yaml))
sed -i "s/\b${oldVersion}\b/value: ${version}/g" deploy-all-in-one.yaml
sed -i "s/\b${oldVersion}\b/value: ${version}/g" deploy-all-in-one-tls.yaml
}

update_chart_yamls $version
generate_changelog $version
make release

echo "=========================== Done ============================="
echo "Congratulations!! Release ${version} tagged."
echo "Now go to github releases and publish the release."
echo "=============================================================="