Skip to content

Commit

Permalink
Add script to publish release and auto generate CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
PrasadG193 committed Jun 10, 2019
1 parent 50deb51 commit e3d771e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
23 changes: 8 additions & 15 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;
@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 public the release."
echo "=============================================================="

0 comments on commit e3d771e

Please sign in to comment.