deploy_changes 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 12d609eec72b9df650f1e8267f0227939d58f50d
4
+ data.tar.gz: c60c58bb2e94121fed26f2e99fc14d4da60912d5
5
+ SHA512:
6
+ metadata.gz: d4ce46727e17cea133c2870009ccb5b5bacfa6a22f2baf5f35a2ae7d2f4846b2fd52b0721dfb475715c905d6ee5d9ee6d26b0da70dc05f379f3a39d1ec3dbdf5
7
+ data.tar.gz: e763bfadbef5b09585dc6caa1d64882b54257162f77eb03ea0b67512c16301fa26428d0f34c859dfe5d8d3eeb815085fd5a8c97c958dc24fb5c028aa959a3f0c
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .deploy_changes
2
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in deploy_changes.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deploy_changes (0.1.0)
5
+ rugged
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ method_source (0.9.0)
13
+ pry (0.11.3)
14
+ coderay (~> 1.1.0)
15
+ method_source (~> 0.9.0)
16
+ rake (10.5.0)
17
+ rspec (3.7.0)
18
+ rspec-core (~> 3.7.0)
19
+ rspec-expectations (~> 3.7.0)
20
+ rspec-mocks (~> 3.7.0)
21
+ rspec-core (3.7.1)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-expectations (3.7.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.7.0)
26
+ rspec-mocks (3.7.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.7.0)
29
+ rspec-support (3.7.0)
30
+ rugged (0.26.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.16)
37
+ deploy_changes!
38
+ pry
39
+ rake (~> 10.0)
40
+ rspec (~> 3.0)
41
+
42
+ BUNDLED WITH
43
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 David Balatero
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # DeployChanges
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/deploy_changes`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'deploy_changes'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install deploy_changes
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dbalatero/deploy_changes.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "deploy_changes"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "deploy_changes/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "deploy_changes"
7
+ spec.version = DeployChanges::VERSION
8
+ spec.authors = ["David Balatero"]
9
+ spec.email = ["dbalatero@gmail.com"]
10
+
11
+ spec.summary = %q{Lets you check if files/directories have changed in Git between last run}
12
+ spec.homepage = "https://github.com/dbalatero/deploy_changes"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "rugged", "~> 0.26"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "pry", "~> 0.11"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ require 'pry'
6
+ require 'deploy_changes'
7
+
8
+ def usage
9
+ puts <<~EOS
10
+ Usage:
11
+
12
+ deploy_changes mark-latest [optional sha1]
13
+ - Run this after a successful deploy to mark the latest deploy SHA
14
+
15
+ deploy_changes changed [file pattern]
16
+ - Exits with 0 if a file pattern has changed since the last time we ran mark-latest.
17
+ - Also exits with 0 if we haven't ran mark-latest yet
18
+ - Exits with 1 if the file pattern has not changed
19
+ EOS
20
+ end
21
+
22
+ command = ARGV.first
23
+
24
+ repo = Rugged::Repository.discover(".")
25
+ commit = DeployChanges::Commit.new(repo)
26
+
27
+ case command
28
+ when 'mark-latest'
29
+ commit.write_head!(ARGV[1])
30
+
31
+ puts "Marked latest commit as last deploy!"
32
+ exit 0
33
+ when 'changed'
34
+ if ARGV.size != 2
35
+ puts "Invalid"
36
+ usage
37
+ exit 1
38
+ end
39
+
40
+ path = DeployChanges::Path.new(repo, commit.last_commit)
41
+
42
+ if path.changed?(ARGV[1])
43
+ exit 0
44
+ else
45
+ exit 1
46
+ end
47
+ else
48
+ usage
49
+
50
+ exit 1
51
+ end
@@ -0,0 +1,6 @@
1
+ require "deploy_changes/version"
2
+ require "deploy_changes/commit"
3
+ require "deploy_changes/path"
4
+
5
+ module DeployChanges
6
+ end
@@ -0,0 +1,31 @@
1
+ module DeployChanges
2
+ class Commit
3
+ attr_reader :repo
4
+
5
+ def initialize(repo)
6
+ @repo = repo
7
+ end
8
+
9
+ def write_head!(sha1 = nil)
10
+ system("mkdir -p #{dir}")
11
+
12
+ sha1 ||= repo.head.target_id
13
+
14
+ File.write(last_deploy_commit_file, sha1)
15
+ end
16
+
17
+ def last_commit
18
+ File.read(last_deploy_commit_file).strip
19
+ end
20
+
21
+ private
22
+
23
+ def dir
24
+ ".deploy_changes"
25
+ end
26
+
27
+ def last_deploy_commit_file
28
+ "#{dir}/last-deploy-commit"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ require 'rugged'
2
+
3
+ module DeployChanges
4
+ class Path
5
+ attr_reader :repo, :last_sha1
6
+
7
+ def initialize(repo, last_sha1)
8
+ @repo = repo
9
+ @last_sha1 = last_sha1
10
+ end
11
+
12
+ def changed?(path)
13
+ diff = repo.index.diff(last_commit)
14
+
15
+ diff.each_delta do |delta|
16
+ files = [delta.old_file[:path], delta.new_file[:path]]
17
+ return true if files.any? { |diff_path| diff_path =~ /^#{path}/ }
18
+ end
19
+
20
+ false
21
+ end
22
+
23
+ private
24
+
25
+ def last_commit
26
+ repo.lookup(last_sha1)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module DeployChanges
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deploy_changes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Balatero
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rugged
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.26'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.26'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description:
84
+ email:
85
+ - dbalatero@gmail.com
86
+ executables:
87
+ - deploy_changes
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - deploy_changes.gemspec
102
+ - exe/deploy_changes
103
+ - lib/deploy_changes.rb
104
+ - lib/deploy_changes/commit.rb
105
+ - lib/deploy_changes/path.rb
106
+ - lib/deploy_changes/version.rb
107
+ homepage: https://github.com/dbalatero/deploy_changes
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.6.11
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Lets you check if files/directories have changed in Git between last run
131
+ test_files: []