travis_bundle_cache 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae4a071831d3e9f5a65da82641068289a54d081a
4
- data.tar.gz: 21aa7726e58acc03270027e9f8c29d8ba0460a39
3
+ metadata.gz: 9823ea826bf7435fac84b37130e2bf5a2f4d918e
4
+ data.tar.gz: 0d3d8c0ac9d1993a046ae5121da984de30f1659a
5
5
  SHA512:
6
- metadata.gz: b5ea24f3d147d636595ca603f99437c9e18d8db395c4221f2055c50867d64bbf7b5bae3c409508eb9c36d7473d7ae8eeef6407bda0bacaa5335010d2d76e854f
7
- data.tar.gz: ff9639729f79513d780d215f46e78ee20ddfad46e5465a6d5c662fbb40d00eb2443dec9075ed99aa045d81e86e84493755ed34f19c525009d4a4c7ff6116ffdd
6
+ metadata.gz: 9664aad420c15f9175d93ea2807881bb14b333dc64154dda8ad49cf6b6258bbbb5f98179ad7557fb9e468ad91bc9aa614e83e71d72da13954575d05a6da5a1bb
7
+ data.tar.gz: 49539468671d40cc88ea6fa8b838614abfd73abd2c1dd5a332ea6b2dfe768a0d82f4d5601115f47e2ecd6f3fc46c91152d4221c037732875c24774cbdc04c034
checksums.yaml.gz.sig ADDED
@@ -0,0 +1 @@
1
+ ���EL�ّC@-�$�|�=�����L��@0�Z E�Œ_I!�#�C��ub�'"խ��փC�*��T�(��q�vӢ�䓖�9A�)���1a�Z����o�����#�uy�sQ��eR{4�B810u��Z��ds9g|S����~؉/9��Pf���l
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ before_install:
6
+ - "mkdir ~/.gemcert && cd ~/.gemcert && gem cert --build test@example.com && cp gem-public_cert.pem $TRAVIS_BUILD_DIR/"
7
+ - "cd $TRAVIS_BUILD_DIR"
8
+ install: bundle install
9
+ script: rspec
data/Gemfile CHANGED
@@ -4,3 +4,9 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'rake'
7
+
8
+ group :test do
9
+ gem "coveralls", "~> 0.6.7", require: false
10
+ gem "rspec", "~> 2.14"
11
+ gem "fakefs", require: "fakefs/safe"
12
+ end
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  Travis Bundle Cache
2
2
  ===================
3
3
  [![Gem Version](https://badge.fury.io/rb/travis_bundle_cache.png)](http://badge.fury.io/rb/travis_bundle_cache)
4
+ [![Build Status](https://travis-ci.org/collectiveidea/travis_bundle_cache.png?branch=master)](https://travis-ci.org/collectiveidea/travis_bundle_cache)
4
5
  [![Code Climate](https://codeclimate.com/github/collectiveidea/travis_bundle_cache.png)](https://codeclimate.com/github/collectiveidea/travis_bundle_cache)
6
+ [![Coverage Status](https://coveralls.io/repos/collectiveidea/travis_bundle_cache/badge.png?branch=master)](https://coveralls.io/r/collectiveidea/travis_bundle_cache?branch=master)
5
7
  [![Dependency Status](https://gemnasium.com/collectiveidea/travis_bundle_cache.png)](https://gemnasium.com/collectiveidea/travis_bundle_cache)
6
8
 
7
9
  The primary purpose of this gem is to make [this](http://randomerrata.com/post/45827813818/travis-s3) easier and slightly more maintainable.
@@ -29,7 +31,13 @@ Usage
29
31
 
30
32
  before_install:
31
33
  - 'echo ''gem: --no-ri --no-rdoc'' > ~/.gemrc'
32
- - gem install travis_bundle_cache
34
+ # Better security (If only we could get Amazon to sign their gem)
35
+ - wget https://raw.github.com/collectiveidea/travis_bundle_cache/4753620b8f2bcfd0c5af85ccd68888c1f593a023/gem-public_cert.pem
36
+ - gem cert --add gem-public_cert.pem
37
+ - gem install aws-sdk
38
+ - gem install travis_bundle_cache -P HighSecurity
39
+ # Low security option
40
+ # - gem install travis_bundle_cache
33
41
 
34
42
  install: travis_bundle_install
35
43
 
@@ -0,0 +1,21 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDijCCAnKgAwIBAgIBATANBgkqhkiG9w0BAQUFADBFMQ4wD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obmZRTI0Vn54e2ofKnWZtylW0SYa9uQplEJK/Ttu88DL99WgwOyNdMlqg
19
+ FJkL4MD3SK4X13qDUlr6YzTkvc8MMfaECuzUIM6KqSGQnyZ16D2zLdZTtr0GPzJZ
20
+ SdQ0gsTaFvafp6C7hh//UHFI92FnVtzpV01oGPDikn3a2qc8eUPvULa2NlJRFQ==
21
+ -----END CERTIFICATE-----
@@ -16,7 +16,7 @@ module TravisBundleCache
16
16
  def install
17
17
  run_command %(cd ~ && wget -O "remote_#{@file_name}" "#{storage[@file_name].url_for(:read)}" && tar -xf "remote_#{@file_name}")
18
18
  run_command %(cd ~ && wget -O "remote_#{@file_name}.sha2" "#{storage[@digest_filename].url_for(:read)}")
19
- run_command %(bundle install --without #{ENV['BUNDLE_WITHOUT'] || "development production"} --path=~/.bundle)
19
+ run_command %(bundle install --without #{ENV['BUNDLE_WITHOUT'] || "development production"} --path=~/.bundle), retry: true
20
20
  end
21
21
 
22
22
  def cache_bundle
@@ -48,7 +48,7 @@ module TravisBundleCache
48
48
  end
49
49
 
50
50
  puts "=> Preparing bundle archive"
51
- `cd ~ && tar -cjf "#{@file_name}" .bundle`
51
+ run_command %(cd ~ && tar -cjf "#{@file_name}" .bundle), exit_on_error: true
52
52
 
53
53
  puts "=> Uploading the bundle"
54
54
  storage[@file_name].write(Pathname.new(@file_path), :reduced_redundancy => true)
@@ -61,12 +61,26 @@ module TravisBundleCache
61
61
 
62
62
  protected
63
63
 
64
- def run_command(cmd)
64
+ def run_command(cmd, opts = {})
65
+ tries = 1
65
66
  puts "Running: #{cmd}"
66
- IO.popen(cmd) do |f|
67
- begin
68
- print f.readchar while true
69
- rescue EOFError
67
+ while true
68
+ IO.popen(cmd) do |f|
69
+ begin
70
+ print f.readchar while true
71
+ rescue EOFError
72
+ end
73
+ end
74
+
75
+ if $?.exitstatus == 0
76
+ break
77
+ elsif opts[:retry] && tries < 3
78
+ tries += 1
79
+ puts "Retrying attempt #{tries} of 3"
80
+ elsif opts[:exit_on_error] || opts[:retry]
81
+ exit($?.exitstatus)
82
+ else
83
+ break
70
84
  end
71
85
  end
72
86
  end
@@ -1,3 +1,3 @@
1
1
  module TravisBundleCache
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,12 @@
1
+ require "coveralls"
2
+ Coveralls.wear!
3
+
4
+ require "travis_bundle_cache"
5
+
6
+ require "fakefs/spec_helpers"
7
+
8
+ RSpec.configure do |config|
9
+ config.order = "random"
10
+ config.expect_with(:rspec) {|c| c.syntax = :expect }
11
+ config.include FakeFS::SpecHelpers
12
+ end
@@ -0,0 +1,127 @@
1
+ require "spec_helper"
2
+
3
+ describe TravisBundleCache::Cache do
4
+ before(:each) do
5
+ ENV["TRAVIS_REPO_SLUG"] = "owner/repo"
6
+ ENV["TRAVIS_BUILD_DIR"] = "/home/travis/owner/repo"
7
+ ENV["AWS_S3_KEY"] = "AN_ACCESS_KEY_ID"
8
+ ENV["AWS_S3_SECRET"] = "AN_SECRET_ACCESS_KEY"
9
+ ENV["AWS_S3_BUCKET"] = "a-bucket-name"
10
+
11
+ @uname = `uname -m`.strip
12
+ @cache = TravisBundleCache::Cache.new
13
+ end
14
+
15
+ describe 'install' do
16
+ before(:each) do
17
+ @cache.stub(:run_command)
18
+ end
19
+
20
+ it 'tries to download an available bundle archive' do
21
+ expect(@cache).to receive(:run_command).once.with(/\Acd ~ && wget -O "remote_owner-repo-#{@uname}\.tgz" "https:\/\/a-bucket-name\.s3\.amazonaws\.com\/owner-repo-#{@uname}.tgz\?AWSAccessKeyId=AN_ACCESS_KEY_ID&Expires=[0-9]+&Signature=[^"]+" && tar -xf "remote_owner-repo-#{@uname}\.tgz"\Z/)
22
+
23
+ @cache.install
24
+ end
25
+
26
+ it 'tries to download an available bundle archive signature' do
27
+ expect(@cache).to receive(:run_command).once.with(/\Acd ~ && wget -O "remote_owner-repo-#{@uname}\.tgz.sha2" "https:\/\/a-bucket-name\.s3\.amazonaws\.com\/owner-repo-#{@uname}.tgz.sha2\?AWSAccessKeyId=AN_ACCESS_KEY_ID&Expires=[0-9]+&Signature=[^"]+"\Z/)
28
+
29
+ @cache.install
30
+ end
31
+
32
+ it 'installs the bundle' do
33
+ expect(@cache).to receive(:run_command).once.with("bundle install --without development production --path=~\/.bundle", retry: true)
34
+
35
+ @cache.install
36
+ end
37
+ end
38
+
39
+ describe 'cache_bundle' do
40
+ before(:each) do
41
+ ENV['TRAVIS_PULL_REQUEST'] = 'false'
42
+ ENV['TRAVIS_BRANCH'] = 'master'
43
+
44
+ @cache.stub(:puts)
45
+ @cache.stub(:run_command)
46
+ AWS::S3::S3Object.any_instance.stub(:write)
47
+
48
+ FileUtils.mkdir_p(ENV["TRAVIS_BUILD_DIR"])
49
+ File.open(File.join(ENV["TRAVIS_BUILD_DIR"], 'Gemfile.lock'), 'w') {|f| f.puts "Some lock contents" }
50
+ end
51
+
52
+ it 'builds a new archive if one does not already exist' do
53
+ expect(@cache).to receive(:archive_and_upload_bundle).once.with(no_args)
54
+
55
+ @cache.cache_bundle
56
+ end
57
+
58
+ it 'builds a new archive if the sha has changed' do
59
+ FileUtils.mkdir_p("~/")
60
+ File.open(File.expand_path("~/remote_owner-repo-#{@uname}.tgz.sha2"), 'w') {|f| f.print "old sha hash" }
61
+ expect(@cache).to receive(:archive_and_upload_bundle).once.with(no_args)
62
+
63
+ @cache.cache_bundle
64
+ end
65
+
66
+ it 'does not build a new archive if the sha matches' do
67
+ FileUtils.mkdir_p("~/")
68
+ File.open(File.expand_path("~/remote_owner-repo-#{@uname}.tgz.sha2"), 'w') {|f| f.print "be7b966bd555fffd27c11f2557484501ad2ed482f1b6164457433800e163ae29" }
69
+ expect(@cache).to receive(:archive_and_upload_bundle).never
70
+ expect(@cache).to receive(:puts).with("=> There were no changes, doing nothing")
71
+
72
+ @cache.cache_bundle
73
+ end
74
+
75
+ it 'does not build a new archive for pull requests' do
76
+ ENV['TRAVIS_PULL_REQUEST'] = '1'
77
+ expect(@cache).to receive(:archive_and_upload_bundle).never
78
+ expect(@cache).to receive(:puts).with("=> This is a pull request, doing nothing")
79
+
80
+ @cache.cache_bundle
81
+ end
82
+
83
+ it 'does not build a new archive for a non master brnach' do
84
+ ENV['TRAVIS_BRANCH'] = 'not-master'
85
+ expect(@cache).to receive(:archive_and_upload_bundle).never
86
+ expect(@cache).to receive(:puts).with("=> This is not the master branch, doing nothing")
87
+
88
+ @cache.cache_bundle
89
+ end
90
+ end
91
+
92
+ describe 'archive_and_upload_bundle' do
93
+ before(:each) do
94
+ @cache.stub(:puts)
95
+ @cache.stub(:run_command)
96
+ AWS::S3::S3Object.any_instance.stub(:write)
97
+
98
+ @cache.instance_variable_set(:@bundle_digest, 'be7b966bd555fffd27c11f2557484501ad2ed482f1b6164457433800e163ae29')
99
+ end
100
+
101
+ it 'runs bundle clean if there was an old archive' do
102
+ @cache.instance_variable_set(:@old_digest, 'non-empty-string')
103
+ expect(@cache).to receive(:run_command).with("bundle clean")
104
+
105
+ @cache.archive_and_upload_bundle
106
+ end
107
+
108
+ it 'archives the current bundle directory' do
109
+ expect(@cache).to receive(:run_command).with(%{cd ~ && tar -cjf "owner-repo-#{@uname}.tgz" .bundle}, exit_on_error: true)
110
+
111
+ @cache.archive_and_upload_bundle
112
+ end
113
+
114
+ it 'sends the correct files to S3' do
115
+ storage = {
116
+ "owner-repo-#{@uname}.tgz" => double(AWS::S3::S3Object),
117
+ "owner-repo-#{@uname}.tgz.sha2" => double(AWS::S3::S3Object)
118
+ }
119
+ @cache.stub(:storage).and_return(storage)
120
+
121
+ expect(storage["owner-repo-#{@uname}.tgz"]).to receive(:write).with(Pathname.new(File.expand_path("~/owner-repo-#{@uname}.tgz")), reduced_redundancy: true)
122
+ expect(storage["owner-repo-#{@uname}.tgz.sha2"]).to receive(:write).with("be7b966bd555fffd27c11f2557484501ad2ed482f1b6164457433800e163ae29", content_type: 'text/plain', reduced_redundancy: true)
123
+
124
+ @cache.archive_and_upload_bundle
125
+ end
126
+ end
127
+ end
@@ -19,6 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
  spec.executables = ["travis_bundle_cache", "travis_bundle_install"]
21
21
 
22
+ spec.signing_key = File.expand_path("~/.gemcert/gem-private_key.pem")
23
+ spec.cert_chain = ['gem-public_cert.pem']
24
+
22
25
  spec.add_dependency "bundler", "~> 1.3"
23
26
  spec.add_dependency "aws-sdk"
24
27
  end
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,13 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis_bundle_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Genord II
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDijCCAnKgAwIBAgIBATANBgkqhkiG9w0BAQUFADBFMQ4wDAYDVQQDDAVkYXZp
14
+ ZDEeMBwGCgmSJomT8ixkARkWDmNvbGxlY3RpdmVpZGVhMRMwEQYKCZImiZPyLGQB
15
+ GRYDY29tMB4XDTEzMDgwMjE0MjAwN1oXDTE0MDgwMjE0MjAwN1owRTEOMAwGA1UE
16
+ AwwFZGF2aWQxHjAcBgoJkiaJk/IsZAEZFg5jb2xsZWN0aXZlaWRlYTETMBEGCgmS
17
+ JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAO+X
18
+ lpzbJojxB0O/2nTxK2NdfgOd2EsnOZaezBZsGDZq0Vbnjec/tNrnsHdUM12LvP1h
19
+ ZuIx/IrAZj4wlsyZgUsKAQs9GXQCDzmKuwo3kmYtUDv55TQJKwDhtdwliTD82FOT
20
+ IkTUEcRZNhtb7ymzpK17p5iHaHL+4BgNs1fbciTxqI1xhh9TGyDOht++9dCjJVDV
21
+ I5nU8VMV8gkAkxA8AlTXNf3hWQNN3tBuvY5EMaG3beN52v+YYDW8Ko4GL16M+aOA
22
+ PShN16CdA5Jjc/hwe6gK175Ma9UTHwIoWDX2WBztM+cU0E27vxFxbe+il9mHk9wG
23
+ BzedoP1o5yNUovdOhIsCAwEAAaOBhDCBgTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
24
+ sDAdBgNVHQ4EFgQUozKz5aO8wO2w0VHWEbPR7x0nBlQwIwYDVR0RBBwwGoEYZGF2
25
+ aWRAY29sbGVjdGl2ZWlkZWEuY29tMCMGA1UdEgQcMBqBGGRhdmlkQGNvbGxlY3Rp
26
+ dmVpZGVhLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEANGHG41mjDpWNsdtjMq7lp5Dw
27
+ xgnf3D3Bz1/t2e4QimdTqniwudSE/P/HD/8HkEn9JMI39xQFyXpfWCFwS5kwsGle
28
+ qr/LzRfLXV3B11TciP10uMYmHQ+46AJ4mL2iyvmRsIKFU45gBpU1/2zJ44GGzYU1
29
+ cSKuuZ0obmZRTI0Vn54e2ofKnWZtylW0SYa9uQplEJK/Ttu88DL99WgwOyNdMlqg
30
+ FJkL4MD3SK4X13qDUlr6YzTkvc8MMfaECuzUIM6KqSGQnyZ16D2zLdZTtr0GPzJZ
31
+ SdQ0gsTaFvafp6C7hh//UHFI92FnVtzpV01oGPDikn3a2qc8eUPvULa2NlJRFQ==
32
+ -----END CERTIFICATE-----
11
33
  date: 2013-08-02 00:00:00.000000000 Z
12
34
  dependencies:
13
35
  - !ruby/object:Gem::Dependency
@@ -48,15 +70,19 @@ extensions: []
48
70
  extra_rdoc_files: []
49
71
  files:
50
72
  - .gitignore
73
+ - .travis.yml
51
74
  - Gemfile
52
75
  - LICENSE.txt
53
76
  - README.md
54
77
  - Rakefile
55
78
  - bin/travis_bundle_cache
56
79
  - bin/travis_bundle_install
80
+ - gem-public_cert.pem
57
81
  - lib/travis_bundle_cache.rb
58
82
  - lib/travis_bundle_cache/cache.rb
59
83
  - lib/travis_bundle_cache/version.rb
84
+ - spec/spec_helper.rb
85
+ - spec/travis_bundle_cache_spec.rb
60
86
  - travis_bundle_cache.gemspec
61
87
  homepage: https://github.com/collectiveidea/travis_bundle_cache
62
88
  licenses:
@@ -82,4 +108,6 @@ rubygems_version: 2.0.3
82
108
  signing_key:
83
109
  specification_version: 4
84
110
  summary: Cache the gem bundle for speedy travis builds
85
- test_files: []
111
+ test_files:
112
+ - spec/spec_helper.rb
113
+ - spec/travis_bundle_cache_spec.rb
metadata.gz.sig ADDED
Binary file