rrm 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
+ SHA256:
3
+ metadata.gz: 4e220d2a14a7fb50f527b6f34cc1f1b0b9622fd86f4bccbaef24a4c867df5dbb
4
+ data.tar.gz: 875410743004d73f298a1315eb4aa49ed096687888782baa3742236169f87d2a
5
+ SHA512:
6
+ metadata.gz: de359b88b0ddba4c8a5e06e58032507ec3c1f216653f3e977b553842deccb22743cc821047649529d19f7dcebdd905a5069a912df446c04e3280fa6b8ff29fe2
7
+ data.tar.gz: 4af9887c71355377fa5c78b9711a0ee481a376359bdef5cdc7fb29caf577ec5f7b15ce1e0f52f974f34c6f37cc49d090dad6cf9b61c41f1d3d584ae159c2fb9d
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .rspec_status
10
+ .byebug_history
11
+ log/*
12
+ !log/.keep
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.2
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at janne.waren@iki.fi. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rrm.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,87 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rrm (0.1.0)
5
+ docker-api (~> 1.34)
6
+ git (~> 1.5)
7
+ highline (~> 2.0)
8
+ nokogiri (~> 1.10)
9
+ slop (~> 4.6)
10
+ tty-progressbar (~> 0.16.0)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ addressable (2.6.0)
16
+ public_suffix (>= 2.0.2, < 4.0)
17
+ awesome_print (1.8.0)
18
+ byebug (11.0.1)
19
+ crack (0.4.3)
20
+ safe_yaml (~> 1.0.0)
21
+ diff-lcs (1.3)
22
+ docile (1.3.1)
23
+ docker-api (1.34.2)
24
+ excon (>= 0.47.0)
25
+ multi_json
26
+ excon (0.62.0)
27
+ git (1.5.0)
28
+ hashdiff (0.3.8)
29
+ highline (2.0.1)
30
+ json (2.2.0)
31
+ mini_portile2 (2.4.0)
32
+ multi_json (1.13.1)
33
+ nokogiri (1.10.2)
34
+ mini_portile2 (~> 2.4.0)
35
+ public_suffix (3.0.3)
36
+ rake (10.5.0)
37
+ rspec (3.8.0)
38
+ rspec-core (~> 3.8.0)
39
+ rspec-expectations (~> 3.8.0)
40
+ rspec-mocks (~> 3.8.0)
41
+ rspec-core (3.8.0)
42
+ rspec-support (~> 3.8.0)
43
+ rspec-expectations (3.8.2)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.8.0)
46
+ rspec-mocks (3.8.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.8.0)
49
+ rspec-support (3.8.0)
50
+ safe_yaml (1.0.5)
51
+ simplecov (0.16.1)
52
+ docile (~> 1.1)
53
+ json (>= 1.8, < 3)
54
+ simplecov-html (~> 0.10.0)
55
+ simplecov-html (0.10.2)
56
+ slop (4.6.2)
57
+ strings-ansi (0.1.0)
58
+ tty-cursor (0.6.1)
59
+ tty-progressbar (0.16.0)
60
+ strings-ansi (~> 0.1.0)
61
+ tty-cursor (~> 0.6.0)
62
+ tty-screen (~> 0.6.4)
63
+ unicode-display_width (~> 1.3)
64
+ tty-screen (0.6.5)
65
+ unicode-display_width (1.5.0)
66
+ vcr (4.0.0)
67
+ webmock (3.5.1)
68
+ addressable (>= 2.3.6)
69
+ crack (>= 0.3.2)
70
+ hashdiff
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ awesome_print
77
+ bundler (~> 2.0)
78
+ byebug
79
+ rake (~> 10.0)
80
+ rrm!
81
+ rspec (~> 3.0)
82
+ simplecov
83
+ vcr
84
+ webmock
85
+
86
+ BUNDLED WITH
87
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Janne Warén
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,51 @@
1
+ # rrm - Ruby Repository Manager
2
+
3
+ Trying to make the repetitive task of updating Ruby (and gem dependencies) for multiple projects a bit less painful.
4
+
5
+ ## What does it do?
6
+
7
+ Give it some URL's to git repositories, and rrm will:
8
+ * Clone each repository
9
+ * Update to the latest patch, minor or major version of Ruby by updating
10
+ * Dockerfile
11
+ * Gemfile
12
+ * Gemfile.lock (by running bundle via Docker)
13
+ * .gitlab-ci.yml
14
+ * .rubocop.yml
15
+ * .travis.yml
16
+ * Updates gems to latest versions if you choose to
17
+ * Push changes in a new branch to remote
18
+
19
+ Staying up to date with new Ruby versions on tens of projects should be easier than ever!
20
+
21
+ ## Running it
22
+
23
+ ### Requirements
24
+
25
+ * Ruby
26
+ * Docker
27
+
28
+ Tested on macOS Mojave with Ruby 2.6.2 and Docker 18.09.2.
29
+
30
+ ### Usage
31
+
32
+ Clone the repository
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jannewaren/rrm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Rrm project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jannewaren/rrm/blob/master/CODE_OF_CONDUCT.md).
45
+
46
+ ## TODO
47
+
48
+ * Interactive mode with some fancy ncurses dialogs etc
49
+ * Only update gems in selected groups (to easily update development dependencies more often for example)
50
+ * Ways to limit or increase output (--quiet mode and --verbose mode)
51
+ * Make proper documentation and refactor all the classes so it could be used as a gem/library inside other projects. For example a Slack bot to update things?
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,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rrm'
5
+
6
+ require 'irb'
7
+ IRB.start(__FILE__)
data/bin/rrm ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rrm'
5
+
6
+ require 'highline'
7
+ require 'slop'
8
+
9
+ opts = Slop.parse do |o|
10
+ o.separator ""
11
+ o.separator "Required parameters"
12
+ o.array '-u', '--urls', 'comma-separated list of git repository clone urls', delimiter: ','
13
+
14
+ o.separator ""
15
+ o.separator "Choose what to update:"
16
+ o.bool '--patch-next', 'update to next available Patch version from current version (eg. 2.3.4 from 2.3.3)'
17
+ o.bool '--patch-latest', 'update to latest new Patch version from current version (eg. 2.3.8 from 2.3.3)'
18
+ o.bool '--minor-next', 'update to next available Minor version from current version (eg. 2.4.5 from 2.3.3)'
19
+ o.bool '--minor-latest', 'update to latest new Minor version from current version (eg. 2.6.2 from 2.5.3)'
20
+ o.bool '--major-next', 'update to next available Major version from current version (eg. 2.6.2 from 1.9.3)'
21
+ o.bool '--major-latest', 'update to latest new Major version from current version (eg. 2.6.2 from 1.9.3)'
22
+ o.bool '--update-gems', 'update gems in Gemfile and Gemfile.lock'
23
+
24
+ o.separator ""
25
+ o.separator "Extra options:"
26
+
27
+ o.array '-e', '--env', 'List environment variables to pass into the Docker container (for example to authenticate in case you have private gems)', delimiter: ','
28
+
29
+ o.on '-h', '--help', 'show this help' do
30
+ puts o
31
+ exit
32
+ end
33
+
34
+ o.on '--list-ruby-versions', 'list all Ruby version available to rrm' do
35
+ puts Rrm.all_ruby_versions
36
+ exit
37
+ end
38
+
39
+ o.on '--version', 'print the version' do
40
+ puts "Ruby Repository Manager"
41
+ puts "rrm #{Rrm::VERSION}"
42
+ exit
43
+ end
44
+ end
45
+
46
+ Rrm::Updater.new(opts).update_all
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,30 @@
1
+ module Rrm
2
+ class Dockerfile
3
+ FILENAME = 'Dockerfile'
4
+ PATTERN = /^FROM ruby:([\d.]{1,5})/
5
+
6
+ attr_accessor :git, :content, :new_version
7
+
8
+ def initialize(git)
9
+ @content = File.read("#{git.dir.path}/#{FILENAME}")
10
+ @git = git
11
+ rescue
12
+ @content = nil
13
+ end
14
+
15
+ def update!(new_version)
16
+ new_content = content.gsub(/(^FROM ruby:)([\d.]{1,5})/, ('\1'+new_version))
17
+ file = File.open("#{git.dir.path}/#{FILENAME}", 'w')
18
+ file.puts new_content
19
+ file.close
20
+ git.commit_all("Updating #{FILENAME} to Ruby #{new_version}")
21
+ rescue
22
+ Rrm.logger.debug("Could not update #{FILENAME} because #{$!.message}")
23
+ nil
24
+ end
25
+
26
+ def ruby_version
27
+ @ruby_version ||= content.match(PATTERN).captures.first
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ module Rrm
2
+ class Gemfile
3
+ FILENAME = 'Gemfile'
4
+ PATTERN = /^ruby ['"](\d.\d.\d)['"]/
5
+
6
+ attr_accessor :git, :content, :new_version
7
+
8
+ def initialize(git)
9
+ @content = File.read("#{git.dir.path}/#{FILENAME}")
10
+ @git = git
11
+ rescue
12
+ @content = nil
13
+ end
14
+
15
+ def update!(new_version)
16
+ new_content = content.gsub(/(^ruby ['"])([\d.]{1,5})(['"])/, ('\1'+new_version+'\3'))
17
+ file = File.open("#{git.dir.path}/#{FILENAME}", 'w')
18
+ file.puts new_content
19
+ file.close
20
+ git.commit_all("Updating #{FILENAME} to Ruby #{new_version}")
21
+ rescue
22
+ Rrm.logger.debug("Could not update #{FILENAME} because #{$!.message}")
23
+ nil
24
+ end
25
+
26
+ def ruby_version
27
+ @ruby_version ||= @content.match(PATTERN).captures.first
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,58 @@
1
+ require 'docker'
2
+
3
+ module Rrm
4
+ class GemfileLock
5
+ GEMFILE = 'Gemfile'
6
+ FILENAME = 'Gemfile.lock'
7
+ TIMEOUT_SECONDS = 240
8
+
9
+ attr_accessor :git, :content, :new_version, :update_gems
10
+
11
+ def initialize(git, update_gems)
12
+ @content = File.read("#{git.dir.path}/#{FILENAME}")
13
+ @git = git
14
+ @update_gems = update_gems
15
+ rescue
16
+ @content = nil
17
+ end
18
+
19
+ def update!(new_version)
20
+ image = Docker::Image.create('fromImage' => "ruby:#{new_version}")
21
+ container = Docker::Container.create('Cmd' => 'bundle', 'Image' => "ruby:#{new_version}", 'Env' => env_options)
22
+ container.store_file("/#{GEMFILE}", File.read("#{git.dir.path}/#{GEMFILE}"))
23
+ container.store_file("/#{FILENAME}", File.read("#{git.dir.path}/#{FILENAME}")) unless update_gems
24
+ container.start
25
+ Rrm.logger.debug "Running 'bundle' inside Docker, please wait. Timeout is #{TIMEOUT_SECONDS} seconds"
26
+ container.wait(TIMEOUT_SECONDS)
27
+ new_content = container.read_file("/#{FILENAME}")
28
+ container.stop
29
+ file = File.open("#{git.dir.path}/#{FILENAME}", 'w')
30
+ file.puts new_content
31
+ file.close
32
+ git.commit_all(commit_message(new_version))
33
+ end
34
+
35
+ private
36
+
37
+ def env_options
38
+ arr = []
39
+ $env_variables.each do |e|
40
+ arr << "#{e}=#{ENV[e]}"
41
+ end
42
+ Rrm.logger.debug "Passing #{$env_variables} to Docker as Env"
43
+ arr
44
+ end
45
+
46
+ def commit_message(new_version)
47
+ msg = "Updating #{FILENAME} to Ruby #{new_version}"
48
+ msg << " and updating #{number_of_gem_updates} gems" if update_gems
49
+ msg
50
+ end
51
+
52
+ def number_of_gem_updates
53
+ git.diff.first.patch.split("\n").select{|s| s.start_with?('+')}.select{|s| s.include?("(")}.size
54
+ rescue
55
+ "?"
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,30 @@
1
+ module Rrm
2
+ class GitlabCi
3
+ FILENAME = '.gitlab-ci.yml'
4
+ PATTERN = /image: ruby:([\d.]{1,5})/
5
+
6
+ attr_accessor :git, :content, :new_version
7
+
8
+ def initialize(git)
9
+ @content = File.read("#{git.dir.path}/#{FILENAME}")
10
+ @git = git
11
+ rescue
12
+ @content = nil
13
+ end
14
+
15
+ def update!(new_version)
16
+ new_content = content.gsub(/(image: ruby:)([\d.]{1,5})/, ('\1'+new_version))
17
+ file = File.open("#{git.dir.path}/#{FILENAME}", 'w')
18
+ file.puts new_content
19
+ file.close
20
+ git.commit_all("Updating #{FILENAME} to Ruby #{new_version}")
21
+ rescue
22
+ Rrm.logger.debug("Could not update #{FILENAME} because #{$!.message}")
23
+ nil
24
+ end
25
+
26
+ def ruby_version
27
+ @ruby_version ||= @content.match(PATTERN).captures.first
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ module Rrm
2
+ class Rubocop
3
+ FILENAME = '.rubocop.yml'
4
+ PATTERN = /TargetRubyVersion: (\d.\d)/
5
+
6
+ attr_accessor :git, :content, :new_version
7
+
8
+ def initialize(git)
9
+ @content = File.read("#{git.dir.path}/#{FILENAME}")
10
+ @git = git
11
+ rescue
12
+ @content = nil
13
+ end
14
+
15
+ def update!(new_version)
16
+ return if ruby_version == new_version
17
+
18
+ new_content = content.gsub(/(TargetRubyVersion: )(\d.\d)/, ('\1'+new_version))
19
+ file = File.open("#{git.dir.path}/#{FILENAME}", 'w')
20
+ file.puts new_content
21
+ file.close
22
+ git.commit_all("Updating #{FILENAME} to Ruby #{new_version}")
23
+ rescue
24
+ Rrm.logger.debug("Could not update #{FILENAME} because #{$!.message}")
25
+ nil
26
+ end
27
+
28
+ def ruby_version
29
+ @ruby_version ||= @content.match(PATTERN).captures.first
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ module Rrm
2
+ class Travis
3
+ FILENAME = '.travis.yml'
4
+ PATTERN = /rvm:\s+-\s(\d.\d.\d)/
5
+
6
+ attr_accessor :git, :content, :new_version
7
+
8
+ def initialize(git)
9
+ @content = File.read("#{git.dir.path}/#{FILENAME}")
10
+ @git = git
11
+ rescue
12
+ @content = nil
13
+ end
14
+
15
+ def update!(new_version)
16
+ new_content = content.gsub(/(rvm:\s+-\s)(\d.\d.\d)/, ('\1'+new_version))
17
+ file = File.open("#{git.dir.path}/#{FILENAME}", 'w')
18
+ file.puts new_content
19
+ file.close
20
+ git.commit_all("Updating #{FILENAME} to Ruby #{new_version}")
21
+ rescue
22
+ Rrm.logger.debug("Could not update #{FILENAME} because #{$!.message}")
23
+ nil
24
+ end
25
+
26
+ def ruby_version
27
+ @ruby_version ||= @content.match(PATTERN).captures.first
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,145 @@
1
+ require 'git'
2
+ require 'securerandom'
3
+
4
+ module Rrm
5
+ class Repository
6
+ CLONEDIR = "/tmp/rrm/#{SecureRandom.uuid}/"
7
+
8
+ attr_accessor :url, :name, :level
9
+ attr_accessor :major, :minor, :patch
10
+ attr_accessor :dockerfile, :gemfile, :gemfile_lock, :gitlab_ci, :rubocop, :travis
11
+ attr_accessor :branch_name
12
+
13
+ def initialize(url, level, update_gems)
14
+ @url = url
15
+ @name = url.split('/').last.gsub('.git', '')
16
+ @dockerfile = Rrm::Dockerfile.new(git)
17
+ @gemfile = Rrm::Gemfile.new(git)
18
+ @gemfile_lock = Rrm::GemfileLock.new(git, update_gems)
19
+ @gitlab_ci = Rrm::GitlabCi.new(git)
20
+ @rubocop = Rrm::Rubocop.new(git)
21
+ @travis = Rrm::Travis.new(git)
22
+ @major, @minor, @patch = current_version.split('.')
23
+ @level = level
24
+ end
25
+
26
+ def git
27
+ @git ||= clone_or_update_git
28
+ end
29
+
30
+ def current_version
31
+ @current_version ||= fetch_current_version
32
+ end
33
+
34
+ def new_version
35
+ @new_version ||= decide_new_ruby_version
36
+ end
37
+
38
+ def update!
39
+ Rrm.logger.debug "Updating #{name} from #{current_version} to #{new_version}"
40
+ create_branch
41
+ dockerfile.update!(new_version)
42
+ gemfile.update!(new_version)
43
+ gemfile_lock.update!(new_version)
44
+ gitlab_ci.update!(new_version)
45
+ rubocop.update!(new_version.split('.')[0..1].join('.'))
46
+ travis.update!(new_version)
47
+ rescue
48
+ Rrm.logger.warn("Failed to update! #{$!.message} - #{$!.backtrace}")
49
+ end
50
+
51
+ def push!
52
+ git.push('origin', @branch_name)
53
+ end
54
+
55
+ private
56
+
57
+ def create_branch
58
+ @branch_name = "#{Time.new.strftime('%Y%m%d%H%M%S')}_upgrade_to_ruby_#{new_version.delete('.')}"
59
+ git.branch(@branch_name).checkout
60
+ end
61
+
62
+ def all
63
+ Rrm.all_ruby_versions.dup
64
+ end
65
+
66
+ def decide_new_ruby_version
67
+ case level
68
+ when :major_next
69
+ major_next
70
+ when :major_latest
71
+ major_latest
72
+ when :minor_next
73
+ minor_next
74
+ when :minor_latest
75
+ minor_latest
76
+ when :patch_next
77
+ patch_next
78
+ when :patch_latest
79
+ patch_latest
80
+ end
81
+ end
82
+
83
+ def major_next
84
+ next_major = (major.to_i+1).to_s
85
+ all.select{|v| v.start_with?("#{next_major}.")}.last
86
+ rescue
87
+ nil
88
+ end
89
+
90
+ def major_latest
91
+ next_major = (major.to_i+1).to_s
92
+ all.select{|v| v > next_major}.last
93
+ rescue
94
+ nil
95
+ end
96
+
97
+ def minor_next
98
+ next_minor = (minor.to_i+1).to_s
99
+ all.select{|v| v.start_with?("#{major}.#{next_minor}.")}.last
100
+ rescue
101
+ nil
102
+ end
103
+
104
+ def minor_latest
105
+ all.select{|v| v.start_with?("#{major}.")}.last
106
+ rescue
107
+ nil
108
+ end
109
+
110
+ def patch_next
111
+ next_patch = (patch.to_i+1).to_s
112
+ all.select{|v| v == ("#{major}.#{minor}.#{next_patch}")}.last
113
+ rescue
114
+ nil
115
+ end
116
+
117
+ def patch_latest
118
+ all.select{|v| v == ("#{major}.#{minor}.")}.last
119
+ rescue
120
+ nil
121
+ end
122
+
123
+ def clone_or_update_git
124
+ git = Git.open("#{CLONEDIR}#{name}")
125
+ git.pull('origin', 'master')
126
+ Rrm.logger.debug("Using previous directory #{CLONEDIR}#{name}")
127
+ git
128
+ rescue ArgumentError
129
+ Rrm.logger.debug("Could not Git.open - reverting to Git.clone instead")
130
+ Git.clone(url, name, path: CLONEDIR)
131
+ rescue
132
+ Rrm.logger.error("Could not open or clone #{url} because #{$!.message} - #{$!.backtrace}")
133
+ nil
134
+ end
135
+
136
+ def fetch_current_version
137
+ line = git.gblob('Gemfile').grep('ruby ')['Gemfile'].flatten
138
+ return nil unless line.last.include?('ruby ')
139
+ line.last.match(/(\d.\d.\d)/).to_s
140
+ rescue
141
+ Rrm.logger.warn("fetch_current_version not found for #{name} - #{$!.message} - #{$!.backtrace}")
142
+ nil
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,81 @@
1
+ module Rrm
2
+ class Updater
3
+ require 'tty-progressbar'
4
+
5
+ attr_accessor :options
6
+ attr_accessor :level
7
+
8
+ # Needs options as a hash. Options follow the naming from
9
+ # the console application in bin/rrm. Example
10
+ #
11
+ # { :urls => [
12
+ # [0] "git@gitlab.com:kickban/form-kickban-fi.git"
13
+ # ],
14
+ # :patch_next => false,
15
+ # :patch_latest => true,
16
+ # :minor_next => false,
17
+ # :minor_latest => false,
18
+ # :major_next => false,
19
+ # :major_latest => false,
20
+ # :update_gems => false
21
+ # }
22
+ def initialize(options)
23
+ $env_variables = options[:env]
24
+
25
+ @options = options
26
+ if options[:major_latest]
27
+ @level = :major_latest
28
+ elsif options[:major_next]
29
+ @level = :major_next
30
+ elsif options[:minor_latest]
31
+ @level = :minor_latest
32
+ elsif options[:minor_next]
33
+ @level = :minor_next
34
+ elsif options[:patch_latest]
35
+ @level = :patch_latest
36
+ elsif options[:patch_next]
37
+ @level = :patch_next
38
+ end
39
+ end
40
+
41
+ def update_all
42
+ Rrm.logger.debug "Available normal Ruby versions: #{Rrm.all_ruby_versions}"
43
+ all_repositories.each do |repository|
44
+ puts "#{repository.name} from #{repository.current_version} to #{repository.new_version}"
45
+ end
46
+
47
+ bar = TTY::ProgressBar.new("Running upgrades (:current of :total) [:bar]", total: all_repositories.size, width: 30)
48
+ all_repositories.each do |repository|
49
+ repository.update!
50
+ bar.advance(1)
51
+ end
52
+
53
+ bar = TTY::ProgressBar.new("Pushing branches (:current of :total) [:bar]", total: all_repositories.size, width: 30)
54
+ all_repositories.each do |repository|
55
+ repository.push!
56
+ bar.advance(1)
57
+ end
58
+
59
+ puts "Pushed branches:"
60
+ all_repositories.each do |repository|
61
+ puts "#{repository.branch_name} (#{repository.git.remote.url})"
62
+ end
63
+ end
64
+
65
+ def all_repositories
66
+ @all_repositories ||=fetch_all_repositories
67
+ end
68
+
69
+ private
70
+
71
+ def fetch_all_repositories
72
+ bar = TTY::ProgressBar.new("Cloning repositories (:current of :total) [:bar]", total: options[:urls].size, width: 30)
73
+ repos = []
74
+ options[:urls].each do |url|
75
+ repos << Rrm::Repository.new(url, level, options[:update_gems])
76
+ bar.advance(1)
77
+ end
78
+ repos
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ module Rrm
2
+ VERSION = '0.1.0'
3
+ end
data/lib/rrm.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+
4
+ require_relative 'rrm/version'
5
+ require_relative 'rrm/repository'
6
+ require_relative 'rrm/updater'
7
+ require_relative 'rrm/filehandlers/dockerfile'
8
+ require_relative 'rrm/filehandlers/gemfile'
9
+ require_relative 'rrm/filehandlers/gemfile_lock'
10
+ require_relative 'rrm/filehandlers/gitlab-ci'
11
+ require_relative 'rrm/filehandlers/rubocop'
12
+ require_relative 'rrm/filehandlers/travis'
13
+
14
+ module Rrm
15
+ class Error < StandardError; end
16
+
17
+ def self.logger
18
+ @logger ||= Logger.new('log/rrm.log')
19
+ end
20
+
21
+ def self.all_ruby_versions
22
+ @all_ruby_versions ||= fetch_all_ruby_versions
23
+ end
24
+
25
+ def self.fetch_all_ruby_versions
26
+ versions = []
27
+ html = open('https://www.ruby-lang.org/en/downloads/releases/')
28
+ doc = Nokogiri::HTML(html)
29
+ rows = doc.search('tr')
30
+ rows.each do |row|
31
+ ver = row.search('td').first.text
32
+ next if ver.include?('preview')
33
+ next if ver.include?('rc')
34
+ next if ver.include?('-p')
35
+ versions << ver.split(' ').last
36
+ rescue
37
+ next
38
+ end
39
+ versions.compact.sort
40
+ end
41
+ end
data/log/.keep ADDED
File without changes
data/rrm.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rrm/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rrm'
7
+ spec.version = Rrm::VERSION
8
+ spec.authors = ['Janne Warén']
9
+ spec.email = ['janne.waren@iki.fi']
10
+
11
+ spec.summary = %q{Updating Ruby and Gems easily on multiple projects}
12
+ spec.description = %q{Makes updating Gemfile and friends easy for a lot of projects at once.}
13
+ spec.homepage = 'https://github.com/jannewaren/rrm'
14
+ spec.license = 'MIT'
15
+
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/jannewaren/rrm'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/jannewaren/rrm/releases'
20
+ else
21
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
22
+ 'public gem pushes.'
23
+ end
24
+
25
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_development_dependency 'bundler', '~> 2.0'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.0'
36
+ spec.add_development_dependency 'byebug', '~> 11.0'
37
+ spec.add_development_dependency 'simplecov', '~> 0.17.0'
38
+ spec.add_development_dependency 'vcr', '~> 5.0'
39
+ spec.add_development_dependency 'webmock', '~> 3.6'
40
+ spec.add_development_dependency 'awesome_print', '~> 1.8'
41
+
42
+ spec.add_runtime_dependency 'git', '~> 1.5'
43
+ spec.add_runtime_dependency 'highline', '~> 2.0'
44
+ spec.add_runtime_dependency 'nokogiri', '~> 1.10'
45
+ spec.add_runtime_dependency 'docker-api', '~> 1.34'
46
+ spec.add_runtime_dependency 'slop', '~> 4.6'
47
+ spec.add_runtime_dependency 'tty-progressbar', '~> 0.16.0'
48
+ end
metadata ADDED
@@ -0,0 +1,266 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rrm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Janne Warén
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '11.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '11.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.17.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.17.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.6'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: awesome_print
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: git
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.5'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.5'
139
+ - !ruby/object:Gem::Dependency
140
+ name: highline
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: nokogiri
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.10'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.10'
167
+ - !ruby/object:Gem::Dependency
168
+ name: docker-api
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '1.34'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '1.34'
181
+ - !ruby/object:Gem::Dependency
182
+ name: slop
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '4.6'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '4.6'
195
+ - !ruby/object:Gem::Dependency
196
+ name: tty-progressbar
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 0.16.0
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 0.16.0
209
+ description: Makes updating Gemfile and friends easy for a lot of projects at once.
210
+ email:
211
+ - janne.waren@iki.fi
212
+ executables: []
213
+ extensions: []
214
+ extra_rdoc_files: []
215
+ files:
216
+ - ".gitignore"
217
+ - ".rspec"
218
+ - ".travis.yml"
219
+ - CODE_OF_CONDUCT.md
220
+ - Gemfile
221
+ - Gemfile.lock
222
+ - LICENSE.txt
223
+ - README.md
224
+ - Rakefile
225
+ - bin/console
226
+ - bin/rrm
227
+ - bin/setup
228
+ - lib/rrm.rb
229
+ - lib/rrm/filehandlers/dockerfile.rb
230
+ - lib/rrm/filehandlers/gemfile.rb
231
+ - lib/rrm/filehandlers/gemfile_lock.rb
232
+ - lib/rrm/filehandlers/gitlab-ci.rb
233
+ - lib/rrm/filehandlers/rubocop.rb
234
+ - lib/rrm/filehandlers/travis.rb
235
+ - lib/rrm/repository.rb
236
+ - lib/rrm/updater.rb
237
+ - lib/rrm/version.rb
238
+ - log/.keep
239
+ - rrm.gemspec
240
+ homepage: https://github.com/jannewaren/rrm
241
+ licenses:
242
+ - MIT
243
+ metadata:
244
+ homepage_uri: https://github.com/jannewaren/rrm
245
+ source_code_uri: https://github.com/jannewaren/rrm
246
+ changelog_uri: https://github.com/jannewaren/rrm/releases
247
+ post_install_message:
248
+ rdoc_options: []
249
+ require_paths:
250
+ - lib
251
+ required_ruby_version: !ruby/object:Gem::Requirement
252
+ requirements:
253
+ - - ">="
254
+ - !ruby/object:Gem::Version
255
+ version: '0'
256
+ required_rubygems_version: !ruby/object:Gem::Requirement
257
+ requirements:
258
+ - - ">="
259
+ - !ruby/object:Gem::Version
260
+ version: '0'
261
+ requirements: []
262
+ rubygems_version: 3.0.3
263
+ signing_key:
264
+ specification_version: 4
265
+ summary: Updating Ruby and Gems easily on multiple projects
266
+ test_files: []