branch_raker 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/CHANGELOG.rdoc +5 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.rdoc +47 -0
- data/Rakefile +2 -0
- data/branch_raker.gemspec +24 -0
- data/lib/branch_raker/version.rb +4 -0
- data/lib/branch_raker.rb +143 -0
- metadata +104 -0
data/.gitignore
ADDED
data/CHANGELOG.rdoc
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Evan Boyd Sosenko
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= Branch Raker
|
2
|
+
|
3
|
+
<b>Use Branch Raker to maintain a build history for each branch. Originally created for LaTeX projects, but useful for anything that needs to be 'compiled'.</b>
|
4
|
+
|
5
|
+
<em>Intelligently builds the latest commit on all of your Git branches.</em>
|
6
|
+
|
7
|
+
== What is Branch Raker?
|
8
|
+
|
9
|
+
Coming soon.
|
10
|
+
|
11
|
+
== Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'branch_raker'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install branch_raker
|
24
|
+
|
25
|
+
== Using Branch Raker
|
26
|
+
|
27
|
+
Coming soon.
|
28
|
+
|
29
|
+
== Development
|
30
|
+
|
31
|
+
=== Source Repository
|
32
|
+
|
33
|
+
The {Branch Raker source}[https://github.com/razor-x/branch_raker] is currently hosted at github.
|
34
|
+
To clone the project run
|
35
|
+
|
36
|
+
$ git clone git://github.com/razor-x/branch_raker.git
|
37
|
+
|
38
|
+
== License
|
39
|
+
|
40
|
+
Branch Raker is licensed under the MIT license.
|
41
|
+
|
42
|
+
== Warranty
|
43
|
+
|
44
|
+
This software is provided "as is" and without any express or
|
45
|
+
implied warranties, including, without limitation, the implied
|
46
|
+
warranties of merchantibility and fitness for a particular
|
47
|
+
purpose.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path( '../lib/branch_raker/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Evan Boyd Sosenko']
|
6
|
+
gem.email = ['razorx@evansosenko.com']
|
7
|
+
gem.description = %q{Use Branch Raker to maintain a build history for each branch. Originally created for LaTeX projects, but useful for anything that needs to be 'compiled'.}
|
8
|
+
gem.summary = %q{Intelligently builds the latest commit on all of your Git branches.}
|
9
|
+
gem.homepage = "http://evansosenko.com"
|
10
|
+
gem.license = 'MIT'
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = 'branch_raker'
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
gem.platform = Gem::Platform::RUBY
|
18
|
+
gem.version = BranchRaker::VERSION
|
19
|
+
|
20
|
+
gem.add_dependency 'grit'
|
21
|
+
gem.add_dependency 'minitar'
|
22
|
+
gem.add_dependency 'rake'
|
23
|
+
|
24
|
+
end
|
data/lib/branch_raker.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'archive/tar/minitar'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'grit'
|
4
|
+
require 'rake'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
include Rake::DSL
|
8
|
+
|
9
|
+
module BranchRaker
|
10
|
+
|
11
|
+
# These constants may be defined before including the module.
|
12
|
+
IGNORE_BRANCHES ||= []
|
13
|
+
REPO_DIR ||= '.'
|
14
|
+
TMP_DIR ||= '/tmp'
|
15
|
+
BUILD_DIR ||= 'builds'
|
16
|
+
TMP_GROUP_DIR ||= "#{BUILD_DIR}/tmp"
|
17
|
+
|
18
|
+
# Variables accessed by several tasks.
|
19
|
+
@current = []
|
20
|
+
@stale = []
|
21
|
+
@ignore = []
|
22
|
+
|
23
|
+
REPO = Grit::Repo.new REPO_DIR
|
24
|
+
|
25
|
+
IGNORE_BRANCHES.each do |b|
|
26
|
+
head = REPO.get_head(b)
|
27
|
+
@ignore << head.commit unless head.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
class BuildError < RuntimeError
|
31
|
+
end
|
32
|
+
|
33
|
+
task :default => 'build:all'
|
34
|
+
|
35
|
+
namespace :built do
|
36
|
+
|
37
|
+
task :current do |t|
|
38
|
+
Dir.glob "#{BUILD_DIR}/*/build_info" do |f|
|
39
|
+
File.read(f).scan(/^ id: ([0-9abcdef]+)/) do |id|
|
40
|
+
@current << REPO.commit(id[0]) unless @current.map{ |c| c.id }.include?(id[0])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if t.application.top_level_tasks.include? 'built:current'
|
45
|
+
heads = REPO.heads.keep_if{ |h| ( @current.map{ |c| c.id } + @ignore.map{ |c| c.id } ).include? h.commit.id }.sort_by{ |h| h.name }
|
46
|
+
if heads.empty?
|
47
|
+
print "No branches with current builds.\n"
|
48
|
+
else
|
49
|
+
print "Listing branches with current builds:\n"
|
50
|
+
heads.each { |h| print " #{h.name}\n" }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
task :stale => :current do |t|
|
56
|
+
@stale = REPO.heads.delete_if { |h| ( @current.map{ |c| c.id } + @ignore.map{ |c| c.id } ).include? h.commit.id }.sort_by{ |h| h.name }
|
57
|
+
|
58
|
+
if t.application.top_level_tasks.include? 'built:stale'
|
59
|
+
heads = REPO.heads.keep_if{ |h| ( @stale.map{ |h| h.commit.id } ).include? h.commit.id }.sort_by{ |h| h.name }
|
60
|
+
if heads.empty?
|
61
|
+
print "No branches with stale builds.\n"
|
62
|
+
else
|
63
|
+
print "Listing branches with stale builds:\n"
|
64
|
+
heads.each { |h| print " #{h.name}\n" }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
namespace :build do
|
71
|
+
|
72
|
+
def extract_repo commit, dir
|
73
|
+
input = Archive::Tar::Minitar::Input.new StringIO.new(REPO.archive_tar commit.id)
|
74
|
+
input.each { |entry| input.extract_entry dir, entry }
|
75
|
+
end
|
76
|
+
|
77
|
+
def build_group heads
|
78
|
+
built = []
|
79
|
+
begin
|
80
|
+
FileUtils.mkdir_p TMP_GROUP_DIR
|
81
|
+
heads.each do |h|
|
82
|
+
status = build(TMP_GROUP_DIR, h.commit, h.name)
|
83
|
+
built << h.name unless status.nil?
|
84
|
+
end
|
85
|
+
FileUtils.mv TMP_GROUP_DIR, "#{BUILD_DIR}/#{Time.now.to_i} (#{built.join(' ,')})" unless built.empty?
|
86
|
+
ensure
|
87
|
+
FileUtils.rm_rf TMP_GROUP_DIR
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def build build_dir, commit, branch = nil
|
92
|
+
|
93
|
+
build_name = branch.nil? ? commit.id : branch
|
94
|
+
|
95
|
+
src = "#{TMP_DIR}/branch_raker_#{commit.id}"
|
96
|
+
out_dir = "#{build_dir}/#{build_name}"
|
97
|
+
|
98
|
+
begin
|
99
|
+
FileUtils.mkdir src
|
100
|
+
FileUtils.mkdir out_dir
|
101
|
+
extract_repo commit, src
|
102
|
+
make src, out_dir
|
103
|
+
|
104
|
+
log = branch.nil? ? '' : "Branch: #{branch}\n"
|
105
|
+
commit.to_hash.each do |k, v|
|
106
|
+
if v.is_a? Hash
|
107
|
+
log << " #{k}:\n"
|
108
|
+
v.each { |k, v| log << " #{k}: #{v}\n" }
|
109
|
+
elsif v.is_a? Array
|
110
|
+
log << " #{k}:\n"
|
111
|
+
v.each { |v| v.each { |k, v| log << " #{k}: #{v}\n" } }
|
112
|
+
else
|
113
|
+
log << " #{k}: #{v}\n"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
File.open("#{build_dir}/build_info", 'a') { |f| f.write log + "\n" }
|
117
|
+
|
118
|
+
print "Built #{build_name}."
|
119
|
+
|
120
|
+
return true
|
121
|
+
|
122
|
+
rescue BuildError => e
|
123
|
+
FileUtils.rm_rf out_dir
|
124
|
+
print "Failed to build #{branch} with error:\n#{e.message}"
|
125
|
+
return nil
|
126
|
+
ensure
|
127
|
+
FileUtils.rm_rf src
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
task :all => 'built:stale' do
|
132
|
+
build_group @stale unless @stale.empty?
|
133
|
+
end
|
134
|
+
|
135
|
+
task :branch, [:branch] => ['built:update'] do |t, args|
|
136
|
+
args.with_defaults :branch => nil
|
137
|
+
head = args[:branch].nil? ? Grit::Head.current(REPO) : REPO.get_head(args[:branch])
|
138
|
+
unless @current.map{ |c| c.id }.include?(head.commit.id)
|
139
|
+
build head.commit, head.name, "#{Time.now.to_i} (#{head.name})"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: branch_raker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Evan Boyd Sosenko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: grit
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: minitar
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Use Branch Raker to maintain a build history for each branch. Originally
|
63
|
+
created for LaTeX projects, but useful for anything that needs to be 'compiled'.
|
64
|
+
email:
|
65
|
+
- razorx@evansosenko.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- CHANGELOG.rdoc
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.rdoc
|
75
|
+
- Rakefile
|
76
|
+
- branch_raker.gemspec
|
77
|
+
- lib/branch_raker.rb
|
78
|
+
- lib/branch_raker/version.rb
|
79
|
+
homepage: http://evansosenko.com
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.8.23
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Intelligently builds the latest commit on all of your Git branches.
|
104
|
+
test_files: []
|