optimal-ci 0.0.1
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/optimal-rspec +5 -0
- data/lib/optimal/ci.rb +18 -0
- data/lib/optimal/ci/provider.rb +18 -0
- data/lib/optimal/ci/provider/base.rb +31 -0
- data/lib/optimal/ci/provider/circle.rb +27 -0
- data/lib/optimal/ci/provider/travis.rb +28 -0
- data/lib/optimal/ci/queue.rb +31 -0
- data/lib/optimal/ci/runner.rb +44 -0
- data/lib/optimal/ci/version.rb +5 -0
- data/lib/rspec/optimal.rb +5 -0
- data/lib/rspec/optimal/runner.rb +18 -0
- data/optimal-ci.gemspec +28 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b80163015f1f21fa19e5f62ee301ba5fc8d68840452c44f89c9f0d5518472d7d
|
4
|
+
data.tar.gz: ec3d0567ba6225990dbb22ae6343b5b9360d840789feabca51e904b27ba7a4f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f99bca894a3bcf8d699b456f17fee7b9b9d96c9469b9d512dd37a4961336b1e1d51a8fbea3e4c1d2784a20eea3203715700bcf8c9cc656dd835eba5b6bbfc10
|
7
|
+
data.tar.gz: 3d9266e0e829b2455dfc6d36662130dbcb45ca16d9d86c2ddce897cfa314a6eb11eed0237968c6ee1c557b038ada6d2bb351ea0ffb020458d8c3dd3c4b69bbdc
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
optimal-ci (0.0.1)
|
5
|
+
rest-client (~> 2.1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
concurrent-ruby (1.1.7)
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
domain_name (0.5.20190701)
|
13
|
+
unf (>= 0.0.5, < 1.0.0)
|
14
|
+
faker (2.13.0)
|
15
|
+
i18n (>= 1.6, < 2)
|
16
|
+
http-accept (1.7.0)
|
17
|
+
http-cookie (1.0.3)
|
18
|
+
domain_name (~> 0.5)
|
19
|
+
i18n (1.8.5)
|
20
|
+
concurrent-ruby (~> 1.0)
|
21
|
+
mime-types (3.3.1)
|
22
|
+
mime-types-data (~> 3.2015)
|
23
|
+
mime-types-data (3.2020.0512)
|
24
|
+
netrc (0.11.0)
|
25
|
+
rake (12.3.3)
|
26
|
+
rest-client (2.1.0)
|
27
|
+
http-accept (>= 1.7.0, < 2.0)
|
28
|
+
http-cookie (>= 1.0.2, < 2.0)
|
29
|
+
mime-types (>= 1.16, < 4.0)
|
30
|
+
netrc (~> 0.8)
|
31
|
+
rspec (3.9.0)
|
32
|
+
rspec-core (~> 3.9.0)
|
33
|
+
rspec-expectations (~> 3.9.0)
|
34
|
+
rspec-mocks (~> 3.9.0)
|
35
|
+
rspec-core (3.9.2)
|
36
|
+
rspec-support (~> 3.9.3)
|
37
|
+
rspec-expectations (3.9.2)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.9.0)
|
40
|
+
rspec-mocks (3.9.1)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.9.0)
|
43
|
+
rspec-support (3.9.3)
|
44
|
+
unf (0.1.4)
|
45
|
+
unf_ext
|
46
|
+
unf_ext (0.0.7.7)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
ruby
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
faker (~> 2.13.0)
|
53
|
+
optimal-ci!
|
54
|
+
rake (~> 12.0)
|
55
|
+
rspec (~> 3.0)
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Mohsen Alizadeh
|
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,32 @@
|
|
1
|
+
# Optimal::Ci
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'optimal-ci'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install optimal-ci
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
|
22
|
+
## Development
|
23
|
+
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/optimal-ci/optimal-ci.
|
28
|
+
|
29
|
+
|
30
|
+
## License
|
31
|
+
|
32
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "optimal/ci"
|
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
data/exe/optimal-rspec
ADDED
data/lib/optimal/ci.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
require "optimal/ci/version"
|
4
|
+
require "optimal/ci/runner"
|
5
|
+
require "optimal/ci/queue"
|
6
|
+
require "rspec/optimal/runner"
|
7
|
+
require "optimal/ci/provider"
|
8
|
+
require "optimal/ci/provider/base"
|
9
|
+
require "optimal/ci/provider/travis"
|
10
|
+
require "optimal/ci/provider/circle"
|
11
|
+
|
12
|
+
|
13
|
+
module Optimal
|
14
|
+
module CI
|
15
|
+
class Error < StandardError; end
|
16
|
+
# Your code goes here...
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Optimal
|
2
|
+
module CI
|
3
|
+
module Provider
|
4
|
+
def self.detect
|
5
|
+
list = constants - [:Base]
|
6
|
+
|
7
|
+
list.each do |p|
|
8
|
+
provider = const_get(p).new
|
9
|
+
|
10
|
+
return provider unless provider.build_number.nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Optimal
|
2
|
+
module CI
|
3
|
+
module Provider
|
4
|
+
class Base
|
5
|
+
def name
|
6
|
+
self.class.name.split("::").last.downcase
|
7
|
+
end
|
8
|
+
|
9
|
+
def total_nodes
|
10
|
+
raise "Not Implemented"
|
11
|
+
end
|
12
|
+
|
13
|
+
def node_index
|
14
|
+
raise "Not Implemented"
|
15
|
+
end
|
16
|
+
|
17
|
+
def build_number
|
18
|
+
raise "Not Implemented"
|
19
|
+
end
|
20
|
+
|
21
|
+
def commit_hash
|
22
|
+
raise "Not Implemented"
|
23
|
+
end
|
24
|
+
|
25
|
+
def branch
|
26
|
+
raise "Not Implemented"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Optimal
|
2
|
+
module CI
|
3
|
+
module Provider
|
4
|
+
class Circle < Base
|
5
|
+
def total_nodes
|
6
|
+
ENV['CIRCLE_NODE_TOTAL']
|
7
|
+
end
|
8
|
+
|
9
|
+
def node_index
|
10
|
+
ENV['CIRCLE_NODE_INDEX']
|
11
|
+
end
|
12
|
+
|
13
|
+
def build_number
|
14
|
+
ENV['CIRCLE_BUILD_NUM']
|
15
|
+
end
|
16
|
+
|
17
|
+
def commit_hash
|
18
|
+
ENV['CIRCLE_SHA1']
|
19
|
+
end
|
20
|
+
|
21
|
+
def branch
|
22
|
+
ENV['CIRCLE_BRANCH']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Optimal
|
2
|
+
module CI
|
3
|
+
module Provider
|
4
|
+
class Travis < Base
|
5
|
+
def total_nodes
|
6
|
+
ENV['CI_NODE_TOTAL']
|
7
|
+
end
|
8
|
+
|
9
|
+
def node_index
|
10
|
+
ENV['CI_NODE_INDEX']
|
11
|
+
end
|
12
|
+
|
13
|
+
def build_number
|
14
|
+
ENV['TRAVIS_BUILD_NUMBER']
|
15
|
+
end
|
16
|
+
|
17
|
+
def commit_hash
|
18
|
+
ENV['TRAVIS_COMMIT']
|
19
|
+
end
|
20
|
+
|
21
|
+
def branch
|
22
|
+
ENV['TRAVIS_BRANCH']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Optimal
|
2
|
+
module CI
|
3
|
+
class Queue
|
4
|
+
def initialize(provider)
|
5
|
+
@provider = provider
|
6
|
+
|
7
|
+
raise "OPTIMAL_CI_URL is not valid ENV" if ENV['OPTIMAL_CI_URL'].nil?
|
8
|
+
raise "OPTIMAL_CI_TOKEN is not valid ENV" if ENV['OPTIMAL_CI_TOKEN'].nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
def push(files)
|
12
|
+
response = ::RestClient.post(ENV['OPTIMAL_CI_URL'] + '/builds', {build_number: @provider.build_number, total_files: files, ci: @provider.name}, { Authorization: ENV['OPTIMAL_CI_TOKEN'] })
|
13
|
+
|
14
|
+
response.code == 204
|
15
|
+
rescue RestClient::Conflict
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def pop
|
20
|
+
response = ::RestClient.get(ENV['OPTIMAL_CI_URL'] + "/builds/#{@provider.build_number}/get_one_file", { Authorization: ENV['OPTIMAL_CI_TOKEN'] })
|
21
|
+
|
22
|
+
return if response.code != 200
|
23
|
+
|
24
|
+
JSON.parse(response.body)
|
25
|
+
|
26
|
+
rescue RestClient::NotFound
|
27
|
+
return nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Optimal
|
2
|
+
module CI
|
3
|
+
class Runner
|
4
|
+
def initialize(args = [])
|
5
|
+
@args = args
|
6
|
+
|
7
|
+
if @args.empty?
|
8
|
+
@paths = [dir]
|
9
|
+
else
|
10
|
+
@paths = @args
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
provider = Optimal::CI::Provider.detect
|
16
|
+
queue = Optimal::CI::Queue.new(provider)
|
17
|
+
|
18
|
+
queue.push(total_files)
|
19
|
+
|
20
|
+
while files = queue.pop
|
21
|
+
system("#{command} #{files.join(' ')}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def total_files
|
26
|
+
return @total_files if @total_files
|
27
|
+
|
28
|
+
@total_files = []
|
29
|
+
|
30
|
+
@paths.each do |path|
|
31
|
+
if path.end_with?(files_end_with)
|
32
|
+
@total_files << path
|
33
|
+
else
|
34
|
+
@total_files << Dir.glob("#{path}/**/*#{files_end_with}")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
@total_files.flatten!
|
39
|
+
|
40
|
+
@total_files
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/optimal-ci.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'lib/optimal/ci/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "optimal-ci"
|
5
|
+
spec.version = Optimal::CI::VERSION
|
6
|
+
spec.authors = ["Mohsen Alizadeh"]
|
7
|
+
spec.email = ["mohsen@alizadeh.us"]
|
8
|
+
|
9
|
+
spec.summary = "optimal-ci"
|
10
|
+
spec.description = "optimal-ci"
|
11
|
+
spec.homepage = "https://github.com/optimal-ci/optimal-ci"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/optimal-ci/optimal-ci"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
spec.add_dependency 'rest-client', '~> 2.1.0'
|
27
|
+
spec.add_development_dependency 'faker', '~> 2.13.0'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: optimal-ci
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mohsen Alizadeh
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faker
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.13.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.13.0
|
41
|
+
description: optimal-ci
|
42
|
+
email:
|
43
|
+
- mohsen@alizadeh.us
|
44
|
+
executables:
|
45
|
+
- optimal-rspec
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rspec"
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- exe/optimal-rspec
|
59
|
+
- lib/optimal/ci.rb
|
60
|
+
- lib/optimal/ci/provider.rb
|
61
|
+
- lib/optimal/ci/provider/base.rb
|
62
|
+
- lib/optimal/ci/provider/circle.rb
|
63
|
+
- lib/optimal/ci/provider/travis.rb
|
64
|
+
- lib/optimal/ci/queue.rb
|
65
|
+
- lib/optimal/ci/runner.rb
|
66
|
+
- lib/optimal/ci/version.rb
|
67
|
+
- lib/rspec/optimal.rb
|
68
|
+
- lib/rspec/optimal/runner.rb
|
69
|
+
- optimal-ci.gemspec
|
70
|
+
homepage: https://github.com/optimal-ci/optimal-ci
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata:
|
74
|
+
homepage_uri: https://github.com/optimal-ci/optimal-ci
|
75
|
+
source_code_uri: https://github.com/optimal-ci/optimal-ci
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 2.3.0
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubygems_version: 3.0.3
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: optimal-ci
|
95
|
+
test_files: []
|