gci 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c5054a7bc682bec251963ae83b64a496d7013fdef5506717bc44736c5b570da8
4
+ data.tar.gz: 46267463380486d6469798c7bb19b0989258b157bc282c1a26c02ff885298426
5
+ SHA512:
6
+ metadata.gz: 6cb9a7d1f05bbfa8264961661c76dd5a8116c3ff3a0950706b9c996b373d9d3150d36173fed2b6edc5a1b5689c13b22b5374df11ef8c20506746fe752d7de584
7
+ data.tar.gz: 28063867afc8274abc325c22b2f5e6da7c6e9fe94173c928eaea8719ffa349378485714402a6b00b46e708bfcc47f009319975503a9b298931272888471944f4
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ /child.gitlab-ci.yml
@@ -0,0 +1,23 @@
1
+ GCI.pipeline do |pipeline|
2
+ pipeline.image = 'ruby:alpine'
3
+
4
+ test_job = GCI::Job.new(stage: :test) do |job|
5
+ job.before_script = [
6
+ 'bundle install --path vendor/ruby'
7
+ ]
8
+ job.cache = {
9
+ key: { files: ['Gemfile.lock'] },
10
+ paths: ['vendor/ruby']
11
+ }
12
+ end
13
+
14
+ %w[rspec rubocop].each do |job_name|
15
+ test_job.change do |job|
16
+ job.name = job_name
17
+ job.script = ["bundle exec #{job_name}"]
18
+ pipeline.jobs << job
19
+ end
20
+ end
21
+
22
+ puts pipeline.to_yaml
23
+ end
@@ -0,0 +1,21 @@
1
+ ---
2
+ :stages:
3
+ - build
4
+ - run
5
+ :image: ruby:alpine
6
+ generate-config:
7
+ :stage: build
8
+ :before_script:
9
+ - gem install gci
10
+ :script:
11
+ - gci --config .gitlab-ci.rb generate
12
+ :artifacts:
13
+ :paths:
14
+ - child.gitlab-ci.yml
15
+ execute-config:
16
+ :stage: run
17
+ :trigger:
18
+ :include:
19
+ - :artifact: child.gitlab-ci.yml
20
+ :job: generate-config
21
+ :strategy: depend
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gci.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 12.0'
7
+ gem 'rspec', '~> 3.0'
8
+ gem 'rubocop', '~> 1.2'
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gci (0.1.1)
5
+ activesupport (>= 5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (6.0.3.4)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ zeitwerk (~> 2.2, >= 2.2.2)
16
+ ast (2.4.1)
17
+ concurrent-ruby (1.1.7)
18
+ diff-lcs (1.4.4)
19
+ i18n (1.8.5)
20
+ concurrent-ruby (~> 1.0)
21
+ minitest (5.14.2)
22
+ parallel (1.20.0)
23
+ parser (2.7.2.0)
24
+ ast (~> 2.4.1)
25
+ rainbow (3.0.0)
26
+ rake (12.3.3)
27
+ regexp_parser (1.8.2)
28
+ rexml (3.2.4)
29
+ rspec (3.10.0)
30
+ rspec-core (~> 3.10.0)
31
+ rspec-expectations (~> 3.10.0)
32
+ rspec-mocks (~> 3.10.0)
33
+ rspec-core (3.10.0)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-expectations (3.10.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-mocks (3.10.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-support (3.10.0)
42
+ rubocop (1.2.0)
43
+ parallel (~> 1.10)
44
+ parser (>= 2.7.1.5)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.8)
47
+ rexml
48
+ rubocop-ast (>= 1.0.1)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 1.4.0, < 2.0)
51
+ rubocop-ast (1.1.1)
52
+ parser (>= 2.7.1.5)
53
+ ruby-progressbar (1.10.1)
54
+ thread_safe (0.3.6)
55
+ tzinfo (1.2.7)
56
+ thread_safe (~> 0.1)
57
+ unicode-display_width (1.7.0)
58
+ zeitwerk (2.4.1)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ gci!
65
+ rake (~> 12.0)
66
+ rspec (~> 3.0)
67
+ rubocop (~> 1.2)
68
+
69
+ BUNDLED WITH
70
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Marius Bobin
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.
@@ -0,0 +1,54 @@
1
+ # Write your GitLab pipeline configuration in Ruby!
2
+
3
+ This gem uses [dynamic child pipelines](https://docs.gitlab.com/ee/ci/parent_child_pipelines.html#dynamic-child-pipelines)
4
+
5
+ ## Why would you use this over plain YAML?
6
+
7
+ - Easy to reuse structures
8
+ - Easy to read complex pipelines
9
+ - More powerful control flow
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'gci'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```
22
+ $ bundle install
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ```
28
+ $ gem install gci
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ```ruby
34
+ GitLab::Pipeline.new do |pipeline|
35
+ pipeline.jobs.new(name: 'test', stage: 'test', script: ['ls -lah'])
36
+
37
+ puts pipeline.to_yaml
38
+ end
39
+ ```
40
+
41
+ ## Development
42
+
43
+ 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.
44
+
45
+ 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).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://gitlab.com/mbobin/gci.
50
+
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'gci'
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__)
@@ -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
data/exe/gci ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path('../lib', __dir__))
4
+
5
+ require 'optparse'
6
+ require 'gci'
7
+
8
+ begin
9
+ options = {}
10
+
11
+ subtext = <<~HELP
12
+ Commonly used command are:
13
+ generate : Generate child pipeline configuration
14
+ root : Generate root pipeline configuration
15
+ HELP
16
+
17
+ global = OptionParser.new do |opts|
18
+ opts.version = GCI::VERSION
19
+ opts.banner = 'Usage: [options] [subcommand]'
20
+ opts.on('-c', '--config PATH', 'The path to the pipeline configuration') do |config|
21
+ options[:config] = config
22
+ end
23
+
24
+ opts.separator ''
25
+ opts.separator subtext
26
+ end
27
+
28
+ global.parse!
29
+
30
+ subcommands = {
31
+ 'generate' => OptionParser.new do |opts|
32
+ opts.banner = 'Usage: -c path/to/config generate'
33
+ end,
34
+ 'root' => OptionParser.new do |opts|
35
+ opts.banner = 'Usage: -c path/to/config root'
36
+ end
37
+ }
38
+
39
+ global.order!
40
+ command = ARGV.shift
41
+ subcommands[command].order!
42
+ GCI::CLI.new.dispatch(command, options)
43
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument, LoadError, GCI::Error => e
44
+ warn "Error: #{e.message}"
45
+ exit 1
46
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/gci/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'gci'
5
+ spec.version = GCI::VERSION
6
+ spec.authors = ['Marius Bobin']
7
+ spec.email = ['marius@mbobin.me']
8
+
9
+ spec.summary = 'Write your GitLab pipeline configuration in Ruby!'
10
+ spec.description = 'Using dynamic pipelines you can use your favorite programming language to generate YAML files for pipelines.'
11
+ spec.homepage = 'https://gitlab.com/mbobin/gci'
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'] = spec.homepage
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(__dir__)) 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
+
27
+ spec.add_dependency 'activesupport', '>= 5.0'
28
+ end
@@ -0,0 +1,54 @@
1
+ require 'active_support/all'
2
+ require 'yaml'
3
+ require 'gci/version'
4
+ require 'gci/cli'
5
+ require 'gci/job'
6
+ require 'gci/pipeline'
7
+
8
+ module GCI
9
+ class Error < StandardError; end
10
+
11
+ def self.pipeline(&block)
12
+ if @pipeline
13
+ yield(@pipeline) if block_given?
14
+ else
15
+ @pipeline = Pipeline.new(&block)
16
+ end
17
+
18
+ @pipeline
19
+ end
20
+
21
+ def self.root_pipeline
22
+ @root_pipeline ||= Pipeline.new do |pipeline|
23
+ pipeline.gitlab_ci_file = '.gitlab-ci.yml'
24
+ pipeline.image = 'ruby:alpine'
25
+ pipeline.stages = %i[build run]
26
+
27
+ pipeline.jobs.build(name: 'generate-config') do |job|
28
+ job.stage = :build
29
+ job.before_script = [
30
+ 'gem install gci'
31
+ ]
32
+
33
+ job.script = [
34
+ 'gci --config .gitlab-ci.rb generate'
35
+ ]
36
+
37
+ job.artifacts = {
38
+ paths: ['child.gitlab-ci.yml']
39
+ }
40
+ end
41
+
42
+ pipeline.jobs.build(name: 'execute-config') do |job|
43
+ job.stage = :run
44
+ job.trigger = {
45
+ include: [
46
+ artifact: 'child.gitlab-ci.yml',
47
+ job: 'generate-config'
48
+ ],
49
+ strategy: 'depend'
50
+ }
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,35 @@
1
+ module GCI
2
+ class CLI
3
+ COMMANDS = %i[generate root].freeze
4
+
5
+ def dispatch(command, options)
6
+ if COMMANDS.include?(command.to_sym)
7
+ public_send(command, options)
8
+ else
9
+ raise Error, "Invalid command '#{command}'"
10
+ end
11
+ end
12
+
13
+ def generate(options)
14
+ evaluate_user_config(options)
15
+
16
+ GCI.pipeline.write
17
+ end
18
+
19
+ def root(options)
20
+ evaluate_user_config(options)
21
+
22
+ GCI.root_pipeline.write
23
+ end
24
+
25
+ private
26
+
27
+ def evaluate_user_config(options)
28
+ if options[:config].present?
29
+ require(Pathname(options[:config]).expand_path)
30
+ else
31
+ raise Error, 'Missing configuration file'
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,91 @@
1
+ module GCI
2
+ class Job
3
+ class Collection
4
+ def initialize
5
+ @data = []
6
+ end
7
+
8
+ def build(**attrs, &block)
9
+ job = Job.new(**attrs, &block)
10
+ @data << job
11
+ job
12
+ end
13
+
14
+ def <<(job)
15
+ @data << job
16
+
17
+ self
18
+ end
19
+
20
+ def to_h
21
+ @data.each_with_object({}) do |job, acc|
22
+ acc.merge!(job.name => job.attributes)
23
+ acc
24
+ end
25
+ end
26
+ end
27
+
28
+ def self.define_attr_accessors(name)
29
+ define_method("#{name}=") do |value|
30
+ @attrs[name] = value
31
+ end
32
+
33
+ define_method(name) do
34
+ @attrs[name]
35
+ end
36
+ end
37
+
38
+ define_attr_accessors :name
39
+ define_attr_accessors :script
40
+ define_attr_accessors :after_script
41
+ define_attr_accessors :allow_failure
42
+ define_attr_accessors :artifacts
43
+ define_attr_accessors :before_script
44
+ define_attr_accessors :cache
45
+ define_attr_accessors :coverage
46
+ define_attr_accessors :dependencies
47
+ define_attr_accessors :environment
48
+ define_attr_accessors :except
49
+ define_attr_accessors :extends
50
+ define_attr_accessors :image
51
+ define_attr_accessors :include
52
+ define_attr_accessors :interruptible
53
+ define_attr_accessors :only
54
+ define_attr_accessors :pages
55
+ define_attr_accessors :parallel
56
+ define_attr_accessors :release
57
+ define_attr_accessors :resource_group
58
+ define_attr_accessors :retry
59
+ define_attr_accessors :rules
60
+ define_attr_accessors :services
61
+ define_attr_accessors :stage
62
+ define_attr_accessors :tags
63
+ define_attr_accessors :timeout
64
+ define_attr_accessors :trigger
65
+ define_attr_accessors :variables
66
+ define_attr_accessors :when
67
+
68
+ def initialize(**attrs)
69
+ @attrs = attrs
70
+ yield(self) if block_given?
71
+ end
72
+
73
+ def stage=(value)
74
+ @attrs[:stage] = value.to_s
75
+ end
76
+
77
+ def change(&block)
78
+ self.class.new(**@attrs.deep_dup, &block)
79
+ end
80
+
81
+ def to_h
82
+ data = @attrs
83
+ data[:stage] = data[:stage].to_s if data[:stage]
84
+ data
85
+ end
86
+
87
+ def attributes
88
+ to_h.except(:name)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,33 @@
1
+ module GCI
2
+ class Pipeline
3
+ attr_reader :jobs
4
+ attr_accessor :stages, :image, :variables
5
+ attr_writer :gitlab_ci_file
6
+
7
+ def initialize
8
+ @jobs = Job::Collection.new
9
+ @stages = %i[build test deploy]
10
+ @gitlab_ci_file = 'child.gitlab-ci.yml'
11
+
12
+ yield(self) if block_given?
13
+ end
14
+
15
+ def write
16
+ File.open(@gitlab_ci_file, 'wb') do |file|
17
+ file.write(to_yaml)
18
+ end
19
+ end
20
+
21
+ def to_h
22
+ data = {}
23
+ data.merge!(stages: stages.map(&:to_s))
24
+ data.merge!(image: @image) if @image.present?
25
+ data.merge!(@jobs.to_h)
26
+ data
27
+ end
28
+
29
+ def to_yaml
30
+ to_h.to_yaml
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module GCI
2
+ VERSION = '0.1.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gci
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Marius Bobin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ description: Using dynamic pipelines you can use your favorite programming language
28
+ to generate YAML files for pipelines.
29
+ email:
30
+ - marius@mbobin.me
31
+ executables:
32
+ - gci
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".gitignore"
37
+ - ".gitlab-ci.rb"
38
+ - ".gitlab-ci.yml"
39
+ - ".rspec"
40
+ - Gemfile
41
+ - Gemfile.lock
42
+ - LICENSE.txt
43
+ - README.md
44
+ - Rakefile
45
+ - bin/console
46
+ - bin/setup
47
+ - exe/gci
48
+ - gci.gemspec
49
+ - lib/gci.rb
50
+ - lib/gci/cli.rb
51
+ - lib/gci/job.rb
52
+ - lib/gci/pipeline.rb
53
+ - lib/gci/version.rb
54
+ homepage: https://gitlab.com/mbobin/gci
55
+ licenses:
56
+ - MIT
57
+ metadata:
58
+ homepage_uri: https://gitlab.com/mbobin/gci
59
+ source_code_uri: https://gitlab.com/mbobin/gci
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.3.0
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.1.2
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Write your GitLab pipeline configuration in Ruby!
79
+ test_files: []