deploy_pin 1.0.4 → 1.1.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: 5dc4d23b4c55d02c475eb9d557750af92c09c7aada2673ff42419ed86d1dc7be
4
- data.tar.gz: 2d1a28450273d9d88e85756c2e1e85a49d5c3f7e9faf98612e395080c144c153
3
+ metadata.gz: 659cf4687485ab93ec0b463064d347ffaaeb18625e63d916047c372c15e01b0d
4
+ data.tar.gz: '0797eb2b2baf73f3bdc699c257dea2a18210d93d7f892926041558a793e296c7'
5
5
  SHA512:
6
- metadata.gz: 0251a330a53102637a20b08feee13bbdde2eafa88b9c2278fe93eabefa1bedf7a05ff9b2ba6a9974703607a5ea3b708d02159df13b593817339c49960e7eccb3
7
- data.tar.gz: 4161069f4c5f477bfff9398469ccda0a4479a05d86aeeea45adf72979a1fd4d95c3d8500c0336230ae593eb408260f9923ad1bdf40c729bf1d708f9518027086
6
+ metadata.gz: 47128a423ef37a1535fd9637ae0d327df547a48d9bdfffe668c7881b1cd96fc904948d264cff825bffe58a17415dbb4de1d97a77fcd713ee43ac3188a5502c94
7
+ data.tar.gz: e70850c635689e803d07c14289597bf466aa123f9162c23a70781a4f9e788fd4441db4abcc5bceb9f6e65849ecdca8689fd4944f9f338fae825e33dae7dfdcf8
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/deploy_pin.svg)](https://badge.fury.io/rb/deploy_pin)
2
+ ![](https://ruby-gem-downloads-badge.herokuapp.com/deploy_pin)
2
3
  [![Build Status](https://travis-ci.org/skcc321/deploy_pin.svg?branch=master)](https://travis-ci.org/skcc321/deploy_pin)
3
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/c0a9ca97c1f9c0478ffc/maintainability)](https://codeclimate.com/github/skcc321/deploy_pin/maintainability)
4
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/c0a9ca97c1f9c0478ffc/test_coverage)](https://codeclimate.com/github/skcc321/deploy_pin/test_coverage)
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # executes tasks
4
+ module DeployPin
5
+ class Collector
6
+ attr_reader :groups
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
26
+ end
27
+
28
+ def run
29
+ count = tasks.count
30
+
31
+ tasks.each_with_index do |task, index|
32
+ yield(index, count, task)
33
+
34
+ # run only uniq tasks
35
+ task.run if tasks.none? { |_task| task.eql?(_task) }
36
+
37
+ # mark each task as done
38
+ task.mark
39
+ end
40
+ end
41
+
42
+ def list
43
+ count = tasks.count
44
+
45
+ tasks.each_with_index do |task, index|
46
+ yield(index, count, task)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -4,43 +4,32 @@
4
4
  module DeployPin
5
5
  module Runner
6
6
  def self.run(groups:)
7
- tasks = pending(groups: groups)
8
- tasks.each_with_index do |task, index|
9
- puts "[#{index + 1}/#{tasks.count}] Task UUID #{task.uuid}"
10
- task.run
11
- puts ""
7
+ DeployPin::Collector.new(groups: groups).run do |index, count, task|
8
+ puts("[#{index + 1}/#{count}] Task #{task.title} #{task.uuid}##{task.group}")
12
9
  end
13
10
  end
14
11
 
15
12
  def self.list(groups:)
16
- pending(groups: groups).each_with_index do |task, index|
17
- puts "======= Task ##{index} ========"
18
- puts task.script
19
- puts ""
13
+ DeployPin::Collector.new(groups: groups).list do |index, count, task|
14
+ puts("======= Task ##{index} ========".white)
15
+
16
+ # print details
17
+ task.details.each do |key, value|
18
+ puts "#{key}:\t\t#{value}"
19
+ end
20
+
21
+ puts("")
22
+ puts("<<<")
23
+ puts task.script.strip.green
24
+ puts(">>>")
25
+ puts("")
20
26
  end
21
-
22
- puts "======= summary ========"
23
- puts "tasks number: #{pending(groups: groups).count}"
24
27
  end
25
28
 
26
- def self.pending(groups:)
27
- files = Dir["#{DeployPin.tasks_path}/*.rb"]
28
-
29
- # get done records uuids
30
- records = DeployPin::Record.pluck(:uuid)
31
-
32
- files.map do |file|
33
- task = DeployPin::Task.new(file)
34
- task.parse_file
35
-
36
- # task is done
37
- next if records.include?(task.uuid)
38
-
39
- # group mismatch
40
- next unless groups.include?(task.group)
41
-
42
- task
43
- end.compact.sort # sort by group position in config
29
+ def self.summary(groups:)
30
+ # print summary
31
+ puts("======= summary ========")
32
+ puts("tasks number: #{DeployPin::Collector.new(groups: groups).tasks.count}")
44
33
  end
45
34
  end
46
35
  end
@@ -4,39 +4,68 @@
4
4
  module DeployPin
5
5
  class Task
6
6
  attr_reader :file,
7
- :group,
8
7
  :uuid,
8
+ :group,
9
+ :title,
9
10
  :script
10
11
 
11
12
  def initialize(file)
12
13
  @file = file
13
14
  @uuid = nil
14
15
  @group = nil
16
+ @title = ""
15
17
  @script = ""
16
18
  end
17
19
 
18
20
  def run
19
- eval(@script)
21
+ # eval script
22
+ eval(script)
23
+ end
24
+
25
+ def mark
26
+ # store record in the DB
27
+ DeployPin::Record.create(uuid: uuid)
28
+ end
29
+
30
+ def done?
31
+ DeployPin::Record.where(uuid: uuid).exists?
20
32
  end
21
33
 
22
34
  def parse_file
23
- @script = File.read(file)
24
- @script.lines[0] =~ /\A# (\d+):(\w+)/
25
- @uuid = $1
26
- @group = $2
35
+ File.foreach(file) do |line|
36
+ case line.strip
37
+ when /\A# (\d+):(\w+)/
38
+ @uuid = $1
39
+ @group = $2
40
+ when /\A# task_title:(.+)/
41
+ @title = $1.strip
42
+ when /\A[^#].*/
43
+ @script += line
44
+ end
45
+ end
27
46
  end
28
47
 
29
48
  def details
30
- puts @uuid, @group, @script
49
+ {
50
+ uuid: uuid,
51
+ group: group,
52
+ title: title
53
+ }
31
54
  end
32
55
 
33
- # for sorting
34
- def <=>(task_b)
35
- group_index <=> task_b.group_index
56
+ def eql?(task_b)
57
+ script == task_b.script
36
58
  end
37
59
 
38
- def group_index
39
- DeployPin.groups.index(group)
40
- end
60
+ protected
61
+
62
+ # for sorting
63
+ def <=>(task_b)
64
+ group_index <=> task_b.group_index
65
+ end
66
+
67
+ def group_index
68
+ DeployPin.groups.index(group)
69
+ end
41
70
  end
42
71
  end
@@ -1,3 +1,3 @@
1
1
  module DeployPin
2
- VERSION = '1.0.4'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/deploy_pin.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require "deploy_pin/runner"
2
+ require "deploy_pin/collector"
2
3
  require "deploy_pin/task"
3
4
  require "deploy_pin/engine"
4
5
  require "parallel"
5
6
  require "ruby-progressbar"
7
+ require "colorize"
6
8
 
7
9
  module DeployPin
8
10
  OPTIONS = %i(
@@ -2,6 +2,6 @@
2
2
 
3
3
  DeployPin.setup do
4
4
  tasks_path "lib/deploy_pin"
5
- groups ["post_script"]
6
- fallback_group "post_script"
5
+ groups ["I", "II", "III"]
6
+ fallback_group "II"
7
7
  end
@@ -1,4 +1,5 @@
1
1
  # <%= @uuid %>:<%= group %>
2
+ # task_title: super duper task
2
3
 
3
4
  # === parallel task code goes down here ===
4
5
  10.times { DeployPin::Record.create(uuid: "hello") }
@@ -9,8 +10,3 @@ Parallel.each(DeployPin::Record.where(uuid: "hello"), progress: "Doing stuff") d
9
10
  end
10
11
  sleep(0.2)
11
12
  end
12
-
13
-
14
-
15
- # Create record in the DB to avoid multiple execution
16
- DeployPin::Record.create(uuid: "<%= @uuid %>")
@@ -1,13 +1,7 @@
1
1
  # <%= @uuid %>:<%= group %>
2
+ # task_title: super duper task
2
3
 
3
4
  # === task code goes down here ===
4
5
  progressbar = ProgressBar.create(title: "Doing stuff", total: 20, format: '%t |%E | %B | %a')
5
6
 
6
7
  20.times { progressbar.increment; sleep(0.2) }
7
-
8
-
9
-
10
-
11
-
12
- # Create record in the DB to avoid multiple execution
13
- DeployPin::Record.create(uuid: "<%= @uuid %>")
@@ -10,5 +10,6 @@ namespace :deploy_pin do
10
10
  args.with_defaults(groups: DeployPin.groups)
11
11
 
12
12
  DeployPin::Runner.list(args)
13
+ DeployPin::Runner.summary(args)
13
14
  end
14
15
  end
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.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rafael
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-28 00:00:00.000000000 Z
11
+ date: 2019-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: 12.3.2
75
+ - !ruby/object:Gem::Dependency
76
+ name: colorize
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: simplecov
77
91
  requirement: !ruby/object:Gem::Requirement
@@ -175,6 +189,7 @@ files:
175
189
  - app/models/deploy_pin/application_record.rb
176
190
  - app/models/deploy_pin/record.rb
177
191
  - lib/deploy_pin.rb
192
+ - lib/deploy_pin/collector.rb
178
193
  - lib/deploy_pin/engine.rb
179
194
  - lib/deploy_pin/runner.rb
180
195
  - lib/deploy_pin/task.rb
@@ -208,7 +223,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
223
  - !ruby/object:Gem::Version
209
224
  version: '0'
210
225
  requirements: []
211
- rubygems_version: 3.0.2
226
+ rubyforge_project:
227
+ rubygems_version: 2.7.6
212
228
  signing_key:
213
229
  specification_version: 4
214
230
  summary: pin some task around deployment