gci 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5054a7bc682bec251963ae83b64a496d7013fdef5506717bc44736c5b570da8
4
- data.tar.gz: 46267463380486d6469798c7bb19b0989258b157bc282c1a26c02ff885298426
3
+ metadata.gz: 070d78a3999dda8cbfa5f3cc9bd4f9e7ab4fd9e9148280dbf3fb697913d87a12
4
+ data.tar.gz: f226b93f81535cb6e1fb11229262b2d160ba01d25322695f6b5f5cf62bc51cea
5
5
  SHA512:
6
- metadata.gz: 6cb9a7d1f05bbfa8264961661c76dd5a8116c3ff3a0950706b9c996b373d9d3150d36173fed2b6edc5a1b5689c13b22b5374df11ef8c20506746fe752d7de584
7
- data.tar.gz: 28063867afc8274abc325c22b2f5e6da7c6e9fe94173c928eaea8719ffa349378485714402a6b00b46e708bfcc47f009319975503a9b298931272888471944f4
6
+ metadata.gz: a2b861901ba6d9be1f4c4bee94752b86ba136f656324d0e864703f5921c7810a480afba887c83178358a2e83472a6a45e41d1aaa2ef1fd5190fa998e1156503c
7
+ data.tar.gz: a17ae50e24fdfef6be219e5562c0a354a6469bfd1de6972f45e9ddf9b379f369a4bb125a94246c24aefeb1c54b8c968686f0828586b29811a16d5c734f65432c
@@ -1,9 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ GCI.root_pipeline do |pipeline|
4
+ pipeline
5
+ .jobs["generate-config"]
6
+ .before_script
7
+ .unshift("ruby -v")
8
+ end
9
+
1
10
  GCI.pipeline do |pipeline|
2
11
  pipeline.image = 'ruby:alpine'
3
12
 
4
13
  test_job = GCI::Job.new(stage: :test) do |job|
5
14
  job.before_script = [
6
- 'bundle install --path vendor/ruby'
15
+ 'apk add --update git',
16
+ "bundle config set path 'vendor/ruby'",
17
+ 'bundle install'
7
18
  ]
8
19
  job.cache = {
9
20
  key: { files: ['Gemfile.lock'] },
@@ -11,10 +22,13 @@ GCI.pipeline do |pipeline|
11
22
  }
12
23
  end
13
24
 
14
- %w[rspec rubocop].each do |job_name|
25
+ {
26
+ rspec: nil,
27
+ rubocop: '--config .rubocop.yml'
28
+ }.each do |job_name, options|
15
29
  test_job.change do |job|
16
30
  job.name = job_name
17
- job.script = ["bundle exec #{job_name}"]
31
+ job.script = ["bundle exec #{job_name} #{options}"]
18
32
  pipeline.jobs << job
19
33
  end
20
34
  end
@@ -6,6 +6,7 @@
6
6
  generate-config:
7
7
  :stage: build
8
8
  :before_script:
9
+ - ruby -v
9
10
  - gem install gci
10
11
  :script:
11
12
  - gci --config .gitlab-ci.rb generate
@@ -0,0 +1,24 @@
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://docs.rubocop.org/rubocop/configuration
11
+
12
+ AllCops:
13
+ TargetRubyVersion: 2.5
14
+ NewCops: enable
15
+ Exclude:
16
+ - .gitlab-ci.rb
17
+ - ./vendor/**/*
18
+
19
+ Style/Documentation:
20
+ Enabled: false
21
+ Metrics/AbcSize:
22
+ Enabled: false
23
+ Metrics/MethodLength:
24
+ Enabled: false
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in gci.gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gci (0.1.1)
4
+ gci (0.1.2)
5
5
  activesupport (>= 5.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -30,14 +30,135 @@ Or install it yourself as:
30
30
 
31
31
  ## Usage
32
32
 
33
+ To generate a simple pipeline with one job to list all the files from the current directory,
34
+ create a `.gitlab-ci.rb` file with the following content:
35
+
33
36
  ```ruby
34
- GitLab::Pipeline.new do |pipeline|
35
- pipeline.jobs.new(name: 'test', stage: 'test', script: ['ls -lah'])
37
+ GCI.pipeline do |pipeline|
38
+ pipeline.jobs.build(name: 'list-files') do |job|
39
+ job.stage = 'test'
40
+ job.script = ['ls -lah']
41
+ end
36
42
 
37
43
  puts pipeline.to_yaml
38
44
  end
39
45
  ```
40
46
 
47
+ to have this up and running you need a simple `.gitlab-ci.yml` config to trigger the [dynamic pipelines](https://docs.gitlab.com/ee/ci/yaml/README.html#trigger-child-pipeline-with-generated-configuration-file):
48
+
49
+ ```yaml
50
+ ---
51
+ :stages:
52
+ - build
53
+ - run
54
+
55
+ :image: ruby:alpine
56
+
57
+ generate-config:
58
+ :stage: build
59
+ :before_script:
60
+ - gem install gci
61
+ :script:
62
+ - gci --config .gitlab-ci.rb generate
63
+ :artifacts:
64
+ :paths:
65
+ - child.gitlab-ci.yml
66
+
67
+ execute-config:
68
+ :stage: run
69
+ :trigger:
70
+ :include:
71
+ - :artifact: child.gitlab-ci.yml
72
+ :job: generate-config
73
+ :strategy: depend
74
+ ```
75
+
76
+
77
+ You can run `gci --config .gitlab-ci.rb root` locally to generate it and push it to the repo. You can change any part of it, for example, adding a `ruby -v` command at the beginning of the execution:
78
+
79
+ ```ruby
80
+ GCI.root_pipeline do |pipeline|
81
+ pipeline
82
+ .jobs["generate-config"]
83
+ .before_script
84
+ .unshift("ruby -v")
85
+ end
86
+ ```
87
+
88
+
89
+ [`.gitlab-ci.rb`](./.gitlab-ci.rb) shows a more advanced usage. A pipeline with two jobs that have a lot in common:
90
+
91
+ ```ruby
92
+ GCI.pipeline do |pipeline|
93
+ pipeline.image = 'ruby:alpine'
94
+
95
+ test_job = GCI::Job.new(stage: :test) do |job|
96
+ job.before_script = [
97
+ 'apk add --update git',
98
+ "bundle config set path 'vendor/ruby'",
99
+ 'bundle install'
100
+ ]
101
+ job.cache = {
102
+ key: { files: ['Gemfile.lock'] },
103
+ paths: ['vendor/ruby']
104
+ }
105
+ end
106
+
107
+ {
108
+ rspec: nil,
109
+ rubocop: '--config .rubocop.yml'
110
+ }.each do |job_name, options|
111
+ test_job.change do |job|
112
+ job.name = job_name
113
+ job.script = ["bundle exec #{job_name} #{options}"]
114
+ pipeline.jobs << job
115
+ end
116
+ end
117
+ end
118
+ ```
119
+
120
+ This is how the YAML configuration for the child pipeline looks like:
121
+
122
+ ```yaml
123
+ ---
124
+ :stages:
125
+ - build
126
+ - test
127
+ - deploy
128
+
129
+ :image: ruby:alpine
130
+
131
+ :rspec:
132
+ :stage: test
133
+ :before_script:
134
+ - apk add --update git
135
+ - bundle config set path 'vendor/ruby'
136
+ - bundle install
137
+ :cache:
138
+ :key:
139
+ :files:
140
+ - Gemfile.lock
141
+ :paths:
142
+ - vendor/ruby
143
+ :script:
144
+ - 'bundle exec rspec '
145
+
146
+ :rubocop:
147
+ :stage: test
148
+ :before_script:
149
+ - apk add --update git
150
+ - bundle config set path 'vendor/ruby'
151
+ - bundle install
152
+ :cache:
153
+ :key:
154
+ :files:
155
+ - Gemfile.lock
156
+ :paths:
157
+ - vendor/ruby
158
+ :script:
159
+ - bundle exec rubocop --config .rubocop.yml
160
+ ```
161
+
41
162
  ## Development
42
163
 
43
164
  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.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'gci'
data/exe/gci CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- $:.unshift(File.expand_path('../lib', __dir__))
4
+ $LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
4
5
 
5
6
  require 'optparse'
6
7
  require 'gci'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/gci/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -7,10 +9,13 @@ Gem::Specification.new do |spec|
7
9
  spec.email = ['marius@mbobin.me']
8
10
 
9
11
  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.'
12
+ spec.description = <<~DESC
13
+ Using dynamic pipelines you can use your favorite programming \
14
+ language to generate YAML files for pipelines.
15
+ DESC
11
16
  spec.homepage = 'https://gitlab.com/mbobin/gci'
12
17
  spec.license = 'MIT'
13
- spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
18
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
14
19
 
15
20
  spec.metadata['homepage_uri'] = spec.homepage
16
21
  spec.metadata['source_code_uri'] = spec.homepage
data/lib/gci.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/all'
2
4
  require 'yaml'
3
5
  require 'gci/version'
@@ -50,5 +52,8 @@ module GCI
50
52
  }
51
53
  end
52
54
  end
55
+
56
+ yield(@root_pipeline) if block_given?
57
+ @root_pipeline
53
58
  end
54
59
  end
@@ -1,13 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GCI
2
4
  class CLI
3
5
  COMMANDS = %i[generate root].freeze
4
6
 
5
7
  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
8
+ raise Error, "Invalid command '#{command}'" unless COMMANDS.include?(command.to_sym)
9
+
10
+ public_send(command, options)
11
11
  end
12
12
 
13
13
  def generate(options)
@@ -25,11 +25,9 @@ module GCI
25
25
  private
26
26
 
27
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
28
+ raise Error, 'Missing configuration file' unless options[:config].present?
29
+
30
+ require(Pathname(options[:config]).expand_path)
33
31
  end
34
32
  end
35
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GCI
2
4
  class Job
3
5
  class Collection
@@ -23,6 +25,10 @@ module GCI
23
25
  acc
24
26
  end
25
27
  end
28
+
29
+ def [](name)
30
+ @data.detect { |job| job.name == name }
31
+ end
26
32
  end
27
33
 
28
34
  def self.define_attr_accessors(name)
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GCI
2
4
  class Pipeline
3
5
  attr_reader :jobs
4
- attr_accessor :stages, :image, :variables
6
+ attr_accessor :stages, :image, :variables, :workflow
5
7
  attr_writer :gitlab_ci_file
6
8
 
7
9
  def initialize
@@ -22,6 +24,7 @@ module GCI
22
24
  data = {}
23
25
  data.merge!(stages: stages.map(&:to_s))
24
26
  data.merge!(image: @image) if @image.present?
27
+ data.merge!(workflow: @workflow) if @workflow.present?
25
28
  data.merge!(@jobs.to_h)
26
29
  data
27
30
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GCI
2
- VERSION = '0.1.1'.freeze
4
+ VERSION = '0.1.2'
3
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marius Bobin
@@ -24,8 +24,10 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
- description: Using dynamic pipelines you can use your favorite programming language
27
+ description: 'Using dynamic pipelines you can use your favorite programming language
28
28
  to generate YAML files for pipelines.
29
+
30
+ '
29
31
  email:
30
32
  - marius@mbobin.me
31
33
  executables:
@@ -37,6 +39,7 @@ files:
37
39
  - ".gitlab-ci.rb"
38
40
  - ".gitlab-ci.yml"
39
41
  - ".rspec"
42
+ - ".rubocop.yml"
40
43
  - Gemfile
41
44
  - Gemfile.lock
42
45
  - LICENSE.txt
@@ -65,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
68
  requirements:
66
69
  - - ">="
67
70
  - !ruby/object:Gem::Version
68
- version: 2.3.0
71
+ version: 2.5.0
69
72
  required_rubygems_version: !ruby/object:Gem::Requirement
70
73
  requirements:
71
74
  - - ">="