Skip to content

Commit

Permalink
update build-release to accept the version instead of hardcoding it [#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidji99 committed Jul 29, 2020
1 parent dd4912b commit a59e7c9
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 28 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: release

on:
push:
tags:
- 'v*'
releases:
types: [unpublished]

jobs:
goreleaser:
Expand Down
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ before:
builds:
- env:
- CGO_ENABLED=0
ldflags:
- '-s -w -X version.ProviderVersion={{.Version}}'
goos:
- freebsd
- openbsd
Expand Down
4 changes: 3 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ default: build
build: fmtcheck
go install

# Example usage: make release version=0.11.0
release: fmtcheck
scripts/build-release
@echo "Generating release."
./scripts/build-release $(version)

test: fmtcheck
echo $(TEST) | \
Expand Down
16 changes: 0 additions & 16 deletions heroku/version.go

This file was deleted.

34 changes: 27 additions & 7 deletions scripts/build-release
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env bash

COLOR_RED='\033[0;31m'
os=$(uname)
COLOR_NONE='\033[0m'
PROVIDER="heroku"
VERSION=$(go run ${PROVIDER}/version.go)
CURRENT_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)

if [ $CURRENT_GIT_BRANCH != 'master' ]; then
Expand All @@ -14,6 +13,18 @@ if [ $CURRENT_GIT_BRANCH != 'master' ]; then
exit 1
fi

if [ $# -ne 1 ]; then
printf "\n"
printf "${COLOR_RED} Error: Release version argument required. \n\n ${COLOR_NONE}"
printf " Example: \n\n ./scripts/build 0.9.0 \n\n"
printf " Example (make): \n\n make release version=0.9.0 \n"
printf "\n"

exit 1
fi

VERSION="v${1}"

echo "Pulling down latest from origin"
git pull origin master

Expand All @@ -22,19 +33,28 @@ git checkout master

echo "Checking if master branch is clean"
if [ "$(git status --porcelain)" != "" ]; then
echo "branch is not clean. please add/commit or stage any changes first"
printf "\n"
printf "${COLOR_RED} Error: branch is not clean. please add/commit or stage any changes first"
printf "\n"

exit 1
fi

echo "Checking if local & remote master branch are in sync"
if [ "$(git diff master origin/master)" != "" ]; then
echo "Local and remote master branch are not in sync. Please rectify"
printf "\n"
printf "${COLOR_RED} Local and remote master branch are not in sync"
printf "\n"

exit 1
fi

echo "Checking if the tag already exists"
if git show ${VERSION} >> /dev/null 2>&1 || false ; then
echo "tag ${VERSION} already exists. Did you forget to bump the version in version/version.go file?"
echo "Checking if ${VERSION} tag already exists"
if git rev-parse "$VERSION" >/dev/null 2>&1; then
printf "\n"
printf "${COLOR_RED} Error: ${VERSION} already exists! ${COLOR_NONE}"
printf "\n"

exit 1
fi

Expand Down
10 changes: 9 additions & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package version

//Cribbed from
//https://github.com/terraform-providers/terraform-provider-azurerm/tree/master/version
//This takes advantage of a new build flag populating the binary version of the
//provider, for example:
//-ldflags="-X=github.com/heroku/terraform-provider-heroku/version.ProviderVersion=x.x.x"

var (
ProviderVersion = "2.6.0"
// ProviderVersion is set during the release process to the release version of the binary, and
// set to acc during tests.
ProviderVersion = "dev"
)

0 comments on commit a59e7c9

Please sign in to comment.