singularity_dsl 1.2.8 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mzg2MGViZWNiZjM3MWYwNWYzMTlmYTk2ZDQxYTcxZmI0NzQxZTNjMw==
4
+ MDYwYWE4MmNhN2ZkNzEzYWFiNmIzYmM0MjExZWNkY2U5YWNiZjA3Yg==
5
5
  data.tar.gz: !binary |-
6
- Zjk3MTE3OTk4NjI3ZGNmMzM3ZDRhMDdmZjc1NGNiOTY4ODBiY2YyNQ==
6
+ YmMwNDYyYWQ4NGY5ZDliNjZhYzZhZjg1Y2NhNjA1ZjY1MjI2Njg1OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OGE5ZjUwZDkwZWY1ZmI4ZjUzNDkyODQ1NmY5ZGVkYmNhOGQ2YTFiYzdkNzA0
10
- MWQ4ODc0MzYxMmZlYTMyNzY0ZWFmNjhhM2ZlOTBjNmE0NzBlZjU0M2EyYzll
11
- NDYxZGQ0MDAxZGJmNjkwYzJkZTRlMWMyN2JlMzNhMTQ1NzIyYWM=
9
+ NzljY2JlZWVkZDVkMjBmN2Q5ZTA2MDU0ZTY1MWNmMzhkNWNiNTM1ZTUyOTlh
10
+ NjZhMDZiNzZkYjNhNTMyNmM4NGI2NTg4NzJjNDY3ZjU1ZjYyOWU4N2NjYzM0
11
+ NjA3M2UyZDZiYmFkZmVmOWQyMGU5MTJhYTAzYjViZDdlODMxODQ=
12
12
  data.tar.gz: !binary |-
13
- N2MxM2M2ZGMxMjgxMGQ5MzZmOTlmOTU1MDQyOWYzNjYwYzM4YWMzNDllMDU3
14
- YjNmNWFiMmE3NjVlYzMxM2EzM2E0MWRhMGI0MDU5ODg0Mzg0MjQ2OTBmNjI4
15
- Njc3ODliODAwZDdmMWMzZTQ4OTVkNzkyY2QwMTEzMzhlMzdiMDM=
13
+ OGM1MjY1MjFkMDkwY2U2ZjRkODU4YTY2NjkyOGQyYmM0YTc3M2I2NzQ2MWU4
14
+ YjFiNmRhOWI3ZGYyMDk3ZDRhZGVlMDgyNGQyOTMxOTExZWM4ODFmYjA3ZWY1
15
+ MmE4YjhmZjI1ZDhhNWE4NjRmMWUyMGQ5OWVlNGQ0YTk3MTgxMTM=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- singularity_dsl (1.2.8)
4
+ singularity_dsl (1.2.9)
5
5
  mixlib-shellout (~> 1.4)
6
6
  rainbow (~> 2.0.0)
7
7
  rake (~> 10.3)
data/README.md CHANGED
@@ -3,25 +3,244 @@
3
3
  A DSL lib for your [SingularityCI](https://github.com/behance/singularity) instance.
4
4
  Inspired by TravisCI's `.travis.yml`
5
5
 
6
- ...Except with the full power of Ruby, its gems & your awesome JenkinsCI machine(s)
6
+ ...Except with the full power of Ruby, its gems & your awesome JenkinsCI machine(s).
7
+
8
+ All you need is a `.singularityrc` file in your repository, the `singularity_runner` (provided by this gem) and you're ready to go!
7
9
 
8
10
  ## Installation
9
11
 
10
- Add this line to your application's Gemfile:
12
+ $ gem install singularity_dsl
11
13
 
12
- gem 'singularity_dsl'
14
+ ## Runner Usage
13
15
 
14
- And then execute:
16
+ Commands:
17
+ singularity_runner batch BATCH_NAME # Run single task batch in the .singularityrc script.
18
+ singularity_runner help [COMMAND] # Describe available commands or one specific command
19
+ singularity_runner tasks # Available tasks.
20
+ singularity_runner test # Run singularity script.
21
+ singularity_runner testmerge FORK BRANCH INTO_BRANCH [INTO_FORK] # Perform a testmerge into the local repo and then run .singularityrc
15
22
 
16
- $ bundle
23
+ Options:
24
+ -t, [--task-path=TASK_PATH] # Directory where custom tasks are defined
25
+ # Default: ./.singularity
26
+ -a, [--all-tasks], [--no-all-tasks] # Do not stop on task failure(s), collect all results
27
+ -s, [--script=SCRIPT] # Specify path to a .singularityrc file
28
+ # Default: ./.singularityrc
17
29
 
18
- Or install it yourself as:
30
+ The `singularity_runner` is designed to do two things:
19
31
 
20
- $ gem install singularity_dsl
32
+ - load custom tasks from the repository you're running it in (`.singularity` dir by default).
33
+ - read a `.singularityrc` file.
34
+
35
+ ### .singularityrc
36
+
37
+ Just a ruby file describing what you want to run. The commands that are run are called `task`s. For example:
38
+
39
+ ```ruby
40
+ shelltask { command 'bundle' }
41
+ rubocop
42
+ rspec
43
+ ```
44
+
45
+ Running `singularity_runner test` in the same directory as this file, everything just gets executed. Simple, right?
46
+
47
+ ### Runner Execution Breakdown
48
+
49
+ What's actually happening is:
50
+
51
+ - the runner first loads up any task definitions. Built in task definitions [here](https://github.com/behance/singularity_dsl/tree/master/lib/singularity_dsl/tasks)
52
+ - runner then looks for any *custom* defined definitions in your `cwd/.singularity` dir
53
+ - loads the entire `.singularityrc` file into an internally managed DSL object
54
+ - depending on what command is run, evaluates blocks in `.singularityrc`
55
+
56
+ ### Task Batches
57
+
58
+ You can even define `batch`es of tasks to be run. So for example:
59
+
60
+ ```ruby
61
+ batch :test do
62
+ rubocop
63
+ rspec
64
+ end
65
+
66
+ shelltask { command 'bundle' }
67
+ ```
68
+
69
+ Running `singularity_runner test` on this file will only run the `bundle` shelltask. Why? Because defining a `batch` does not run anything. It's just a way for your to organize what tasks should be run together.
70
+
71
+ To actually run it, you need this line: `invoke_batch :test`
72
+
73
+ Or, if you **just** want to run that one batch, without the `bundle` shelltask, you can tell the runner to do just that! `singularity_runner batch test`
74
+
75
+ ### Task API, Custom Tasks & Task Extensions
76
+
77
+ A task is just a ruby class. For base functionality, it needs an `execute` method. You can have it do whatever you want in that method.
78
+ To further customize it, you can define a `description` method that returns a string with some info about the task.
79
+
80
+ Tasks also take [ruby blocks](http://www.reactive.io/tips/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/).
81
+
82
+ What this means is that you can pass blocks of code to tasks from your `.singularityrc`. Those blocks of code would then be executed in the context of the Task. Think [resources in chef](http://docs.getchef.com/resource.html). You can use these blocks to configure how certain task declarations run.
83
+
84
+ ### `singularity_runner`, Custom Tasks & Task Extensions
85
+
86
+ As mentioned, `singularity_runner` can load custom tasks or task extensions. By default, it will load **all** files in `cwd/.singularity`
87
+
88
+ This allows you to do a few things:
89
+
90
+ 1. abstract out common tasks that you use to build, test, etc your code
91
+ 2. configure tools / tasks with default values specific to your use case
92
+ 3. create a common lib of task definitions to be shared amoungst your repositories
93
+
94
+ To see a list of base tasks, their class names, what their names are in `.singularityrc`'s context, you just have to run:
95
+
96
+ ```
97
+ singularity_runner tasks
98
+ ```
99
+
100
+ Which yields something like:
101
+
102
+ ```
103
+ Task Task Function Description
104
+
105
+ Rake rake Simple resource to just wrap the Rake CLI
106
+ RSpec rspec Run RSpec tests. Uses RSpec::Core
107
+ Rubocop rubocop Runs rubocop, loads .rubocop.yml from ./
108
+ ShellTask shelltask Runs a SH command using Mixlib::ShellOut
109
+ ```
110
+
111
+ Note that there is a task called `shelltask`, defined by a ruby Task class called `ShellTask`.
112
+ Say you wanted to create a task for a common echo command. You can simply create a ruby file in `cwd/.singularity`, say `echo.rb`
113
+
114
+ ```ruby
115
+ class Echo extends ShellTask
116
+ def execute
117
+ command 'echo "hello"'
118
+ super
119
+ end
120
+ end
121
+ ```
21
122
 
22
- ## Usage
123
+ The `singularity_runner tasks` command should then list your task as one of the tasks usable from your cwd.
23
124
 
24
- TODO: cause there are a lot of things that I want to do
125
+ ```
126
+ Task Task Function Description
127
+
128
+ Rake rake Simple resource to just wrap the Rake CLI
129
+ RSpec rspec Run RSpec tests. Uses RSpec::Core
130
+ Rubocop rubocop Runs rubocop, loads .rubocop.yml from ./
131
+ ShellTask shelltask Runs a SH command using Mixlib::ShellOut
132
+ Echo echo Runs the Echo task.
133
+ ```
134
+
135
+ The `Echo` task does a couple of things. Take a look at the [ShellTask class](https://github.com/behance/singularity_dsl/blob/master/lib/singularity_dsl/tasks/shell_task.rb).
136
+ All `Echo` is doing is setting the shell command in the parent class to `echo "hello"` & then calling it. Nothing special here, but you can hopefully see that this opens up a lot of possibilities.
137
+
138
+ ### Builtin Tasks
139
+
140
+ **Task**
141
+
142
+ Base task that all tasks extend from. If an instance of this class is ever used, or if a child class does not define `execute`, an error is raised.
143
+
144
+ Configuration Methods | Description
145
+ ---- | ----
146
+ N/A | N/A
147
+
148
+ **Rake**
149
+
150
+ Run a rake task!
151
+
152
+ Configuration Methods | Description
153
+ ---- | ----
154
+ `target` | What Rake task to execute
155
+
156
+ **RSpec**
157
+
158
+ Run a suite of rspec tests.
159
+
160
+ Configuration Methods | Description
161
+ ---- | ----
162
+ `config_file` | Where rspec config file is
163
+ `spec_dir` | Where rspec tests are
164
+
165
+ **Rubocop**
166
+
167
+ Run rubocop.
168
+
169
+ Configuration Methods | Description
170
+ ---- | ----
171
+ `config_file` | Where Rubocop.yml is
172
+ `file` | Add a file to the list of files to run rubocop against
173
+
174
+ **ShellTask**
175
+
176
+ Run a SH task using [Mixlib::ShellOut](https://github.com/opscode/mixlib-shellout)
177
+
178
+ Configuration Methods | Description
179
+ ---- | ----
180
+ `no_fail` | Runner does not fail if this task fails to run
181
+ `command` | Shell command to execute
182
+ `alt` | Alternative shell command to execute (used in conjunction with `condition`)
183
+ `condition` | Shell command to execute. If successful, run the command set via `command`, otherwise run `alt`
184
+
185
+ ### Runstate Callbacks
186
+
187
+ These are blocks of tasks that you can run depending on the status of the runner (i.e.: whether all of your tasks succeeded in running, failed, errored, etc).
188
+
189
+ Block Name | Description
190
+ ---- | ----
191
+ `on_success` | invoked when `singularity_runner` runs everything (via `test`, `testmerge`, `batch`) successfully
192
+ `on_error` | invoked when `singularity_runner` errors out while trying to run something in your `.singularityrc`, **after** it has been processed
193
+ `on_fail` | invoked when any of your tasks error out (e.g.: shelltask returns a non-zero exit code)
194
+ `always` | always invoked **after** a `.singularityrc` run
195
+
196
+ ### Advanced Usage with `testmerge`
197
+
198
+ `singularity_runner testmerge` has a very bare-bones implementation of a git merge. Given a fork, a branch in that fork, a base_repo & base_branch, the runner will:
199
+
200
+ - merge fork:branch into base_repo:base_branch
201
+ - perform a diff between the two
202
+ - take the file list (the changeset) and inject it into a running instance of the DSL
203
+ - run the `test` command (unless the `-r` flag is given with a batch name, then it runs a batch)
204
+
205
+ Why would you do this? To conditionally execute blocks of tasks or batches based on what files changed! This can help in automating test workflows in your CI system, testing merges into trunk, etc.
206
+
207
+ But how?
208
+
209
+ ### Working with changesets from the `testmerge` command
210
+
211
+ The DSL exposes 2 methods to help you determine whether you want to execute blocks of code or not:
212
+
213
+ Method | Args | Return | Desc
214
+ ---- | ---- | ---- | ----
215
+ `files_changed?` | `String` or `Array` | `Boolean` | Performs a file extension regex match, returns true if any files in the changeset match, false otherwise
216
+ `changed_files` | `String` or `Array` | `Array` | Returns all files that have extensions that match the given values, returns an array of those files
217
+
218
+ So for example, say you only want to execute rspec tests when there are Ruby file changes. You can do something like this:
219
+
220
+ ```ruby
221
+ batch :ruby do
222
+ shelltask { command 'bundle' }
223
+ rake { target 'build_app' }
224
+ rspec
225
+ end
226
+
227
+ batch :test_merge do
228
+ if files_changed? 'js'
229
+ shelltask { command 'grunt testjs' }
230
+ end
231
+
232
+ if files_changed? 'rb'
233
+ rubocop { files changed_files('rb') }
234
+ invoke_batch :ruby
235
+ end
236
+ end
237
+ ```
238
+
239
+ Running
240
+ ```
241
+ singularity_runner testmerge git@github.com:me/repo feature-branch master git@github.com:org/repo -r test_merge
242
+ ```
243
+ Will perform the test merge & then pass ALL of the changed files in that merge into the `.singularityrc`!
25
244
 
26
245
  ## Contributing
27
246
 
@@ -34,7 +34,7 @@ module SingularityDsl
34
34
 
35
35
  def load_tasks_in_path(path)
36
36
  base_tasks = task_list
37
- files_in_path(path).each do |file|
37
+ files_in_path(path, 'rb').each do |file|
38
38
  SingularityDsl.module_eval(::File.read file)
39
39
  end
40
40
  load_tasks(task_list - base_tasks)
@@ -5,10 +5,11 @@ module SingularityDsl
5
5
  module Files
6
6
  private
7
7
 
8
- def files_in_path(path)
8
+ def files_in_path(path, extension = false)
9
9
  paths = [path] if ::File.file? path
10
10
  paths = dir_glob path if ::File.directory? path
11
11
  paths ||= []
12
+ paths = filter_ext paths, extension if extension
12
13
  paths
13
14
  end
14
15
 
@@ -16,5 +17,9 @@ module SingularityDsl
16
17
  dir = ::File.join dir, '**'
17
18
  ::Dir.glob dir
18
19
  end
20
+
21
+ def filter_ext(path_list, ext)
22
+ path_list.select { |file| file.match(/\.#{ext}$/) }
23
+ end
19
24
  end
20
25
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version const for gem
4
4
  module SingularityDsl
5
- VERSION = '1.2.8'
5
+ VERSION = '1.2.9'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singularity_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.8
4
+ version: 1.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - chr0n1x
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-29 00:00:00.000000000 Z
11
+ date: 2014-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout