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 +4 -4
- data/.gitlab-ci.rb +17 -3
- data/.gitlab-ci.yml +1 -0
- data/.rubocop.yml +24 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +123 -2
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/exe/gci +2 -1
- data/gci.gemspec +7 -2
- data/lib/gci.rb +5 -0
- data/lib/gci/cli.rb +8 -10
- data/lib/gci/job.rb +6 -0
- data/lib/gci/pipeline.rb +4 -1
- data/lib/gci/version.rb +3 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 070d78a3999dda8cbfa5f3cc9bd4f9e7ab4fd9e9148280dbf3fb697913d87a12
|
4
|
+
data.tar.gz: f226b93f81535cb6e1fb11229262b2d160ba01d25322695f6b5f5cf62bc51cea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2b861901ba6d9be1f4c4bee94752b86ba136f656324d0e864703f5921c7810a480afba887c83178358a2e83472a6a45e41d1aaa2ef1fd5190fa998e1156503c
|
7
|
+
data.tar.gz: a17ae50e24fdfef6be219e5562c0a354a6469bfd1de6972f45e9ddf9b379f369a4bb125a94246c24aefeb1c54b8c968686f0828586b29811a16d5c734f65432c
|
data/.gitlab-ci.rb
CHANGED
@@ -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
|
-
'
|
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
|
-
|
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
|
data/.gitlab-ci.yml
CHANGED
data/.rubocop.yml
ADDED
@@ -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
data/Gemfile.lock
CHANGED
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
|
-
|
35
|
-
pipeline.jobs.
|
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
data/bin/console
CHANGED
data/exe/gci
CHANGED
data/gci.gemspec
CHANGED
@@ -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 =
|
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.
|
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
data/lib/gci/cli.rb
CHANGED
@@ -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
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
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
|
data/lib/gci/job.rb
CHANGED
data/lib/gci/pipeline.rb
CHANGED
@@ -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
|
data/lib/gci/version.rb
CHANGED
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.
|
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.
|
71
|
+
version: 2.5.0
|
69
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
73
|
requirements:
|
71
74
|
- - ">="
|