From ac9b2cbffbf6723c5b99bd2f8f7c3b47ca02188d Mon Sep 17 00:00:00 2001 From: Eduardo Date: Mon, 30 Jul 2018 20:23:37 -0700 Subject: [PATCH] Release script (#9) --- .gitignore | 1 + Makefile | 8 ++++ README.md | 2 +- release | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100755 release diff --git a/.gitignore b/.gitignore index cddb1e4c..2c6a5067 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ terraform-provider-bless .vscode terraform.tfstate* dist +*-packr.go diff --git a/Makefile b/Makefile index 940fbc82..63dead0d 100644 --- a/Makefile +++ b/Makefile @@ -3,3 +3,11 @@ build: test: @TF_ACC=yes go test -cover -v ./... + +packr: + packr + +release: packr + ./release + +.PHONY: build test packr release diff --git a/README.md b/README.md index 341e0ec9..02d18311 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ provider "bless" { profile = "" } -resource "bless" "example" { +resource "bless_ca" "example" { kms_key_id = "" } diff --git a/release b/release new file mode 100755 index 00000000..495f5b1b --- /dev/null +++ b/release @@ -0,0 +1,108 @@ +#!/usr/bin/env ruby + +require 'rubygems' +require 'git' +require 'logger' +require 'semantic' + + +g = Git.open('.') +g.fetch('origin', {tags: true}) + +if g.status.changed.length > 0 + puts "Please release only from a clean working directory (no uncommitted changes)." + exit(1) +end + +head_sha = g.object("HEAD").sha +master_sha = g.object("origin/master").sha + +if head_sha != master_sha + puts "Please only release versions from master, that way the tagged git sha is on master." + puts "SHAs on branches could go away if a PR is squash-merged." + exit(1) +end + +tag_index = g.tags.inject(Hash.new) do |ind, t| + ind[t.objectish] = t.name + ind +end + +tag, sha = nil, nil + +g.log(1000).each do |c| + if (tag = tag_index[c.sha]) + sha = c.sha + break + end +end + +puts "Found tag #{tag}" +puts "sha for that tag: #{sha}" + +v = open('VERSION').read.strip +semver = Semantic::Version.new(v) + +puts "VERSION file says #{v}" + +if tag.sub('v', '') != v + puts "tag does not match version file" + exit(1) +end + +breaking = false +feature = false +puts "included commits…" +g.log.between("v#{v}", 'HEAD').each do |commit| + puts "* #{commit.message}" + + if commit.message.include?("[breaking]") + breaking = true + end + if commit.message.include?("[feature]") + feature = true + end +end + +if breaking + puts "this appears to be a breaking change" +else + puts "this appears not to be a breaking change" +end + +release_type = if semver.major < 1 + if breaking + "minor" + else + "patch" + end +else + if breaking + "major" + elsif feature + "minor" + else + "patch" + end +end + +puts "release type is #{release_type}" + +new_version = semver.increment!(release_type.to_sym) + +puts "shall we do a #{release_type} release? new version will be #{new_version} (y/n)" +a = gets.chomp +if a != 'y' + puts "canceled" + exit(1) +end + +f = open('VERSION', 'w') +f.write(new_version.to_s) +f.close() + +g.add('VERSION') +g.commit("release version #{new_version.to_s}") +g.add_tag("v#{new_version.to_s}") + +`make release`