diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b8e8e410..5280759b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,8 @@ name: release on: - push: - tags: - - 'v*' + releases: + types: [unpublished] jobs: goreleaser: diff --git a/.goreleaser.yml b/.goreleaser.yml index 24392499..59678656 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -4,6 +4,8 @@ before: builds: - env: - CGO_ENABLED=0 + ldflags: + - '-s -w -X version.ProviderVersion={{.Version}}' goos: - freebsd - openbsd diff --git a/GNUmakefile b/GNUmakefile index db6f4354..3bc08b39 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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) | \ diff --git a/heroku/version.go b/heroku/version.go deleted file mode 100644 index 156a0fd0..00000000 --- a/heroku/version.go +++ /dev/null @@ -1,16 +0,0 @@ -// +build ignore - -// This a hack to populate the version in the custom binary file as this provider is not official. - -package main - -import ( - "fmt" - "github.com/heroku/terraform-provider-heroku/version" -) - -var ver = version.ProviderVersion - -func main() { - fmt.Println(ver) -} diff --git a/scripts/build-release b/scripts/build-release index cfbf2242..d664cf8f 100755 --- a/scripts/build-release +++ b/scripts/build-release @@ -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 @@ -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 @@ -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 diff --git a/version/version.go b/version/version.go index 4f3453d4..a0dacbbc 100644 --- a/version/version.go +++ b/version/version.go @@ -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" )