deploy_pin 1.0.4 → 1.1.0
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/README.md +1 -0
- data/lib/deploy_pin/collector.rb +50 -0
- data/lib/deploy_pin/runner.rb +19 -30
- data/lib/deploy_pin/task.rb +42 -13
- data/lib/deploy_pin/version.rb +1 -1
- data/lib/deploy_pin.rb +2 -0
- data/lib/generators/deploy_pin/install/templates/deploy_pin.rb +2 -2
- data/lib/generators/deploy_pin/task/templates/parallel_task.rb.erb +1 -5
- data/lib/generators/deploy_pin/task/templates/task.rb.erb +1 -7
- data/lib/tasks/deploy_pin_tasks.rake +1 -0
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 659cf4687485ab93ec0b463064d347ffaaeb18625e63d916047c372c15e01b0d
|
4
|
+
data.tar.gz: '0797eb2b2baf73f3bdc699c257dea2a18210d93d7f892926041558a793e296c7'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47128a423ef37a1535fd9637ae0d327df547a48d9bdfffe668c7881b1cd96fc904948d264cff825bffe58a17415dbb4de1d97a77fcd713ee43ac3188a5502c94
|
7
|
+
data.tar.gz: e70850c635689e803d07c14289597bf466aa123f9162c23a70781a4f9e788fd4441db4abcc5bceb9f6e65849ecdca8689fd4944f9f338fae825e33dae7dfdcf8
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
[](https://badge.fury.io/rb/deploy_pin)
|
2
|
+

|
2
3
|
[](https://travis-ci.org/skcc321/deploy_pin)
|
3
4
|
[](https://codeclimate.com/github/skcc321/deploy_pin/maintainability)
|
4
5
|
[](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
|
data/lib/deploy_pin/runner.rb
CHANGED
@@ -4,43 +4,32 @@
|
|
4
4
|
module DeployPin
|
5
5
|
module Runner
|
6
6
|
def self.run(groups:)
|
7
|
-
|
8
|
-
|
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
|
-
|
17
|
-
puts
|
18
|
-
|
19
|
-
|
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.
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
data/lib/deploy_pin/task.rb
CHANGED
@@ -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
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
49
|
+
{
|
50
|
+
uuid: uuid,
|
51
|
+
group: group,
|
52
|
+
title: title
|
53
|
+
}
|
31
54
|
end
|
32
55
|
|
33
|
-
|
34
|
-
|
35
|
-
group_index <=> task_b.group_index
|
56
|
+
def eql?(task_b)
|
57
|
+
script == task_b.script
|
36
58
|
end
|
37
59
|
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
data/lib/deploy_pin/version.rb
CHANGED
data/lib/deploy_pin.rb
CHANGED
@@ -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 %>")
|
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
|
+
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-
|
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
|
-
|
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
|