Skip to content

Commit

Permalink
Add release tools
Browse files Browse the repository at this point in the history
Add rake based release tools to easily deploy new version and its
artifacts.
  • Loading branch information
niezbop committed Nov 14, 2017
1 parent 184b610 commit 563a1ae
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .github_changelog_generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
future-release=v1.0.0beta2
since-tag=v1.0.0beta1
exclude_tags_regex=v0\.[0-8]\..*
exclude-labels=nochangelog
cache_log=./github-changelog-generator.log
2 changes: 1 addition & 1 deletion Assets/Plugins/Editor/Uplift/About.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Uplift
{
internal static class About
{
public static readonly string Version = "1.0.0beta1";
public static readonly string Version = "1.0.0beta2";
public static readonly string[] Authors = new string[]
{
"Przemysław Kamiński",
Expand Down
Empty file added CHANGELOG.md
Empty file.
230 changes: 205 additions & 25 deletions DevelopmentTools/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,218 @@
# Please refrain from expanding this file unless really necessary

require 'fileutils'
require 'github_api'
require 'u3d'

UI = U3dCore::UI

task :chdir do
file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
rakefile_dir = File.expand_path File.dirname file
Dir.chdir(File.join(rakefile_dir, '..'))
file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
rakefile_dir = File.expand_path File.dirname file
Dir.chdir(File.join(rakefile_dir, '..'))
end

task :install_gems => [:chdir] do
sh('bundle install')
task install_gems: [:chdir] do
sh('bundle install')
end

desc "Run the tests using u3d"
task :test => [:chdir] do
pwd = Dir.pwd
sh "bundle exec u3d run -- -logFile u3d.log -runTests -projectPath #{pwd} -testResults #{pwd}/results.xml -testPlatform editmode -batchmode"
desc 'Run the tests using u3d'
task test: [:chdir] do
pwd = Dir.pwd
sh "bundle exec u3d run -- -logFile u3d.log -runTests -projectPath #{pwd} -testResults #{pwd}/results.xml -testPlatform editmode -batchmode"
end

desc 'Build the Uplift DLL and the unitypackage contain the DLL and its dependencies'
task :build, [:unity_version] => [:chdir] do |t, args|
args.with_defaults(unity_version: '5.6.0f3')
unity_version = args[:unity_version]
File.write("ProjectSettings/ProjectVersion.txt", "m_EditorVersion: #{unity_version}")
FileUtils.cp("ProjectSettings/ProjectVersion.txt", "Build/ProjectSettings/ProjectVersion.txt")

sh('bundle exec u3d -- -logFile u3d.log -batchmode -quit -executeMethod BuildTool.DllCompiler.BuildPackage')

editor_dir = File.join('Assets', 'Plugins', 'Editor')
# prepare a Unity package
dirs = [ editor_dir ]
uplift_package = File.absolute_path File.join('target', "Uplift_#{unity_version}.unitypackage")
Dir.chdir('Build') do
sh("bundle exec u3d -- -logFile u3d.log -batchmode -quit -exportPackage #{dirs.join(" ")} #{uplift_package}")
end
puts "File #{uplift_package} generated!"
task :build, [:unity_version] => [:chdir] do |_t, args|
args.with_defaults(unity_version: '5.6.0f3')
unity_version = args[:unity_version]
File.write('ProjectSettings/ProjectVersion.txt', "m_EditorVersion: #{unity_version}")
FileUtils.cp('ProjectSettings/ProjectVersion.txt', 'Build/ProjectSettings/ProjectVersion.txt')

sh('bundle exec u3d -- -logFile u3d.log -batchmode -quit -executeMethod BuildTool.DllCompiler.BuildPackage')

editor_dir = File.join('Assets', 'Plugins', 'Editor')
# prepare a Unity package
dirs = [editor_dir]
uplift_package = File.absolute_path File.join('target', "Uplift_#{unity_version}.unitypackage")
Dir.chdir('Build') do
sh("bundle exec u3d -- -logFile u3d.log -batchmode -quit -exportPackage #{dirs.join(' ')} #{uplift_package}")
end
puts "File #{uplift_package} generated!"
end

# DEPLOYMENT

artifact_targets = ['5.6.0f3', '2017.1.2f1']
repository = 'uplift'
owner = 'Dragonbox'

desc 'Make sure the current branch is master, and no changes have been made'
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

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

desc 'Bump the version number to the version entered interactively; pushes a commit to master'
task bump: %i[ensure_git_clean chdir] 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?")
UpliftCode.version = nextversion
GithubChangelogGenerator.future_release = nextversion
sh 'git add .github_changelog_generator Assets/Plugins/Editor/Uplift/About.cs'
sh "git commit -m \"Bump version to #{nextversion}\""
sh 'git push'
end

desc 'Update the changelog, no commit made'
task :changelog do
puts "Updating changelog #{ENV['UPLIFT_GITHUB_TOKEN']}"
sh 'github_changelog_generator' if ENV['UPLIFT_GITHUB_TOKEN']
end

desc 'Prepare a release: check repo status, generate changelog, create PR'
task pre_release: %i[ensure_git_clean chdir] do
nextversion = UpliftCode.version

# check if not already prereleased
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

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 origin #{pr_branch}"

github = MyGithub.github
github.pull_requests.create owner, repository,
title: msg,
body: 'This is automatically generated to prepare for the new version',
head: pr_branch,
base: 'master'

sh 'git checkout master'
sh "git branch -D #{pr_branch}"
end

desc 'Release the new version and generate artifacts to attach to it'
task release: %i[ensure_git_clean chdir] do
nextversion = UpliftCode.version

# check if preleased
output = run_command("git tag -l v#{nextversion}").strip
UI.user_error! "Version '#{nextversion}' has not been prepared, run 'rake pre_release'" if output == ''

tag_name = 'v' + nextversion

github = MyGithub.github
release = github.repos.releases.create owner, repository,
tag_name: tag_name,
target_commitish: 'master',
name: "Release for version #{tag_name}",
draft: true,
prelease: false

artifact_targets.each do |tar|
puts "--- #{tar} ---"
Rake::Task['build'].invoke(tar)
Rake::Task['build'].reenable
end

Dir['target/*.unitypackage'].each do |artifact|
github.repos.releases.assets.upload owner, repository, release['id'], artifact,
name: File.basename(artifact),
content_type: 'application/octet-stream'
end
end

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 UpliftCode
PATH = 'Assets/Plugins/Editor/Uplift/About.cs'.freeze
class << self
def version
s = File.read(PATH)
s.split("\n").each do |line|
m = line.match(/public static readonly string Version = "(.*)"/)
return m[1] if m
end
UI.user_error! 'Could not retrieve version from codebase'
end

def version=(version)
s = File.read(PATH)
lines = s.split("\n").map do |line|
m = line.match(/(.*public static readonly string Version = ").*(".*)/)
if m
"#{m[1]}#{version}#{m[2]}"
else
line
end
end
File.write(PATH, lines.join("\n") + "\n")
end
end
end

class MyGithub
@github
def self.github
@github = Github.new oauth_token: ENV['UPLIFT_GITHUB_TOKEN'] unless @github
@github
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 default: ['test']
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ ruby "2.3.3"
source 'https://rubygems.org'

gem 'u3d', '>= 1.0.3'
gem 'github_api', '>= 0.18.0'

27 changes: 27 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
colored (1.2)
commander (4.4.3)
highline (~> 1.7.2)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
file-tail (1.2.0)
tins (~> 1.0)
filesize (0.1.1)
github_api (0.18.1)
addressable (~> 2.4)
descendants_tracker (~> 0.0.4)
faraday (~> 0.8)
hashie (>= 3.4)
oauth2 (~> 1.0)
hashie (3.5.6)
highline (1.7.8)
inifile (3.0.0)
jwt (1.5.6)
multi_json (1.12.2)
multi_xml (0.6.0)
multipart-post (2.0.0)
oauth2 (1.4.0)
faraday (>= 0.8, < 0.13)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
plist (3.3.0)
public_suffix (3.0.1)
rack (2.0.3)
security (0.1.3)
thread_safe (0.3.6)
tins (1.15.0)
u3d (1.0.8)
colored (>= 1.2, < 2.0.0)
Expand All @@ -26,6 +52,7 @@ PLATFORMS
x64-mingw32

DEPENDENCIES
github_api (>= 0.18.0)
u3d (>= 1.0.3)

RUBY VERSION
Expand Down

0 comments on commit 563a1ae

Please sign in to comment.