Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Release script (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo authored Jul 31, 2018
1 parent 0a1b69b commit ac9b2cb
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ terraform-provider-bless
.vscode
terraform.tfstate*
dist
*-packr.go
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ build:

test:
@TF_ACC=yes go test -cover -v ./...

packr:
packr

release: packr
./release

.PHONY: build test packr release
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ provider "bless" {
profile = "<aws_profile>"
}
resource "bless" "example" {
resource "bless_ca" "example" {
kms_key_id = "<kms_key_id>"
}
Expand Down
108 changes: 108 additions & 0 deletions release
Original file line number Diff line number Diff line change
@@ -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`

0 comments on commit ac9b2cb

Please sign in to comment.