rail_grinder 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.gitlab-ci.yml +22 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +28 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/rg +8 -0
- data/lib/rail_grinder/project.rb +63 -0
- data/lib/rail_grinder/repository.rb +36 -0
- data/lib/rail_grinder/version.rb +3 -0
- data/lib/rail_grinder.rb +61 -0
- data/rail_grinder.gemspec +28 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df2042b7ee8beb294168367b58793ed2d27a4caf
|
4
|
+
data.tar.gz: 8a77394196bcb8bd2c11f6af9ae5184badea592c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 856d0a1f866944c5b7c01c97615a9ba85898530e07d75958ef1adc35e26a339032e4b05d50bb351f048c1692a0a493b171b0ef5f707e1b5285a58bd05c667161
|
7
|
+
data.tar.gz: 1295fc0e66ff7326e836b3894221581d8d6453fbbb30127d4a6c25d2f014afe47ba3752c468cdd783a632a5c23e8652b331f836743178d86ce94adf08d6df8a0
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Official language image. Look for the different tagged releases at:
|
2
|
+
# https://hub.docker.com/r/library/ruby/tags/
|
3
|
+
image: "ruby:2.3"
|
4
|
+
|
5
|
+
# Cache gems in between builds
|
6
|
+
cache:
|
7
|
+
paths:
|
8
|
+
- vendor/ruby
|
9
|
+
|
10
|
+
# This is a basic example for a gem or script which doesn't use
|
11
|
+
# services such as redis or postgres
|
12
|
+
before_script:
|
13
|
+
- ruby -v # Print out ruby version for debugging
|
14
|
+
# Uncomment next line if your rails app needs a JS runtime:
|
15
|
+
# - apt-get update -q && apt-get install nodejs -yqq
|
16
|
+
- apt-get update -q && apt-get install cmake -yqq
|
17
|
+
- gem install bundler --no-ri --no-rdoc # Bundler is not installed with the image
|
18
|
+
- bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
|
19
|
+
|
20
|
+
rspec:
|
21
|
+
script:
|
22
|
+
- rake
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Steve Halasz
|
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,28 @@
|
|
1
|
+
# RailGrinder
|
2
|
+
|
3
|
+
A [rail grinder](https://en.wikipedia.org/wiki/Railgrinder) grinds worn railroad rails to have a consistent profile. If you have a fleet of apps, this tool can help you manage the gem versions they use.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
You will need cmake installed to compile the `rugged` gem's included version of libgit2.
|
8
|
+
|
9
|
+
$ gem install rail_grinder
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
TODO: Write usage instructions here
|
14
|
+
|
15
|
+
## Development
|
16
|
+
|
17
|
+
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.
|
18
|
+
|
19
|
+
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).
|
20
|
+
|
21
|
+
## Todo
|
22
|
+
|
23
|
+
* update prompt on restore
|
24
|
+
|
25
|
+
## License
|
26
|
+
|
27
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
28
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rail_grinder"
|
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
|
data/bin/setup
ADDED
data/exe/rg
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "rail_grinder/repository"
|
2
|
+
|
3
|
+
module RailGrinder
|
4
|
+
class Project
|
5
|
+
def initialize
|
6
|
+
@repos = []
|
7
|
+
@repo_dir = RailGrinder::REPO_DIR
|
8
|
+
@target_gem = nil
|
9
|
+
@target_version = nil
|
10
|
+
load_state
|
11
|
+
|
12
|
+
# Load configuration file if it exists.
|
13
|
+
|
14
|
+
if Dir.exist?(@repo_dir)
|
15
|
+
puts "Repositories will be cloned to the existing './#{@repo_dir}' directory."
|
16
|
+
else
|
17
|
+
Dir.mkdir @repo_dir
|
18
|
+
# TODO: handle failure to create dir?
|
19
|
+
puts "A new './#{@repo_dir}' directory has been created to clone repositories into."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Add a git repository to the project.
|
24
|
+
def add_repo(url)
|
25
|
+
@repos = Repository.new(url, @repo_dir)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Set the target gem that we want to update to the latest version in all
|
29
|
+
# the repositories in the project.
|
30
|
+
def set_target(gem, version)
|
31
|
+
# TODO: validate
|
32
|
+
@target_gem = gem
|
33
|
+
@target_version = version
|
34
|
+
end
|
35
|
+
|
36
|
+
# Show the current status of all the repositories in the project. Show
|
37
|
+
# the version of the target gem, whether tests have passed or failed,
|
38
|
+
# whether the update has been committed, pushed, deployed, etc. in each
|
39
|
+
# repository.
|
40
|
+
def show_status
|
41
|
+
# TODO: Iterate @repos instead?
|
42
|
+
puts "You want '#{@target_gem}' at version #{@target_version}. Currently it's at:"
|
43
|
+
Dir.glob("#{@repo_dir}/*/Gemfile.lock").sort.each do |gemfile|
|
44
|
+
app_dir = File.dirname(gemfile)
|
45
|
+
Dir.chdir(app_dir)
|
46
|
+
lockfile = Bundler::LockfileParser.new(
|
47
|
+
Bundler.read_file(File.basename(gemfile))
|
48
|
+
)
|
49
|
+
|
50
|
+
lockfile.specs.each do |s|
|
51
|
+
if s.name == @target_gem
|
52
|
+
puts "#{s.version.to_s} : #{app_dir}"
|
53
|
+
break
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def save_state
|
60
|
+
open(RailGrinder::STATE_FILE, 'wb') { |f| f.puts Marshal.dump(self) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module RailGrinder
|
2
|
+
# Get the base name of the repository from its url.
|
3
|
+
# Module method rather than private class method so it makes a nice
|
4
|
+
# testable unit.
|
5
|
+
def RailGrinder.inferred_name(url)
|
6
|
+
# Get the bit of the url after the last /
|
7
|
+
name = if url =~ %r|/([^/]+)$|
|
8
|
+
Regexp.last_match[1]
|
9
|
+
end
|
10
|
+
name.gsub!(/\.git$/, '')
|
11
|
+
unless name
|
12
|
+
raise "Couldn't guess name of app from the repo url"
|
13
|
+
end
|
14
|
+
name
|
15
|
+
end
|
16
|
+
|
17
|
+
# Represent a git repository. Handle cloning a repo into a project, and once
|
18
|
+
# it's there, performing commits and pushes.
|
19
|
+
class Repository
|
20
|
+
def initialize(url, repo_dir)
|
21
|
+
unless url
|
22
|
+
raise "Please provide the url to a git repository.\n eg. $ rg.rb add git@gitlab.com:lycoperdon/foo.git"
|
23
|
+
end
|
24
|
+
@url = url
|
25
|
+
@path = "#{repo_dir}/#{RailGrinder.inferred_name(@url)}"
|
26
|
+
|
27
|
+
system "git clone #{@url} #{@path}"
|
28
|
+
# Make sure the clone call went Ok
|
29
|
+
if $CHILD_STATUS.signaled?
|
30
|
+
puts "!! child died with signal %d, %s coredump" % [$CHILD_STATUS.termsig, $CHILD_STATUS.coredump? ? 'with' : 'without']
|
31
|
+
elsif $CHILD_STATUS.exitstatus != 0
|
32
|
+
puts "!! child exited with value %d\n" % [$CHILD_STATUS.exitstatus]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/rail_grinder.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require "rail_grinder/project"
|
2
|
+
require "rail_grinder/version"
|
3
|
+
|
4
|
+
# require 'awesome_print'
|
5
|
+
# TODO: Don't load this as a matter of course
|
6
|
+
# require 'byebug'
|
7
|
+
require 'English'
|
8
|
+
require 'readline'
|
9
|
+
# require 'rugged'
|
10
|
+
|
11
|
+
module RailGrinder
|
12
|
+
REPO_DIR = 'repos'
|
13
|
+
STATE_FILE = '.rail_grinder'
|
14
|
+
|
15
|
+
def RailGrinder.show_help
|
16
|
+
puts "TODO: Actually put the help here"
|
17
|
+
end
|
18
|
+
|
19
|
+
def RailGrinder.run
|
20
|
+
# If there is saved project state, load it.
|
21
|
+
# Otherwise create a new project.
|
22
|
+
project = if File.exist?(STATE_FILE)
|
23
|
+
Marshal.load( File.read(STATE_FILE) )
|
24
|
+
else
|
25
|
+
Project.new
|
26
|
+
end
|
27
|
+
|
28
|
+
# Drop the user in a prompt and process commands as they are entered
|
29
|
+
prompt = 'rg> '
|
30
|
+
while line = Readline.readline(prompt, true)
|
31
|
+
args = line.split
|
32
|
+
command = args.shift
|
33
|
+
|
34
|
+
case command
|
35
|
+
when 'add'
|
36
|
+
# rg> add git@gitlab.com:lycoperdon/foo.git
|
37
|
+
project.add_repo(args.shift)
|
38
|
+
when 'target'
|
39
|
+
# rg> target rails 4.2.7
|
40
|
+
(target_gem, target_version) = *args
|
41
|
+
project.set_target(target_gem, target_version)
|
42
|
+
prompt = "rg #{target_gem}@#{target_version}> "
|
43
|
+
when 'status'
|
44
|
+
project.show_status
|
45
|
+
when 'help'
|
46
|
+
RailGrinder.show_help
|
47
|
+
when /exit|quit/
|
48
|
+
project.save_state
|
49
|
+
puts "Goodbye..."
|
50
|
+
break
|
51
|
+
else
|
52
|
+
puts "I'm sorry, I don't know about that command"
|
53
|
+
RailGrinder.show_help
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# TODO:
|
58
|
+
# Clean out after testing...
|
59
|
+
# `rm -rf repos/{*,.*}
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rail_grinder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rail_grinder"
|
8
|
+
spec.version = RailGrinder::VERSION
|
9
|
+
spec.authors = ["Steve Halasz"]
|
10
|
+
spec.email = ["stevehalasz@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Interrogate and update the version of a gem used by a fleet of apps"
|
13
|
+
spec.homepage = "https://gitlab.com/lycoperdon/rail_grinder"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "rugged"
|
22
|
+
|
23
|
+
spec.add_development_dependency "awesome_print"
|
24
|
+
spec.add_development_dependency "byebug"
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rail_grinder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Halasz
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-17 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'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: awesome_print
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.11'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.11'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- stevehalasz@gmail.com
|
100
|
+
executables:
|
101
|
+
- rg
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".gitlab-ci.yml"
|
107
|
+
- ".rspec"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- exe/rg
|
115
|
+
- lib/rail_grinder.rb
|
116
|
+
- lib/rail_grinder/project.rb
|
117
|
+
- lib/rail_grinder/repository.rb
|
118
|
+
- lib/rail_grinder/version.rb
|
119
|
+
- rail_grinder.gemspec
|
120
|
+
homepage: https://gitlab.com/lycoperdon/rail_grinder
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.5.1
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Interrogate and update the version of a gem used by a fleet of apps
|
144
|
+
test_files: []
|