deploy_pin 1.1.3 → 1.2.1

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: 46972e3ae1de0473d6bc9cfa562d1278bc4063a1023586c677edaa9bf8b47466
4
- data.tar.gz: c31626b6f0711cf7d7db14258ff4a64c1bca3b96058bf2dcbeb810eccb38fa45
3
+ metadata.gz: ea0329967282201470ee39ab8cf9bad06a025f7b9e450a48f3fda96e48433d7f
4
+ data.tar.gz: 35f10a49f28f6194f1b1e68d58f7a8958f47c1e254b6b38c56445c782e28ca0d
5
5
  SHA512:
6
- metadata.gz: 906f19ce26ce0bdd3d29b124ea5e4327f53f8ad5c24945a630a00320348263831457939155cbf1ffde7035bd334f282b74ee2adc125f23f0e5e880f9e1486f84
7
- data.tar.gz: 447c61ad0c2eddc0af71f1b2eee7cf74b65857567c631ada48e71762d599e2bff15209cc2c4f4820a58738d85fba35b75718303d3c4a45a81613ae4871845aa8
6
+ metadata.gz: ddfc115d8671ce6d5c677bf07f47f88b07eae65e845f5380c7d71caa3ee544d435dd7d773af306ccd4ab6fb1d9e0f558ac23ad37ecc46d88d43440a2c5de1d8b
7
+ data.tar.gz: dc42d8b471074663325db88614c1a51f2ce538ac377c8fee07b8f655b09cf60df34791adb0da30e8d0d2237d452e54771936009c23e68413139169f0aa062425
data/README.md CHANGED
@@ -36,9 +36,9 @@ To run all pending tasks
36
36
  rake deploy_pin:run
37
37
  ```
38
38
 
39
- ### Groupped tasks
40
- ~~~ please define allowed groups in config/initializers/deploy_pin.rb ~~~
39
+ ## Groupped tasks
41
40
 
41
+ Please define allowed groups in `config/initializers/deploy_pin.rb`
42
42
  if you want to group tasks around "allowed_group"
43
43
 
44
44
  ```bash
@@ -57,7 +57,24 @@ To run all pending tasks
57
57
  rake deploy_pin:run[allowed_group]
58
58
  ```
59
59
 
60
+ ## Run by uuid
61
+
62
+ To run some specific task by uuid
63
+ ```bash
64
+ rake deploy_pin:run[uuid_1, uuid_2]
65
+ ```
66
+ Or you can combine uuid and group
67
+ ```bash
68
+ rake deploy_pin:run[uuid, allowed_group]
69
+ ```
70
+ In case if you want to rerun task you should add exclamation mark in the end of uuid
71
+ ```bash
72
+ rake deploy_pin:run['uuid_1!', 'uuid_2!']
73
+ ```
74
+
60
75
  ## Installation
76
+
77
+
61
78
  Add this line to your application's Gemfile:
62
79
 
63
80
  ```ruby
@@ -74,7 +91,7 @@ Or install it yourself as:
74
91
  $ gem install deploy_pin
75
92
  ```
76
93
 
77
- ### then generate configuration file
94
+ then generate configuration file
78
95
  ```bash
79
96
  rails g deploy_pin:install
80
97
  ```
@@ -1,6 +1,7 @@
1
1
  require "deploy_pin/runner"
2
2
  require "deploy_pin/collector"
3
3
  require "deploy_pin/task"
4
+ require "deploy_pin/task_criteria"
4
5
  require "deploy_pin/engine"
5
6
  require "parallel"
6
7
  require "ruby-progressbar"
@@ -3,26 +3,10 @@
3
3
  # executes tasks
4
4
  module DeployPin
5
5
  class Collector
6
- attr_reader :groups
6
+ attr_reader :identifiers
7
7
 
8
- def initialize(groups:)
9
- @groups = groups
10
- end
11
-
12
- def files
13
- Dir["#{DeployPin.tasks_path}/*.rb"]
14
- end
15
-
16
- def tasks
17
- files.map do |file|
18
- task = DeployPin::Task.new(file)
19
- task.parse_file
20
-
21
- next if task.done? # task is done
22
- next unless groups.include?(task.group) # group mismatch
23
-
24
- task
25
- end.compact.sort # sort by group position in config
8
+ def initialize(identifiers:)
9
+ @identifiers = identifiers
26
10
  end
27
11
 
28
12
  def run
@@ -38,7 +22,7 @@ module DeployPin
38
22
  task.run if executable
39
23
 
40
24
  # mark each task as done
41
- task.mark
25
+ task.mark unless task.done?
42
26
  end
43
27
  end
44
28
 
@@ -56,5 +40,29 @@ module DeployPin
56
40
  task if _tasks[0..index].none? { |_task| task.eql?(_task) }
57
41
  end.compact
58
42
  end
43
+
44
+ def tasks_count
45
+ tasks.count
46
+ end
47
+
48
+ private
49
+
50
+ def files
51
+ Dir["#{DeployPin.tasks_path}/*.rb"]
52
+ end
53
+
54
+ def tasks
55
+ files.map do |file|
56
+ task = DeployPin::Task.new(file)
57
+ task.parse_file
58
+
59
+ # check if task is suitable
60
+ task if task_criteria.suitable?(task)
61
+ end.compact.sort # sort by group position in config
62
+ end
63
+
64
+ def task_criteria
65
+ @task_criteria ||= DeployPin::TaskCriteria.new(identifiers: identifiers)
66
+ end
59
67
  end
60
68
  end
@@ -3,14 +3,14 @@
3
3
  # executes tasks
4
4
  module DeployPin
5
5
  module Runner
6
- def self.run(groups:)
7
- DeployPin::Collector.new(groups: groups).run do |index, count, task, executable|
6
+ def self.run(identifiers:)
7
+ DeployPin::Collector.new(identifiers: identifiers).run do |index, count, task, executable|
8
8
  self.print("[#{index + 1}/#{count}] Task #{task.title} #{task.uuid}##{task.group} (#{executable ? 'run' : 'skip'})")
9
9
  end
10
10
  end
11
11
 
12
- def self.list(groups:)
13
- DeployPin::Collector.new(groups: groups).list do |index, count, task|
12
+ def self.list(identifiers:)
13
+ DeployPin::Collector.new(identifiers: identifiers).list do |index, count, task|
14
14
  self.print("======= Task ##{index} ========".white)
15
15
 
16
16
  # print details
@@ -26,10 +26,10 @@ module DeployPin
26
26
  end
27
27
  end
28
28
 
29
- def self.summary(groups:)
29
+ def self.summary(identifiers:)
30
30
  # print summary
31
31
  self.print("======= Summary ========")
32
- self.print("tasks number: #{DeployPin::Collector.new(groups: groups).tasks.count}")
32
+ self.print("tasks number: #{DeployPin::Collector.new(identifiers: identifiers).tasks_count}")
33
33
  end
34
34
 
35
35
  def self.print(msg)
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # check task criteria
4
+ module DeployPin
5
+ class TaskCriteria
6
+ SKIP_REGEXEP = /\A-(.+[^!])\z/
7
+ FORCE_REGEXP = /\A([^-].+)!\z/
8
+ COMMON_REGEXP = /(^[^-]*.+[^!]*$)/
9
+
10
+ attr_reader :identifiers
11
+
12
+ def initialize(identifiers:)
13
+ @identifiers = identifiers
14
+ end
15
+
16
+ def suitable?(task)
17
+ task_cover = ->(task, regexp) {
18
+ items = identifiers.flat_map {|x| x.to_s.scan(regexp) }.flatten
19
+
20
+ items & [task.group, task.uuid]
21
+ }
22
+
23
+ return false if task_cover.(task, SKIP_REGEXEP).any?
24
+ return true if task_cover.(task, FORCE_REGEXP).any?
25
+
26
+ task_cover.(task, COMMON_REGEXP).any? && !task.done?
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module DeployPin
2
- VERSION = '1.1.3'
2
+ VERSION = '1.2.1'
3
3
  end
@@ -1,13 +1,13 @@
1
1
  namespace :deploy_pin do
2
2
  desc "run pending tasks"
3
- task :run, [:groups] => :environment do |t, args|
4
- args.with_defaults(groups: DeployPin.groups)
3
+ task :run, [:identifiers] => :environment do |t, args|
4
+ args.with_defaults(identifiers: DeployPin.groups)
5
5
 
6
6
  DeployPin::Runner.run(args)
7
7
  end
8
8
 
9
- task :list, [:groups] => :environment do |t, args|
10
- args.with_defaults(groups: DeployPin.groups)
9
+ task :list, [:identifiers] => :environment do |t, args|
10
+ args.with_defaults(identifiers: DeployPin.groups)
11
11
 
12
12
  DeployPin::Runner.list(args)
13
13
  DeployPin::Runner.summary(args)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deploy_pin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - rafael
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-09 00:00:00.000000000 Z
11
+ date: 2019-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -193,6 +193,7 @@ files:
193
193
  - lib/deploy_pin/engine.rb
194
194
  - lib/deploy_pin/runner.rb
195
195
  - lib/deploy_pin/task.rb
196
+ - lib/deploy_pin/task_criteria.rb
196
197
  - lib/deploy_pin/version.rb
197
198
  - lib/generators/deploy_pin/install/USAGE
198
199
  - lib/generators/deploy_pin/install/install_generator.rb
@@ -223,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
224
  - !ruby/object:Gem::Version
224
225
  version: '0'
225
226
  requirements: []
226
- rubygems_version: 3.0.2
227
+ rubygems_version: 3.0.6
227
228
  signing_key:
228
229
  specification_version: 4
229
230
  summary: pin some task around deployment