Skip to content

Commit

Permalink
Added automated release rake tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorrowe committed Oct 24, 2014
1 parent d70fc92 commit 5cb8e97
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
$VERSION = File.read(File.expand_path('../VERSION', __FILE__)).strip
$VERSION = ENV['VERSION'] ||
File.read(File.expand_path('../VERSION', __FILE__)).strip
$GITHUB_ACCESS_TOKEN = ENV['JMESPATH_GITHUB_ACCESS_TOKEN']

Dir.glob('**/*.rake').each do |task_file|
load task_file
Expand Down
1 change: 1 addition & 0 deletions lib/jmespath.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module JMESPath
autoload :Token, 'jmespath/token'
autoload :TokenStream, 'jmespath/token_stream'
autoload :TreeInterpreter, 'jmespath/tree_interpreter'
autoload :VERSION, 'jmespath/version'

class << self

Expand Down
3 changes: 3 additions & 0 deletions lib/jmespath/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module JMESPath
VERSION = '0.2.0'
end
36 changes: 36 additions & 0 deletions tasks/changelog.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
task 'changelog:version' do
# replaces "Next Release (TBD)" in the CHANGELOG with a version and date
changelog = File.open('CHANGELOG.md', 'r', encoding: 'UTF-8') { |f| f.read }
changelog = changelog.lines
changelog[0] = "#{$VERSION} (#{Time.now.strftime('%Y-%m-%d')})\n"
changelog = changelog.join
File.open('CHANGELOG.md', 'w', encoding: 'UTF-8') { |f| f.write(changelog) }
sh("git add CHANGELOG.md")
end

task 'changelog:next_release' do
# inserts a "Next Release (TDB)" section at the top of the CHANGELOG
lines = []
lines << "Next Release (TBD)\n"
lines << "------------------\n"
lines << "\n"
changelog = File.open('CHANGELOG.md', 'r', encoding: 'UTF-8') { |f| f.read }
changelog = lines.join + changelog
File.open('CHANGELOG.md', 'w', encoding: 'UTF-8') { |f| f.write(changelog) }
sh("git add CHANGELOG.md")
sh("git commit -m 'Added next release section to the changelog.'")
end

task 'changelog:latest' do
# Returns the contents of the most recent CHANGELOG section
changelog = File.open('CHANGELOG.md', 'r', encoding: 'UTF-8') { |f| f.read }
lines = []
changelog.lines[3..-1].each do |line|
if line.match(/^\d+\.\d+\.\d+/)
break
else
lines << line
end
end
puts lines[0..-2].join
end
31 changes: 31 additions & 0 deletions tasks/git.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
task 'git:require-clean-workspace' do
# Ensure the git repo is free of unstaged or untracked files prior
# to building / testing / pushing a release.
unless `git diff --shortstat 2> /dev/null | tail -n1` == ''
warn('workspace must be clean to release')
exit
end
end

task 'git:tag' do
sh("git commit -m \"Bumped version to v#{$VERSION}\"")
sh("git tag -a -m \"$(rake git:tag_message)\" v#{$VERSION}")
end

task 'git:tag_message' do
issues = `git log $(git describe --tags --abbrev=0)...HEAD -E --grep '#[0-9]+' 2>/dev/null`
issues = issues.scan(/((?:\S+\/\S+)?#\d+)/).flatten
msg = "Tag release v#{$VERSION}"
msg << "\n\n"
unless issues.empty?
msg << "References: #{issues.uniq.sort.join(', ')}"
msg << "\n\n"
end
msg << `rake changelog:latest`
puts msg
end

task 'git:push' do
sh('git push origin')
sh('git push origin --tags')
end
29 changes: 29 additions & 0 deletions tasks/github.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
task 'github:require-access-token' do
unless $GITHUB_ACCESS_TOKEN
warn("you must export JMESPATH_GITHUB_ACCESS_TOKEN")
exit
end
end

task 'github:release' do
require 'octokit'

gh = Octokit::Client.new(access_token: $GITHUB_ACCESS_TOKEN)

repo = 'trevorrowe/jmespath.rb'
tag_ref_sha = `git show-ref v#{version}`.split(' ').first
tag = gh.tag(repo, tag_ref_sha)

release = gh.create_release(repo, "v#{version}", {
name: 'Release v' + version + ' - ' + tag.tagger.date.strftime('%Y-%m-%d'),
body: tag.message.lines[2..-1].join,
prerelease: version.match('rc') ? true : false,
})

gh.upload_asset(release.url, 'docs.zip',
:content_type => 'application/octet-stream')

gh.upload_asset(release.url, "jmespath-#{$VERSION}.gem",
:content_type => 'application/octet-stream')

end
41 changes: 41 additions & 0 deletions tasks/release.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
task 'release:require-version' do
unless ENV['VERSION']
warn("usage: VERSION=x.y.z rake release")
exit
end
end

task 'release:bump-version' do
sh("echo '#{$VERSION}' > VERSION")
path = 'lib/jmespath/version.rb'
file = File.read(path)
file = file.gsub(/VERSION = '.+?'/, "VERSION = '#{$VERSION}'")
File.open(path, 'w') { |f| f.write(file) }
sh("git add #{path}")
sh("git add VERSION")
end

task 'release:stage' => [
'release:require-version',
'github:require-access-token',
'git:require-clean-workspace',
'test:unit',
'changelog:version',
'release:bump-version',
'git:tag',
'gem:build',
'docs:zip',
]

task 'release:publish' => [
'git:push',
'gems:push',
'github:release',
]

task 'release:cleanup' => [
'changelog:next_release',
]

desc "Public release"
task :release => ['release:stage', 'release:publish', 'release:cleanup']

0 comments on commit 5cb8e97

Please sign in to comment.