itamae 1.9.13 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d31a078719d6c81a81538a9018dd038502f5b70b05918927bc3a97e6afdf8ebb
4
- data.tar.gz: 23e7489bd095e53a783be646ba54c9d88dad035eb00248528126fb35f03a50ac
3
+ metadata.gz: 3c8a12f995297dabd31b3252f40b6dd38f0cc9238ca9653a7884d4d0e821824d
4
+ data.tar.gz: caf697caf3d0f628b6dc1beffe697c6b97b247cfbb1a711674e44f14c8830dab
5
5
  SHA512:
6
- metadata.gz: a00853cae59ed87678e3351a3888d352c372c03d8cd6ebbe1491df525648440efb69ed8c67611dce68a41681ea8782d263feec21b87c229df5d646bfb16997c8
7
- data.tar.gz: c5315707855dce49e9470a6c9723ecb537fd1b117cc29ea755bf023c320fe5aedb2d1d1882e173509cf68ed1e502c9728451471bb810ea4bbdf520ccb2f2e63b
6
+ metadata.gz: 34c6c6d4b83792d9fbe733c8d0ba82ca770d9b194340800ad9afcd9cd33682313458c814f80c80bac3f25389e3dce60132f23da21b8b66032ee08ab850b6dd9e
7
+ data.tar.gz: 69bce9ffc7feb0528027d3af15a9127799dffd775a4f9c07dc72a0a98ed6d04fbbd8a8eb13d9fb0d4fbc6b55d4f032d7be51fee365ddb70cfb71de459010f1fc
@@ -1,8 +1,15 @@
1
1
  ## Unreleased
2
- [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.9.12...master)
2
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.10.0...master)
3
+
4
+ ## v1.10.0
5
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.9.13...v1.10.0)
6
+
7
+ Features
8
+
9
+ - [Support `only_if` and `not_if` inside a `define`](https://github.com/itamae-kitchen/itamae/pull/271)
3
10
 
4
11
  ## v1.9.13
5
- [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.9.11...v1.9.12)
12
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.9.12...v1.9.13)
6
13
 
7
14
  Bugfixes
8
15
 
@@ -161,6 +161,18 @@ module Itamae
161
161
  context.instance_eval(&@definition.class.definition_block)
162
162
  end
163
163
 
164
+ def run
165
+ if @definition.do_not_run_because_of_only_if?
166
+ Itamae.logger.debug "#{@definition.resource_type}[#{@definition.resource_name}] Execution skipped because of only_if attribute"
167
+ return
168
+ elsif @definition.do_not_run_because_of_not_if?
169
+ Itamae.logger.debug "#{@definition.resource_type}[#{@definition.resource_name}] Execution skipped because of not_if attribute"
170
+ return
171
+ end
172
+
173
+ super
174
+ end
175
+
164
176
  private
165
177
 
166
178
  def show_banner
@@ -160,6 +160,16 @@ module Itamae
160
160
  self.class.name.split("::").last.scan(/[A-Z][^A-Z]+/).map(&:downcase).join('_')
161
161
  end
162
162
 
163
+ def do_not_run_because_of_only_if?
164
+ @only_if_command &&
165
+ run_command(@only_if_command, error: false).exit_status != 0
166
+ end
167
+
168
+ def do_not_run_because_of_not_if?
169
+ @not_if_command &&
170
+ run_command(@not_if_command, error: false).exit_status == 0
171
+ end
172
+
163
173
  private
164
174
 
165
175
  alias_method :current, :current_attributes
@@ -270,16 +280,6 @@ module Itamae
270
280
  end
271
281
  end
272
282
 
273
- def do_not_run_because_of_only_if?
274
- @only_if_command &&
275
- run_command(@only_if_command, error: false).exit_status != 0
276
- end
277
-
278
- def do_not_run_because_of_not_if?
279
- @not_if_command &&
280
- run_command(@not_if_command, error: false).exit_status == 0
281
- end
282
-
283
283
  def backend
284
284
  runner.backend
285
285
  end
@@ -1,3 +1,3 @@
1
1
  module Itamae
2
- VERSION = "1.9.13"
2
+ VERSION = "1.10.0"
3
3
  end
@@ -227,6 +227,42 @@ describe file('/tmp/remote_file_in_definition') do
227
227
  its(:content) { should eq("definition_example\n") }
228
228
  end
229
229
 
230
+ describe file('/tmp/created_by_definition_2_created') do
231
+ it { should be_file }
232
+ its(:content) { should eq("name:created,key:value2,message:Hello, Itamae\n") }
233
+ end
234
+
235
+ describe file('/tmp/remote_file_in_definition_2_created') do
236
+ it { should be_file }
237
+ its(:content) { should eq("definition_example_2\n") }
238
+ end
239
+
240
+ describe file('/tmp/created_by_definition_2_not_created') do
241
+ it { should_not exist }
242
+ end
243
+
244
+ describe file('/tmp/remote_file_in_definition_2_not_created') do
245
+ it { should_not exist }
246
+ end
247
+
248
+ describe file('/tmp/created_by_definition_3_created') do
249
+ it { should be_file }
250
+ its(:content) { should eq("name:created,key:value3,message:Hello, Itamae\n") }
251
+ end
252
+
253
+ describe file('/tmp/remote_file_in_definition_3_created') do
254
+ it { should be_file }
255
+ its(:content) { should eq("definition_example_3\n") }
256
+ end
257
+
258
+ describe file('/tmp/created_by_definition_3_not_created') do
259
+ it { should_not exist }
260
+ end
261
+
262
+ describe file('/tmp/remote_file_in_definition_3_not_created') do
263
+ it { should_not exist }
264
+ end
265
+
230
266
  describe file('/tmp/multi_delayed_notifies') do
231
267
  it { should be_file }
232
268
  its(:content) { should eq("1\n2\n3\n4\n") }
@@ -342,6 +342,28 @@ definition_example "name" do
342
342
  key 'value'
343
343
  end
344
344
 
345
+ execute "touch /tmp/trigger_for_definition_example_2"
346
+
347
+ definition_example_2 "created" do
348
+ key "value2"
349
+ only_if "test -f /tmp/trigger_for_definition_example_2"
350
+ end
351
+
352
+ definition_example_2 "not_created" do
353
+ key "value2"
354
+ not_if "test -f /tmp/trigger_for_definition_example_2"
355
+ end
356
+
357
+ definition_example_3 "created" do
358
+ key "value3"
359
+ not_if "test -f /tmp/this_file_is_not_exists"
360
+ end
361
+
362
+ definition_example_3 "not_created" do
363
+ key "value3"
364
+ only_if "test -f /tmp/this_file_is_not_exists"
365
+ end
366
+
345
367
  #####
346
368
 
347
369
  file "/tmp/never_exist4" do
@@ -4,3 +4,18 @@ define :definition_example, key: 'default' do
4
4
  remote_file "/tmp/remote_file_in_definition"
5
5
  end
6
6
 
7
+ define :definition_example_2, key: 'default' do
8
+ execute "echo 'name:#{params[:name]},key:#{params[:key]},message:#{node[:message]}' > /tmp/created_by_definition_2_#{params[:name]}"
9
+
10
+ remote_file "/tmp/remote_file_in_definition_2_#{params[:name]}" do
11
+ source "files/remote_file_in_definition_2"
12
+ end
13
+ end
14
+
15
+ define :definition_example_3, key: 'default' do
16
+ execute "echo 'name:#{params[:name]},key:#{params[:key]},message:#{node[:message]}' > /tmp/created_by_definition_3_#{params[:name]}"
17
+
18
+ remote_file "/tmp/remote_file_in_definition_3_#{params[:name]}" do
19
+ source "files/remote_file_in_definition_3"
20
+ end
21
+ end
@@ -14,3 +14,10 @@ set :docker_container, ENV["DOCKER_CONTAINER"]
14
14
 
15
15
  # Set PATH
16
16
  # set :path, '/sbin:/usr/local/sbin:$PATH'
17
+
18
+ RSpec.configure do |config|
19
+ unless ENV["CI"]
20
+ # focus is enabled only local (Run all specs at CI)
21
+ config.filter_run_when_matching :focus
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.13
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-10-22 00:00:00.000000000 Z
13
+ date: 2018-11-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
@@ -274,6 +274,8 @@ files:
274
274
  - spec/integration/recipes/default2.rb
275
275
  - spec/integration/recipes/define/default.rb
276
276
  - spec/integration/recipes/define/files/remote_file_in_definition
277
+ - spec/integration/recipes/define/files/remote_file_in_definition_2
278
+ - spec/integration/recipes/define/files/remote_file_in_definition_3
277
279
  - spec/integration/recipes/dry_run.rb
278
280
  - spec/integration/recipes/files/empty_file
279
281
  - spec/integration/recipes/files/remote_file_auto
@@ -330,6 +332,8 @@ test_files:
330
332
  - spec/integration/recipes/default2.rb
331
333
  - spec/integration/recipes/define/default.rb
332
334
  - spec/integration/recipes/define/files/remote_file_in_definition
335
+ - spec/integration/recipes/define/files/remote_file_in_definition_2
336
+ - spec/integration/recipes/define/files/remote_file_in_definition_3
333
337
  - spec/integration/recipes/dry_run.rb
334
338
  - spec/integration/recipes/files/empty_file
335
339
  - spec/integration/recipes/files/remote_file_auto