Rakefile in u3d-1.0.2 vs Rakefile in u3d-1.0.3
- old
+ new
@@ -21,15 +21,127 @@
## --- END LICENSE BLOCK ---
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'rubocop/rake_task'
+require 'u3d'
+UI = U3dCore::UI
+
# doesn't yet support dot file
# https://github.com/skywinder/github-changelog-generator/issues/473
# require 'github_changelog_generator/task'
RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new
+
+class GithubChangelogGenerator
+ PATH = '.github_changelog_generator'.freeze
+ class << self
+ def future_release
+ s = File.read(PATH)
+ s.split("\n").each do |line|
+ m = line.match(/future-release=v(.*)/)
+ return m[1] if m
+ end
+ raise "Couldn't find future-release in #{PATH}"
+ end
+
+ def future_release=(nextv)
+ s = File.read(PATH)
+ lines = s.split("\n").map do |line|
+ m = line.match(/future-release=v(.*)/)
+ if m
+ "future-release=v#{nextv}"
+ else
+ line
+ end
+ end
+ File.write(PATH, lines.join("\n") + "\n")
+ end
+ end
+end
+
+class U3dCode
+ PATH = 'lib/u3d/version.rb'.freeze
+ class << self
+ def version=(version)
+ s = File.read(PATH)
+ lines = s.split("\n").map do |line|
+ m = line.match(/(.*VERSION = ').*('.freeze.*)/)
+ if m
+ "#{m[1]}#{version}#{m[2]}"
+ else
+ line
+ end
+ end
+ File.write(PATH, lines.join("\n") + "\n")
+ end
+ end
+end
+
+def run_command(command, error_message = nil)
+ output = `#{command}`
+ unless $CHILD_STATUS.success?
+ error_message = "Failed to run command '#{command}'" if error_message.nil?
+ UI.user_error!(error_message)
+ end
+ output
+end
+
+task :ensure_git_clean do
+ branch = run_command('git rev-parse --abbrev-ref HEAD', "Couldn't get current git branch").strip
+ UI.user_error!("You are not on 'master' but on '#{branch}'") unless branch == "master"
+ output = run_command('git status --porcelain', "Couldn't get git status")
+ UI.user_error!("git status not clean:\n#{output}") unless output == ""
+end
+
+# ensure ready to prepare a PR
+task :prepare_git_pr, [:pr_branch] do |_t, args|
+ pr_branch = args['pr_branch']
+ raise "Missing pr_branch argument" unless pr_branch
+ UI.user_error! "Prepare git PR stopped by user" unless UI.confirm("Creating PR branch #{pr_branch}")
+ run_command("git checkout -b #{pr_branch}")
+end
+
+task pre_release: 'ensure_git_clean' do
+ require 'u3d/version'
+ nextversion = U3d::VERSION
+
+ # check not already released
+ output = run_command("git tag -l v#{nextversion}").strip
+ UI.user_error! "Version '#{nextversion}' already released. Run 'rake bump'" unless output == ''
+
+ gh_future_release = GithubChangelogGenerator.future_release
+ UI.user_error! "GithubChangelogGenerator version #{gh_future_release} != #{nextversion}" unless gh_future_release == nextversion
+
+ pr_branch = "release_#{nextversion}"
+ Rake::Task["prepare_git_pr"].invoke(pr_branch)
+
+ Rake::Task["changelog"].invoke
+
+ sh('git diff')
+ UI.user_error! "Pre release stopped by user." unless UI.confirm("CHANGELOG PR for version #{nextversion}. Confirm?")
+
+ msg = "Preparing release for #{nextversion}"
+ sh 'git add CHANGELOG.md'
+ sh "git commit -m '#{msg}'"
+ sh "git push lacostej" # FIXME: hardcoded
+ # FIXME check hub present
+ sh "hub pull-request -m '#{msg}' -l nochangelog"
+ sh 'git checkout master'
+ sh "git branch -D #{pr_branch}"
+end
+
+task bump: 'ensure_git_clean' do
+ nextversion = UI.input "Next version will be:"
+ UI.user_error! "Bump version stopped by user" unless UI.confirm("Next version will be #{nextversion}. Confirm?")
+ U3dCode.version = nextversion
+ GithubChangelogGenerator.future_release = nextversion
+ sh 'rspec'
+ sh 'git add .github_changelog_generator lib/u3d/version.rb Gemfile.lock'
+ sh "git commit -m 'Bump version to #{nextversion}'"
+ sh 'git push'
+end
task :changelog do
puts "Updating changelog #{ENV['CHANGELOG_GITHUB_TOKEN']}"
sh "github_changelog_generator" if ENV['CHANGELOG_GITHUB_TOKEN']
end