Skip to content

Commit

Permalink
Github release progress
Browse files Browse the repository at this point in the history
  • Loading branch information
weeeBox committed Feb 1, 2016
1 parent 78ac5e1 commit 8603a44
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea
/out
/credentials.rb
/dropbox_deploy_credentials.rb
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@ DEPENDENCIES
dropbox-sdk
rake
rubyzip (>= 1.0.0)

BUNDLED WITH
1.10.6
84 changes: 80 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ require_relative 'common'
require_relative 'git'

require_relative 'dropbox_deploy'
require_relative 'credentials'
require_relative 'dropbox_deploy_credentials'

include Common

task :init do

$git_repo = 'https://github.com/ArduboyGameDevelopers/PixelSpaceOdyssey.git'
$git_branch = 'feature/level_editor'
$git_branch = 'develop'

$project_name = 'PixelSpaceOdyssey'
$project_config = 'Release'

$dir_builder = File.expand_path '.'
$dir_tools = resolve_path "#{$dir_builder}/tools"
$dir_project = "#{$dir_repo}/#{$project_name}"

$dir_out = "#{$dir_builder}/out"
Expand Down Expand Up @@ -50,9 +52,9 @@ task :build => :clone_repo do
not_nil $1
end

project_version = extract_project_version $dir_emu
$project_version = extract_project_version $dir_emu

puts "Project version: #{project_version}"
puts "Project version: #{$project_version}"

# create directory
dir_build = "#{$dir_emu_build}/#{$project_config}"
Expand Down Expand Up @@ -107,7 +109,7 @@ task :build => :clone_repo do

make_dir $dir_out_builds, :overwrite => true

file_build = "#{$dir_out_builds}/#{$project_name}-#{project_version}.zip"
file_build = "#{$dir_out_builds}/#{$project_name}-#{$project_version}.zip"
zip_dir dir_deploy, file_build

end
Expand All @@ -121,3 +123,77 @@ task :deploy => :build do
dropbox.deploy file_build

end

desc 'Create Github release'
task :create_github_release => [:build] do

file_package = resolve_path Dir["#{$dir_out_builds}/*.zip"].first

# Merge changes to master
Git.git_merge $dir_repo, $git_branch, 'master'

# Create release
github_create_release $dir_repo, $project_version, file_package

end

def github_create_release(dir_repo, version, package_zip)

fail_script_unless_file_exists dir_repo
fail_script_unless_file_exists package_zip

github_release_bin = resolve_path "#{$dir_tools}/github/github-release"

Dir.chdir dir_repo do

name = "Pixel Space Odyssey v#{version}"
tag = version

repo_name = git_get_repo_name '.'
fail_script_unless repo_name, "Unable to extract repo name: #{dir_repo}"

# delete old release
cmd = %("#{github_release_bin}" delete)
cmd << %( -s #{$github_access_token})
cmd << %( -u #{$github_owner})
cmd << %( -r #{repo_name})
cmd << %( -t "#{tag}")

exec_shell cmd, "Can't remove old release", :dont_fail_on_error => true

# create a release
release_notes = get_release_notes dir_repo, version

cmd = %("#{github_release_bin}" release)
cmd << %( -s #{$github_access_token})
cmd << %( -u #{$github_owner})
cmd << %( -r #{repo_name})
cmd << %( -t "#{tag}")
cmd << %( -n "#{name}")
cmd << %( -d "#{release_notes}")

exec_shell cmd, "Can't push release"

# uploading package
cmd = %("#{github_release_bin}" upload)
cmd << %( -s #{$github_access_token})
cmd << %( -u #{$github_owner})
cmd << %( -r #{repo_name})
cmd << %( -t "#{tag}")
cmd << %( -n "#{File.basename(package_zip)}")
cmd << %( -f "#{File.expand_path(package_zip)}")

exec_shell cmd, "Can't upload package asset"

end
end

############################################################

def git_get_repo_name(dir_repo)
Dir.chdir dir_repo do
file_config = '.git/config'
config = File.read file_config
return extract_regex config, %r#url = git@github\.com:.*?/(.*?).git#
end
end
38 changes: 38 additions & 0 deletions common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,42 @@ def zip_dir(path, out_file = nil)
return File.expand_path out_file
end

def get_release_notes(dir_repo, version)

header = "## v.#{version}"

file_release_notes = resolve_path "#{dir_repo}/CHANGELOG.md"

lines = File.readlines file_release_notes

start_index = -1
end_index = -1

(0 .. lines.length - 1).each do |index|
line = lines[index]
if line.include? header
start_index = index + 1
break
end
end

(start_index + 1 .. lines.length - 1).each do |index|
line = lines[index]
if line =~ /## v\.\d+\.\d+\.\d+/
end_index = index - 1
break
end
end


fail_script_unless start_index != -1 && end_index != -1, "Can't extract release notes"

notes = lines[start_index..end_index].join
notes.strip!
notes.gsub! '"', '\\"'

return notes

end

end
2 changes: 2 additions & 0 deletions credentials.rb.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$github_access_token = ''
$github_owner = ''
Binary file added tools/github/github-release
Binary file not shown.

0 comments on commit 8603a44

Please sign in to comment.