Created
December 1, 2016 05:15
-
-
Save cmtonkinson/ea8d1433cca27841e1dbac8c1c096ff5 to your computer and use it in GitHub Desktop.
Very early UI on top of rake-version gem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "Bump the version, update the changelog, create a new tag" | |
task :release, [:semver, :debug] do |task, args| | |
@debug = false | |
@semver_type = nil | |
@old_version = nil | |
@new_version = nil | |
@commit_log = nil | |
@today = Date.today.strftime('%Y-%m-%d') | |
@debug = true unless args[:debug].nil? | |
if args[:semver].nil? | |
puts "No semver type given {major,minor,patch}. Exiting." | |
puts args.to_hash.inspect if @debug | |
exit 1 | |
else | |
@semver_type = args[:semver] | |
puts "Creating new #{@semver_type} release." if @debug | |
end | |
############################################################################# | |
# Get current version. | |
@old_version = `cat VERSION` | |
puts "Previous version #{@old_version}" if @debug | |
############################################################################# | |
# Bump the version. | |
print "New version " | |
Rake::Task["version:bump:#{@semver_type}"].invoke | |
@new_version = `cat VERSION` | |
############################################################################# | |
# List commits since last version. | |
@commit_log = `git log --pretty=format:'%h %s (%aN)' #{@old_version}..HEAD`.split "\n" | |
if @debug | |
puts "New changes:" | |
puts @commit_log.map { |c| " #{c}" } | |
end | |
############################################################################# | |
# Add the changelog entries. | |
additions = "\n## %s (%s)\n\n" % [@new_version, @today] | |
additions << @commit_log.map { |c| " * #{c}\n" }.reduce(:+) | |
existing = IO.read 'CHANGELOG.md' | |
IO.write 'CHANGELOG.md', additions + existing | |
puts `cat CHANGELOG.md` if @debug | |
############################################################################# | |
# Create a new commit with the version and changelog. | |
`git add VERSION CHANGELOG.md` | |
`git commit -m "Release version #{@new_version}"` | |
puts `git show` if @debug | |
############################################################################# | |
# Create a new tag for the version. | |
`git tag #{@new_version} HEAD` | |
if @debug | |
print "Created new release tag: " | |
puts `git tag --list -n1 --contains HEAD` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment