Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 4e16430

Browse files
committed
add tasks for gem management
1 parent 1a1b2a6 commit 4e16430

File tree

4 files changed

+186
-0
lines changed

4 files changed

+186
-0
lines changed

Rakefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require './tasks/gems'
2+
require './tasks/git'
3+
require './tasks/version'
4+
5+
HYPERLOOP_REPOS =%w[hyper-component hyper-mesh hyper-model hyper-operation hyper-react
6+
hyper-router hyper-spec hyper-store hyperloop hyperloop-config]
7+
8+
task :default do
9+
# show usage
10+
end
11+

tasks/gems.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace :hyperloop do
2+
namespace :gems do
3+
desc "build all hyperloop gems"
4+
task :build do
5+
HYPERLOOP_REPOS.each do |repo|
6+
Dir.chdir(File.join('..', repo)) do
7+
puts "\033[0;32mBuilding gem for #{repo}:\033[0;30m"
8+
`gem build #{branch}`
9+
end
10+
end
11+
end
12+
13+
desc "upload all hyperloop gems to the inabox gem server, accepts host as argument"
14+
task :inabox, [:host] do |_, arg|
15+
host = arg[:host]
16+
HYPERLOOP_REPOS.each do |repo|
17+
Dir.chdir(File.join('..', repo)) do
18+
best_time = Time.new(1970, 1, 1)
19+
last_created_gem_fst = Dir.glob('*.gem').reduce([best_time, '']) do |gem_fst, gem|
20+
mtime = File.stat(gem).mtime
21+
mtime > gem_fst[0] ? [mtime, gem] : gem_fst
22+
end
23+
if host
24+
`gem inabox -g #{host} #{last_created_gem_fst[1]}`
25+
else
26+
`gem inabox #{last_created_gem_fst[1]}`
27+
end
28+
end
29+
end
30+
end
31+
end
32+
end

tasks/git.rb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
namespace :hyperloop do
2+
namespace :git do
3+
desc "create new branch in local hyperloop repos, requires branch name as argument"
4+
task :create_branch, [:branch_name] do |_, arg|
5+
branch = arg[:branch_name]
6+
if branch.nil?
7+
puts "please use: rake hyperloop:git:create_branch[your_branch_name]"
8+
return
9+
end
10+
HYPERLOOP_REPOS.each do |repo|
11+
Dir.chdir(File.join('..', repo)) do
12+
puts "\033[0;32mCreating new branch for #{repo}:\033[0;30m\t#{`git branch #{branch}`}"
13+
end
14+
end
15+
end
16+
17+
desc "checkout branch in local hyperloop repos, requires branch name as argument"
18+
task :co_branch, [:branch_name] do |_, arg|
19+
branch = arg[:branch_name]
20+
if branch.nil?
21+
puts "please use: rake hyperloop:git:co_branch[your_branch_name]"
22+
return
23+
end
24+
HYPERLOOP_REPOS.each do |repo|
25+
Dir.chdir(File.join('..', repo)) do
26+
puts "\033[0;32mChecking out branch for #{repo}:\033[0;30m\t#{`git checkout #{branch}`}"
27+
end
28+
end
29+
end
30+
31+
desc "show current branch in local hyperloop repos"
32+
task :show_branch do
33+
HYPERLOOP_REPOS.each do |repo|
34+
Dir.chdir(File.join('..', repo)) do
35+
puts "\033[0;32mCurrent branch of #{repo}:\033[0;30m\t#{`git rev-parse --abbrev-ref HEAD`}"
36+
end
37+
end
38+
end
39+
40+
desc "commit all changes in all repos in their current branches, requires commit_message"
41+
task :commit, [:commit_message] do |_, arg|
42+
message = arg[:commit_message]
43+
if message.nil?
44+
puts "please use: rake hyperloop:git:commit[your_commit_message]"
45+
return
46+
end
47+
HYPERLOOP_REPOS.each do |repo|
48+
Dir.chdir(File.join('..', repo)) do
49+
puts "\033[0;32mCreating new branch for #{repo}:\033[0;30m\t#{`git commit -am "#{message}"`}"
50+
end
51+
end
52+
end
53+
54+
desc "push all local hyperloop repos, accepts remote as argument, default origin"
55+
task :push do
56+
end
57+
58+
desc "show git status for local hyperloop repos"
59+
task :status do
60+
HYPERLOOP_REPOS.each do |repo|
61+
Dir.chdir(File.join('..', repo)) do
62+
puts "\033[0;32mStatus for #{repo}:\033[0;30m"
63+
puts
64+
puts `git status`
65+
puts
66+
puts
67+
end
68+
end
69+
end
70+
end
71+
end

tasks/version.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
namespace :hyperloop do
2+
namespace :version do
3+
4+
def file_version_for(repo)
5+
case repo
6+
when 'hyper-component' then ['./lib/hyperloop/component/version', 'Hyperloop::Component::VERSION']
7+
when 'hyper-mesh' then ['./lib/hypermesh/version', 'Hypermesh::VERSION']
8+
when 'hyper-model' then ['./lib/hyperloop/model/version', 'Hyperloop::Model::VERSION']
9+
when 'hyper-operation' then ['./lib/hyper-operation/version', 'Hyperloop::Operation::VERSION']
10+
when 'hyper-react' then ['./lib/reactive-ruby/version', 'React::VERSION']
11+
when 'hyper-router' then ['./lib/hyper-router/version', 'HyperRouter::VERSION']
12+
when 'hyper-spec' then ['./lib/hyper-spec/version', 'HyperSpec::VERSION']
13+
when 'hyper-store' then ['./lib/hyper-store/version', 'HyperStore::VERSION']
14+
when 'hyperloop' then ['./lib/hyperloop/version', 'Hyperloop::VERSION']
15+
when 'hyperloop-config' then ['../hyperloop/lib/hyperloop/version', 'Hyperloop::VERSION']
16+
end
17+
end
18+
19+
def set_version(repo, version)
20+
fv_arr = file_version_for(repo)
21+
out = ''
22+
File.open(fv_arr[0] + '.rb', 'rt+') do |f|
23+
f.each_line do |line|
24+
if /VERSION/.match?(line)
25+
out << line.sub(/VERSION = ['"][\w.-]+['"]/, "VERSION = '#{version}'" )
26+
else
27+
out << line
28+
end
29+
end
30+
f.truncate(0)
31+
f.pos = 0
32+
f.write(out)
33+
end
34+
end
35+
36+
desc "set gems version to, requires gem version and hyper-router gem version as arguments"
37+
task :set, [:version, :hrversion] do |_, arg|
38+
version = arg[:version]
39+
hrversion = arg[:hrversion]
40+
if version.nil? || hrversion.nil?
41+
puts "please use: rake hyperloop:version:set[the_new_gem_version,the_new_hyper_router_version]"
42+
return
43+
end
44+
HYPERLOOP_REPOS.each do |repo|
45+
Dir.chdir(File.join('..', repo)) do
46+
if repo == 'hyper-router'
47+
set_version(repo, hrversion)
48+
sv = hrversion
49+
elsif repo == 'hyperloop-config'
50+
# nothing
51+
sv = version
52+
else
53+
set_version(repo, version)
54+
sv = version
55+
end
56+
puts "\033[0;32ms#{repo} now at:\033[0;30m\t#{sv}"
57+
end
58+
end
59+
end
60+
61+
desc "show current gem versions"
62+
task :show do
63+
HYPERLOOP_REPOS.each do |repo|
64+
Dir.chdir(File.join('..', repo)) do
65+
fv_arr = file_version_for(repo)
66+
require fv_arr[0]
67+
puts "\033[0;32m#{repo}:\033[0;30m\t#{Object.const_get(fv_arr[1])}"
68+
end
69+
end
70+
end
71+
end
72+
end

0 commit comments

Comments
 (0)