heirloom 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ ## v0.3.1:
2
+
3
+ * Switched from Minitar to shell
4
+ * Removed Minitar gem
5
+ * Fixed git commit flag
6
+ * Updated specs
7
+ * Updated gems
8
+
1
9
  ## v0.3.0:
2
10
 
3
11
  * Move account authorization out of config to cli
@@ -24,6 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_runtime_dependency 'fog'
25
25
  s.add_runtime_dependency 'grit'
26
26
  s.add_runtime_dependency 'logger'
27
- s.add_runtime_dependency 'minitar'
28
27
  s.add_runtime_dependency 'trollop'
29
28
  end
@@ -22,7 +22,7 @@ module Heirloom
22
22
  :exclude => args[:exclude],
23
23
  :config => config
24
24
 
25
- directory.build_artifact_from_directory
25
+ return false unless directory.build_artifact_from_directory
26
26
 
27
27
  self.local_build = directory.local_build
28
28
 
@@ -43,8 +43,13 @@ module Heirloom
43
43
  private
44
44
 
45
45
  def add_git_commit
46
- git_commit = GitDirectory.new(:path => source).commit
47
- add_git_commit_to_artifact_record git_commit
46
+ git = GitDirectory.new(:path => source)
47
+ commit = git.commit id
48
+ if commit
49
+ add_git_commit_to_artifact_record commit
50
+ else
51
+ logger.warn "Could not find Git sha: #{id}."
52
+ end
48
53
  end
49
54
 
50
55
  def add_git_commit_to_artifact_record(commit)
@@ -26,17 +26,21 @@ module Heirloom
26
26
 
27
27
  @archive.destroy if @archive.exists?
28
28
 
29
- archive_file = @archive.build :bucket_prefix => @opts[:bucket_prefix],
30
- :directory => @opts[:directory],
31
- :exclude => @opts[:exclude].split(','),
32
- :git => @opts[:git]
29
+ build = @archive.build :bucket_prefix => @opts[:bucket_prefix],
30
+ :directory => @opts[:directory],
31
+ :exclude => @opts[:exclude].split(','),
32
+ :git => @opts[:git]
33
33
 
34
- @archive.upload :bucket_prefix => @opts[:bucket_prefix],
35
- :regions => @opts[:regions],
36
- :public_readable => @opts[:public],
37
- :file => archive_file
38
-
39
- @archive.cleanup
34
+ if build
35
+ @archive.upload :bucket_prefix => @opts[:bucket_prefix],
36
+ :regions => @opts[:regions],
37
+ :public_readable => @opts[:public],
38
+ :file => build
39
+ @archive.cleanup
40
+ else
41
+ @logger.error "Build failed."
42
+ exit 1
43
+ end
40
44
  end
41
45
 
42
46
  private
@@ -1,9 +1,5 @@
1
- require 'zlib'
2
- require 'archive/tar/minitar'
3
1
  require 'tmpdir'
4
2
 
5
- include Archive::Tar
6
-
7
3
  module Heirloom
8
4
 
9
5
  class Directory
@@ -18,7 +14,7 @@ module Heirloom
18
14
  end
19
15
 
20
16
  def build_artifact_from_directory
21
- random_text = (0...8).map{65.+(rand(25)).chr}.join
17
+ random_text = (0...8).map{65.+(Kernel.rand(25)).chr}.join
22
18
 
23
19
  unless local_build
24
20
  self.local_build = File.join(Dir.tmpdir, random_text + ".tar.gz")
@@ -28,12 +24,18 @@ module Heirloom
28
24
  logger.info "Excluding #{exclude.to_s}."
29
25
  logger.info "Adding #{files_to_pack.to_s}."
30
26
 
31
- tgz = Zlib::GzipWriter.new File.open(local_build, 'wb')
32
-
33
- Minitar.pack(files_to_pack, tgz)
27
+ build_archive local_build, files_to_pack
34
28
  end
35
29
 
36
30
  private
31
+
32
+ def build_archive(local_build, files_to_pack)
33
+ command = "tar czf #{local_build} #{files_to_pack.join(' ')}"
34
+ logger.info "Archiving with: `#{command}`"
35
+ output = `#{command}`
36
+ logger.debug "Exited with status: '#{$?.exitstatus}' ouput: '#{output}'"
37
+ $?.success?
38
+ end
37
39
 
38
40
  def files_to_pack
39
41
  Dir.entries(path) - ['.', '..'] - exclude
@@ -6,15 +6,18 @@ module Heirloom
6
6
 
7
7
  class GitDirectory
8
8
 
9
- attr_accessor :path
10
-
11
9
  def initialize(args)
12
- self.path = args[:path]
10
+ @path = args[:path]
13
11
  end
14
12
 
15
13
  def commit(sha = nil)
16
- repo = Repo.new path
17
- sha ? repo.commits(sha).first : repo.commits.first
14
+ repo = Repo.new @path
15
+ if sha
16
+ commit = repo.commits(sha)
17
+ commit ? commit.first : false
18
+ else
19
+ repo.commits.first
20
+ end
18
21
  end
19
22
 
20
23
  end
@@ -1,3 +1,3 @@
1
1
  module Heirloom
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -4,36 +4,81 @@ describe Heirloom do
4
4
 
5
5
  before do
6
6
  @config_mock = double 'config'
7
- @logger_mock = double 'logger'
7
+ @logger_stub = stub :debug => 'true', :info => 'true', :warn => 'true'
8
8
  @simpledb_mock = double 'simple db'
9
- @config_mock.should_receive(:logger).and_return(@logger_mock)
9
+ @config_mock.should_receive(:logger).and_return(@logger_stub)
10
10
  Heirloom::AWS::SimpleDB.should_receive(:new).with(:config => @config_mock).
11
11
  and_return(@simpledb_mock)
12
12
  @simpledb_mock.should_receive(:create_domain).with 'tim'
13
13
  @builder = Heirloom::Builder.new :config => @config_mock,
14
- :name => 'tim',
15
- :id => '123'
14
+ :name => 'tim',
15
+ :id => '123'
16
16
  end
17
17
 
18
18
  it "should build an archive" do
19
- directory_mock = double "directory"
19
+ directory_stub = stub :build_artifact_from_directory => '/tmp/build_dir',
20
+ :local_build => '/var/tmp/file.tar.gz'
21
+ git_dir_mock = double "git directory mock"
22
+ author_stub = stub :name => 'weaver'
23
+ git_commit_stub = stub :id_abbrev => 'abc123',
24
+ :message => 'yoyo',
25
+ :author => author_stub
20
26
  Heirloom::Directory.should_receive(:new).with(:path => 'path_to_build',
21
27
  :exclude => ['.dir_to_exclude'],
22
28
  :config => @config_mock).
23
- and_return(directory_mock)
24
- directory_mock.should_receive :build_artifact_from_directory
25
- directory_mock.should_receive(:local_build).and_return('/tmp/file')
29
+ and_return directory_stub
26
30
  @builder.should_receive(:create_artifact_record)
27
- @builder.should_receive(:add_git_commit)
28
- @logger_mock.should_receive(:info).with("Build complete.")
31
+ Heirloom::GitDirectory.should_receive(:new).
32
+ with(:path => 'path_to_build').
33
+ and_return git_dir_mock
34
+ git_dir_mock.should_receive(:commit).
35
+ with('123').and_return git_commit_stub
36
+ commit_attributes = { 'sha' => '123',
37
+ 'abbreviated_sha' => 'abc123',
38
+ 'message' => 'yoyo',
39
+ 'author' => 'weaver' }
40
+ @simpledb_mock.should_receive(:put_attributes).
41
+ with('tim', '123', commit_attributes)
42
+
43
+ @builder.build(:exclude => ['.dir_to_exclude'],
44
+ :directory => 'path_to_build',
45
+ :git => 'true').should == '/var/tmp/file.tar.gz'
46
+ end
47
+
48
+ it "should build an archive and log a warning if the git sha is not found" do
49
+ directory_stub = stub :build_artifact_from_directory => '/tmp/build_dir',
50
+ :local_build => '/var/tmp/file.tar.gz'
51
+ git_dir_mock = double "git directory mock"
52
+ Heirloom::Directory.should_receive(:new).with(:path => 'path_to_build',
53
+ :exclude => ['.dir_to_exclude'],
54
+ :config => @config_mock).
55
+ and_return directory_stub
56
+ @builder.should_receive(:create_artifact_record)
57
+ Heirloom::GitDirectory.should_receive(:new).
58
+ with(:path => 'path_to_build').
59
+ and_return git_dir_mock
60
+ @logger_stub.should_receive(:warn).with "Could not find Git sha: 123."
61
+ git_dir_mock.should_receive(:commit).
62
+ with('123').and_return false
63
+ @builder.build(:exclude => ['.dir_to_exclude'],
64
+ :directory => 'path_to_build',
65
+ :git => 'true').should == '/var/tmp/file.tar.gz'
66
+ end
67
+
68
+
69
+ it "should return false if the build fails" do
70
+ directory_stub = stub :build_artifact_from_directory => false
71
+ Heirloom::Directory.should_receive(:new).with(:path => 'path_to_build',
72
+ :exclude => ['.dir_to_exclude'],
73
+ :config => @config_mock).
74
+ and_return directory_stub
29
75
  @builder.build(:exclude => ['.dir_to_exclude'],
30
76
  :directory => 'path_to_build',
31
- :git => 'true').should == '/tmp/file'
77
+ :git => 'true').should be_false
32
78
  end
33
79
 
34
80
  it "should cleanup the local archive" do
35
81
  @builder.local_build = '/tmp/file'
36
- @logger_mock.should_receive(:info).with("Cleaning up local build /tmp/file.")
37
82
  File.should_receive(:delete).with('/tmp/file')
38
83
  @builder.cleanup
39
84
  end
@@ -4,23 +4,41 @@ describe Heirloom do
4
4
 
5
5
  before do
6
6
  @config_mock = double 'config'
7
- @logger_mock = double 'logger'
8
- @config_mock.should_receive(:logger).and_return(@logger_mock)
7
+ @logger_stub = stub :debug => 'true', :info => 'true', :warn => 'true'
8
+ @config_mock.should_receive(:logger).and_return(@logger_stub)
9
9
  @directory = Heirloom::Directory.new :config => @config_mock,
10
- :exclude => ['.', '..', 'pack_me'],
10
+ :exclude => ['.', '..', 'dont_pack_me'],
11
11
  :path => '/target/dir'
12
12
  end
13
13
 
14
14
  it "should build an archive from the latest commit in path" do
15
- @logger_mock.should_receive(:info).exactly(3).times
16
15
  file_mock = double 'file'
17
- File.should_receive(:open).and_return file_mock
18
- gzip_mock = double 'gzip mock'
19
- Zlib::GzipWriter.should_receive(:new).and_return gzip_mock
20
- @directory.should_receive(:files_to_pack).
21
- exactly(2).times.and_return(['pack_me'])
22
- Minitar.should_receive(:pack).with(['pack_me'], gzip_mock)
23
- @directory.build_artifact_from_directory
16
+ output_mock = double 'output mock'
17
+ Dir.stub :tmpdir => '/tmp/dir'
18
+ Kernel.stub :rand => 0
19
+ Dir.should_receive(:entries).with('/target/dir').
20
+ exactly(2).times.
21
+ and_return(['pack_me', '.hidden', 'dont_pack_me'])
22
+ Heirloom::Directory.any_instance.should_receive(:`).
23
+ with("tar czf /tmp/dir/AAAAAAAA.tar.gz pack_me .hidden").
24
+ and_return output_mock
25
+ $?.should_receive(:success?).and_return true
26
+ @directory.build_artifact_from_directory.should be_true
27
+ end
28
+
29
+ it "should return false if the shell is not succesful" do
30
+ file_mock = double 'file'
31
+ output_mock = double 'output mock'
32
+ Dir.stub :tmpdir => '/tmp/dir'
33
+ Kernel.stub :rand => 0
34
+ Dir.should_receive(:entries).with('/target/dir').
35
+ exactly(2).times.
36
+ and_return(['pack_me', '.hidden', 'dont_pack_me'])
37
+ Heirloom::Directory.any_instance.should_receive(:`).
38
+ with("tar czf /tmp/dir/AAAAAAAA.tar.gz pack_me .hidden").
39
+ and_return output_mock
40
+ $?.should_receive(:success?).and_return false
41
+ @directory.build_artifact_from_directory.should be_false
24
42
  end
25
43
 
26
44
  end
@@ -2,27 +2,31 @@ require 'spec_helper'
2
2
 
3
3
  describe Heirloom do
4
4
 
5
- before do
6
- @git_directory = Heirloom::GitDirectory.new :path => '/target/dir'
7
- end
5
+ before do
6
+ @repo_mock = double 'repo mock'
7
+ @git_directory = Heirloom::GitDirectory.new :path => '/target/dir'
8
+ Repo.should_receive(:new).with('/target/dir').and_return(@repo_mock)
9
+ @commits_mock = double 'commits mock'
10
+ end
8
11
 
9
- it "should read commit from the given path" do
10
- repo_mock = double 'repo mock'
11
- Repo.should_receive(:new).with('/target/dir').and_return(repo_mock)
12
- commits_mock = double 'commits mock'
13
- repo_mock.should_receive(:commits).and_return(commits_mock)
14
- commits_mock.should_receive(:first).and_return('git_sha')
15
- @git_directory.commit.should == 'git_sha'
16
- end
12
+ it "should read commit from the given path" do
13
+ @repo_mock.should_receive(:commits).and_return(@commits_mock)
14
+ @commits_mock.should_receive(:first).and_return('git_sha')
15
+ @git_directory.commit.should == 'git_sha'
16
+ end
17
17
 
18
- it "should read commit from the given path" do
19
- repo_mock = double 'repo mock'
20
- Repo.should_receive(:new).with('/target/dir').and_return(repo_mock)
21
- commits_mock = double 'commits mock'
22
- repo_mock.should_receive(:commits).with('sha_i_want').
23
- and_return(commits_mock)
24
- commits_mock.should_receive(:first).and_return('git_sha')
25
- @git_directory.commit 'sha_i_want'
26
- end
18
+ it "should read commit from the given path" do
19
+ @repo_mock.should_receive(:commits).with('sha_i_want').
20
+ and_return(@commits_mock)
21
+ @commits_mock.should_receive(:first).and_return('git_sha')
22
+ @git_directory.commit('sha_i_want').should == 'git_sha'
23
+ end
24
+
25
+ it "should return false if the commit given does not exist" do
26
+ @repo_mock.should_receive(:commits).with('sha_that_dont_exist').
27
+ and_return(@commits_mock)
28
+ @commits_mock.should_receive(:first).and_return nil
29
+ @git_directory.commit('sha_that_dont_exist').should be_false
30
+ end
27
31
 
28
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heirloom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-30 00:00:00.000000000 Z
12
+ date: 2012-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70366950210620 !ruby/object:Gem::Requirement
16
+ requirement: &70227657292060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70366950210620
24
+ version_requirements: *70227657292060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fog
27
- requirement: &70366950210120 !ruby/object:Gem::Requirement
27
+ requirement: &70227657291640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70366950210120
35
+ version_requirements: *70227657291640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: grit
38
- requirement: &70366950209660 !ruby/object:Gem::Requirement
38
+ requirement: &70227657290960 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70366950209660
46
+ version_requirements: *70227657290960
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: logger
49
- requirement: &70366950209200 !ruby/object:Gem::Requirement
49
+ requirement: &70227657290280 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,21 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70366950209200
58
- - !ruby/object:Gem::Dependency
59
- name: minitar
60
- requirement: &70366950208780 !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
66
- type: :runtime
67
- prerelease: false
68
- version_requirements: *70366950208780
57
+ version_requirements: *70227657290280
69
58
  - !ruby/object:Gem::Dependency
70
59
  name: trollop
71
- requirement: &70366950208340 !ruby/object:Gem::Requirement
60
+ requirement: &70227657289580 !ruby/object:Gem::Requirement
72
61
  none: false
73
62
  requirements:
74
63
  - - ! '>='
@@ -76,7 +65,7 @@ dependencies:
76
65
  version: '0'
77
66
  type: :runtime
78
67
  prerelease: false
79
- version_requirements: *70366950208340
68
+ version_requirements: *70227657289580
80
69
  description: I help build and manage building tar.gz files and deploying them into
81
70
  the cloud
82
71
  email:
@@ -168,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
157
  version: '0'
169
158
  segments:
170
159
  - 0
171
- hash: 2580747408097791260
160
+ hash: -4029449288318118169
172
161
  required_rubygems_version: !ruby/object:Gem::Requirement
173
162
  none: false
174
163
  requirements:
@@ -177,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
166
  version: '0'
178
167
  segments:
179
168
  - 0
180
- hash: 2580747408097791260
169
+ hash: -4029449288318118169
181
170
  requirements: []
182
171
  rubyforge_project: heirloom
183
172
  rubygems_version: 1.8.16