Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaro Holodiuk authored and yr0 committed May 12, 2018
0 parents commit cf6d573
Show file tree
Hide file tree
Showing 30 changed files with 554 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
log/*
!log/.keep
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
20 changes: 20 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
AllCops:
TargetRubyVersion: 2.5
DisplayStyleGuide: true
DisplayCopNames: true
Include:
- '**/Gemfile'
Exclude:
- '**/bin/**'

Metrics/LineLength:
Max: 120

Metrics/MethodLength:
Max: 10

Metrics/BlockLength:
Max: 100

Style/Documentation:
Enabled: false
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

source 'https://rubygems.org'

ruby '2.5.1'

gem 'activesupport'

gem 'rspec'
gem 'webmock'

gem 'rubocop'
70 changes: 70 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (5.2.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.4.0)
concurrent-ruby (1.0.5)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
hashdiff (0.3.7)
i18n (1.0.1)
concurrent-ruby (~> 1.0)
minitest (5.11.3)
parallel (1.12.1)
parser (2.5.1.0)
ast (~> 2.4.0)
powerpack (0.1.1)
public_suffix (3.0.2)
rainbow (3.0.0)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
rubocop (0.55.0)
parallel (~> 1.10)
parser (>= 2.5)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
safe_yaml (1.0.4)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.3.2)
webmock (3.4.1)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff

PLATFORMS
ruby

DEPENDENCIES
activesupport
rspec
rubocop
webmock

RUBY VERSION
ruby 2.5.1p57

BUNDLED WITH
1.16.1
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (c) 2018 Yaro Holodiuk

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Continuous Versions
A utility for keeping track of new (Ruby) releases.
It has been developed as a part of automating RVM binaries build process
that needs to be triggered manually whenever a new version of interpreter
is released.

### Installation and usage (tested only on macOS)

1. Download the code and place it in a directory.
2. Install ruby (Tested on `2.5.1`) and gem `bundle`.
3. Do `bundle install` within the directory.
4. To run an iteration of Continuous Versions, do `./bin/continuous-versions`.

### Intuition
The utility returns the difference between the interpreter releases from RSS feed and
those stored in a list on RVM's github. As a result, it allows to quickly check which
binaries need to be uploaded.

Currently the utility only supports JRuby flow, so if you run it, it will output the diff
between the list of binaries at RVM repo and those at JRuby's most recent RSS feed.

Later we will implement another part that submits the GitHub PR based on this diff.

For MRI the flow is slightly more complex, since after we have the versions diff, we need to
trigger the server build to produce the binaries for every combination of new version and a
system supported by RVM. After this process is done, the server would report back to
Continuous Versions with the status. If successful, the GitHub PR needs to be submitted.
5 changes: 5 additions & 0 deletions bin/continuous-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require File.join(File.dirname(__FILE__), '..', 'lib', 'continuous_versions')

ContinuousVersions.start
48 changes: 48 additions & 0 deletions lib/continuous_versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

require 'active_support'
require 'active_support/dependencies'
require 'rss'
require 'open-uri'

ActiveSupport::Dependencies.autoload_paths << File.join(File.dirname(__FILE__), 'ruby_version_checker')
$LOAD_PATH.unshift(File.dirname(__FILE__))

module ContinuousVersions
extend ActiveSupport::Autoload

autoload :PrSubmitter
autoload :RssFromUrlFetcher

module BuildInteractions
extend ActiveSupport::Autoload

autoload :Listener
autoload :Trigger
end

module Interpreters
extend ActiveSupport::Autoload

autoload :Jruby
autoload :Mri

module Jruby
extend ActiveSupport::Autoload

autoload :VersionsFilter
autoload :VersionsParser
end

module Mri
extend ActiveSupport::Autoload

autoload :VersionsParser
end
end

def self.start
Interpreters::Jruby.call
# Interpreters::Mri.call
end
end
9 changes: 9 additions & 0 deletions lib/continuous_versions/build_interactions/listener.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module ContinuousVersions
module BuildInteractions
# Continuously listens to build statuses and logs successes or errors
class Listener
end
end
end
12 changes: 12 additions & 0 deletions lib/continuous_versions/build_interactions/trigger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module ContinuousVersions
module BuildInteractions
class Trigger
def call(versions)
return if versions.blank?
puts 'Triggering the build for versions: ', versions
end
end
end
end
17 changes: 17 additions & 0 deletions lib/continuous_versions/interpreters/jruby.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module ContinuousVersions
module Interpreters
module Jruby
RSS_URL = 'http://jruby.org/atom.xml'

def self.call
[RssFromUrlFetcher, VersionsParser, VersionsFilter, PrSubmitter].reduce(RSS_URL) do |output, klass|
result = klass.new.call(output)
break if result.nil?
result
end
end
end
end
end
33 changes: 33 additions & 0 deletions lib/continuous_versions/interpreters/jruby/versions_filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module ContinuousVersions
module Interpreters
module Jruby
class VersionsFilter
RVM_CONFIG_MD5_URL = 'https://raw.githubusercontent.com/rvm/rvm/master/config/md5'
# 'https://raw.githubusercontent.com/rvm/rvm/ba6894df6ca9794b0ada7c70143af2125c48ba88/config/md5'
JRUBY_PREFIX = 'jruby-bin-'

def call(versions)
uri = URI.parse(RVM_CONFIG_MD5_URL)
config_md5_contents = uri.open.readlines.map(&:strip).select do |line|
line.start_with? JRUBY_PREFIX
end

versions.map { |version| file_signature_for version } - config_md5_contents
end

private

def file_signature_for(version)
return if version.nil?

file_name = "jruby-bin-#{version}.tar.gz"
md5_uri = URI.parse("https://s3.amazonaws.com/jruby.org/downloads/#{version}/#{file_name}.md5")
md5 = md5_uri.open.read.strip
"#{file_name}=#{md5}"
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/continuous_versions/interpreters/jruby/versions_parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module ContinuousVersions
module Interpreters
module Jruby
class VersionsParser
NEW_VERSION_REGEX = /^JRuby ([\d.\w_-]+) released[!?.,]*$/i

def call(rss_feed)
rss_feed.entries.map do |entry|
entry.title.content.scan(NEW_VERSION_REGEX).to_a.flatten.first
end.compact
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/continuous_versions/interpreters/mri.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module ContinuousVersions
module Interpreters
module Mri
RSS_URL = 'http://www.ruby-lang.org/en/feeds/news.rss'

def self.call
[RssFromUrlFetcher, VersionsParser, BuildInteractions::Trigger].reduce(RSS_URL) do |output, klass|
result = klass.new.call(output)
break if result.nil?
result
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/continuous_versions/interpreters/mri/versions_parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module ContinuousVersions
module Interpreters
module Mri
class VersionsParser
NEW_VERSION_REGEX = /^Ruby ([\d.\w_-]+) released[!?.,]*$/i

def call(rss_feed)
rss_feed.items.map do |item|
item.title.scan(NEW_VERSION_REGEX).to_a.flatten.first
end.compact
end
end
end
end
end
9 changes: 9 additions & 0 deletions lib/continuous_versions/pr_submitter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module ContinuousVersions
class PrSubmitter
def call(file_signatures)
puts 'Submitting a PR for file signatures: ', file_signatures
end
end
end
12 changes: 12 additions & 0 deletions lib/continuous_versions/rss_from_url_fetcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module ContinuousVersions
class RssFromUrlFetcher
def call(url)
uri = URI.parse(url)
RSS::Parser.parse(uri.open)
rescue OpenURI::HTTPError
nil
end
end
end
Empty file added log/.keep
Empty file.
16 changes: 16 additions & 0 deletions spec/fixtures/jruby_no_releases.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<feed xmlns="http://www.w3.org/2005/Atom">
<title>JRuby.org News</title>
<link href="http://www.jruby.org/atom.xml" rel="self"/>
<link href="http://www.jruby.org"/>
<updated>2018-04-23T16:31:29+00:00</updated>
<id>http://www.jruby.org/</id>
<author>
<name>The JRuby Team</name>
<email>something</email>
</author>
<entry>
<id>something</id>
<updated>2018-04-23T00:00:00+00:00</updated>
<title>Hello</title>
</entry>
</feed>
16 changes: 16 additions & 0 deletions spec/fixtures/jruby_with_releases.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<feed xmlns="http://www.w3.org/2005/Atom">
<title>JRuby.org News</title>
<link href="http://www.jruby.org/atom.xml" rel="self"/>
<link href="http://www.jruby.org"/>
<updated>2018-04-23T16:31:29+00:00</updated>
<id>http://www.jruby.org/</id>
<author>
<name>The JRuby Team</name>
<email>something</email>
</author>
<entry>
<id>something</id>
<updated>2018-04-23T00:00:00+00:00</updated>
<title>JRuby 9.1.17.0 Released</title>
</entry>
</feed>
Loading

0 comments on commit cf6d573

Please sign in to comment.