git-restart 0.0.1.pre.dev → 0.0.1
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/bin/git-restart +11 -3
- data/lib/git-restart/runner.rb +48 -16
- data/lib/git-restart/task.rb +38 -9
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2731a1fddf96cb0555902773ea66010ae28ec5a
|
4
|
+
data.tar.gz: ba700b8d5c346ac619ff1f848706b4d7f3e8a7b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e58995f9e245b556d013fd96044fd30372e8bb823ec2c13f17c8e1c7890421b0e1766e255dfb08a3620191c4f58dcc0973f66cc9b10e649946d834b1ec8b5b70
|
7
|
+
data.tar.gz: 760c16c44d23c4e54e586e6969682e9b8079dbd600c12197e5e60dc1d90b3810fcf3833e039c85acee28d02dfb54a88edc7bca47faa2e19fc4dfdde615016fd2
|
data/bin/git-restart
CHANGED
@@ -5,10 +5,18 @@ require 'git-restart/runner.rb'
|
|
5
5
|
|
6
6
|
puts "Starting runner ..."
|
7
7
|
|
8
|
-
|
8
|
+
$taskfiles = Array.new();
|
9
|
+
target = ".gitrun"
|
10
|
+
ARGV.each do |t|
|
11
|
+
if(File.extname(t) == ".gitrun")
|
12
|
+
target = t;
|
13
|
+
elsif(File.extname(t) == ".gittask")
|
14
|
+
$taskfiles << t;
|
15
|
+
end
|
16
|
+
end
|
9
17
|
|
10
|
-
raise ArgumentError, "No valid
|
18
|
+
raise ArgumentError, "No valid runner file specified!" unless File.exist? target
|
11
19
|
|
12
20
|
load target
|
13
21
|
|
14
|
-
GitRestart::Task.runner.mqtt.
|
22
|
+
GitRestart::Task.runner.mqtt.lockAndListen
|
data/lib/git-restart/runner.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
|
2
2
|
require 'mqtt/sub_handler'
|
3
|
+
|
3
4
|
require 'git'
|
5
|
+
require 'octokit'
|
4
6
|
|
5
7
|
require_relative "task.rb"
|
6
8
|
|
@@ -9,12 +11,16 @@ module GitRestart
|
|
9
11
|
attr_accessor :name
|
10
12
|
|
11
13
|
attr_accessor :repo, :branches, :exclude_branches, :start_on
|
14
|
+
attr_accessor :allowed_tasks
|
12
15
|
|
13
16
|
attr_reader :next_tasks
|
14
17
|
attr_reader :current_task_file
|
15
18
|
|
19
|
+
attr_reader :mqtt
|
20
|
+
attr_accessor :octokit
|
21
|
+
|
16
22
|
def current_commit()
|
17
|
-
@git.object("HEAD
|
23
|
+
@git.object("HEAD").sha;
|
18
24
|
end
|
19
25
|
def current_branch()
|
20
26
|
@git.current_branch();
|
@@ -23,9 +29,15 @@ module GitRestart
|
|
23
29
|
@current_modified;
|
24
30
|
end
|
25
31
|
|
26
|
-
def initialize()
|
32
|
+
def initialize(fileList = nil)
|
33
|
+
raise ArgumentError, "File list needs to be nil or an Array!" unless (fileList.is_a? Array or fileList.nil?)
|
34
|
+
|
27
35
|
GitRestart::Task.runner = self;
|
28
36
|
|
37
|
+
@allowed_tasks = Array.new();
|
38
|
+
@allowed_tasks << fileList if(fileList);
|
39
|
+
@allowed_tasks << $taskfiles unless($taskfiles.empty?)
|
40
|
+
|
29
41
|
@current_tasks = Hash.new();
|
30
42
|
@next_tasks = Hash.new();
|
31
43
|
|
@@ -38,16 +50,15 @@ module GitRestart
|
|
38
50
|
|
39
51
|
yield(self);
|
40
52
|
|
53
|
+
@allowed_tasks.flatten!
|
54
|
+
|
41
55
|
@listenedSub = @mqtt.subscribe_to "GitHub/#{@repo}" do |data|
|
42
|
-
puts "Received data: #{data}"
|
43
56
|
begin
|
44
57
|
data = JSON.parse(data, symbolize_names: true);
|
45
58
|
rescue
|
46
59
|
next;
|
47
60
|
end
|
48
61
|
|
49
|
-
puts "Processing data #{data}"
|
50
|
-
|
51
62
|
next unless data[:branch];
|
52
63
|
if(not @branches.empty?)
|
53
64
|
next unless @branches.include? data[:branch];
|
@@ -55,16 +66,29 @@ module GitRestart
|
|
55
66
|
next if @exclude_branches.include? data[:branch];
|
56
67
|
end
|
57
68
|
|
58
|
-
puts "Queueing data!"
|
59
|
-
|
60
69
|
@branchQueue << data;
|
61
70
|
end
|
62
71
|
|
63
72
|
autostart();
|
64
73
|
_start_task_thread();
|
74
|
+
|
75
|
+
at_exit {
|
76
|
+
_stop_all_tasks();
|
77
|
+
}
|
65
78
|
end
|
66
79
|
|
67
80
|
def update_status(name, newStatus, message = nil)
|
81
|
+
puts "Task #{@name} assumed a new status: #{newStatus}#{message ? " MSG:#{message}" : ""}"
|
82
|
+
|
83
|
+
return unless @octokit;
|
84
|
+
|
85
|
+
begin
|
86
|
+
@octokit.create_status(@repo, current_commit(), newStatus, {
|
87
|
+
context: "#{@name}/#{name}".gsub(" ", "_"),
|
88
|
+
description: message,
|
89
|
+
})
|
90
|
+
rescue
|
91
|
+
end
|
68
92
|
end
|
69
93
|
|
70
94
|
def _start_task_thread()
|
@@ -72,8 +96,6 @@ module GitRestart
|
|
72
96
|
loop do
|
73
97
|
newData = @branchQueue.pop;
|
74
98
|
|
75
|
-
puts "Popped data: #{newData}"
|
76
|
-
|
77
99
|
@current_modified = newData[:touched];
|
78
100
|
_switch_to(newData[:branch], newData[:head_commit]);
|
79
101
|
end
|
@@ -106,23 +128,28 @@ module GitRestart
|
|
106
128
|
t.gsub!(/^\.\//,"");
|
107
129
|
@current_task_file = t;
|
108
130
|
|
109
|
-
|
131
|
+
unless(@allowed_tasks.empty?)
|
132
|
+
next unless @allowed_tasks.include? @current_task_file
|
133
|
+
end
|
134
|
+
|
110
135
|
begin
|
111
136
|
load(t);
|
112
137
|
rescue ScriptError, StandardError
|
138
|
+
update_status("File #{t}", :failure, "File could not be parsed!")
|
113
139
|
puts("File #{t} could not be loaded!");
|
114
140
|
rescue GitRestart::TaskValidityError
|
141
|
+
update_status("File #{t}", :failure, "Task-file not configured properly!")
|
115
142
|
puts("Task-File #{t} is not configured properly!");
|
116
143
|
end
|
117
144
|
end
|
118
145
|
|
119
|
-
puts "Finished loading! Next tasks
|
146
|
+
puts "Finished loading! Next tasks: #{@next_tasks.keys}"
|
120
147
|
end
|
121
148
|
|
122
149
|
def _start_next_tasks()
|
123
150
|
_generate_next_tasks();
|
124
151
|
|
125
|
-
puts "
|
152
|
+
puts "\nStarting next tasks!"
|
126
153
|
@next_tasks.each do |name, t|
|
127
154
|
next unless t.active;
|
128
155
|
next unless t.triggered?
|
@@ -133,19 +160,24 @@ module GitRestart
|
|
133
160
|
end
|
134
161
|
|
135
162
|
def _switch_to(branch, commit = nil)
|
136
|
-
puts "
|
137
|
-
|
163
|
+
puts "\n\nSwitching to branch: #{branch}#{commit ? ",commit: #{commit}" : ""}"
|
164
|
+
|
165
|
+
begin
|
166
|
+
@git.fetch();
|
167
|
+
rescue
|
168
|
+
end
|
138
169
|
|
139
170
|
if(branch != current_branch())
|
140
171
|
_stop_all_tasks();
|
141
172
|
else
|
142
173
|
_stop_triggered_tasks();
|
143
174
|
end
|
175
|
+
@git.reset_hard();
|
144
176
|
@git.checkout(branch);
|
145
|
-
@git.reset_hard(commit);
|
146
|
-
|
147
177
|
@git.merge("origin/#{branch}");
|
148
178
|
|
179
|
+
@git.reset_hard(commit);
|
180
|
+
|
149
181
|
_start_next_tasks();
|
150
182
|
end
|
151
183
|
|
data/lib/git-restart/task.rb
CHANGED
@@ -17,8 +17,6 @@ module GitRestart
|
|
17
17
|
attr_reader :lastStatus
|
18
18
|
attr_reader :status_message
|
19
19
|
|
20
|
-
attr_reader :mqtt
|
21
|
-
|
22
20
|
def self.runner=(runner)
|
23
21
|
@runner = runner;
|
24
22
|
end
|
@@ -32,6 +30,9 @@ module GitRestart
|
|
32
30
|
def branch()
|
33
31
|
runner().current_branch();
|
34
32
|
end
|
33
|
+
def current_commit()
|
34
|
+
runner().current_commit();
|
35
|
+
end
|
35
36
|
def modified()
|
36
37
|
runner().current_modified();
|
37
38
|
end
|
@@ -69,6 +70,8 @@ module GitRestart
|
|
69
70
|
|
70
71
|
valid?
|
71
72
|
|
73
|
+
@status_file ||= "/tmp/TaskLog_#{@name}_#{current_commit()}";
|
74
|
+
|
72
75
|
if(runner().next_tasks[@name])
|
73
76
|
raise TaskValidityError, "A task of name #{@name} already exists!"
|
74
77
|
else
|
@@ -82,8 +85,12 @@ module GitRestart
|
|
82
85
|
|
83
86
|
@watched.each do |regEx|
|
84
87
|
modified().each do |f|
|
85
|
-
|
86
|
-
|
88
|
+
if regEx.to_s =~ /^\(\?\-mix:\\\/(.*)\)$/ then
|
89
|
+
return true if f =~ Regexp.new($1);
|
90
|
+
else
|
91
|
+
next unless f =~ /#{Regexp.quote(@chdir)}(.*)/
|
92
|
+
return true if $1 =~ regEx;
|
93
|
+
end
|
87
94
|
end
|
88
95
|
end
|
89
96
|
|
@@ -100,21 +107,39 @@ module GitRestart
|
|
100
107
|
end
|
101
108
|
end
|
102
109
|
|
110
|
+
def _rm_logfile()
|
111
|
+
if File.exist?("/tmp/TaskLog_#{@name}_#{current_commit()}") then
|
112
|
+
File.delete("/tmp/TaskLog_#{@name}_#{current_commit()}");
|
113
|
+
end
|
114
|
+
end
|
115
|
+
def _get_statusline()
|
116
|
+
return "No status specified" unless File.exist? @status_file
|
117
|
+
|
118
|
+
sMsg = ""
|
119
|
+
File.open(@status_file, "r") do |sFile|
|
120
|
+
sFile.each_line do |l| sMsg = l; end
|
121
|
+
end
|
122
|
+
|
123
|
+
return sMsg;
|
124
|
+
end
|
125
|
+
|
103
126
|
def _report_status(status, message = nil)
|
104
|
-
|
127
|
+
message ||= _get_statusline();
|
128
|
+
@status_message = message;
|
105
129
|
|
106
130
|
return unless @report_status
|
107
131
|
|
108
132
|
runner().update_status(@name, status, message);
|
109
|
-
puts "Task #{@name} assumed a new status: #{status}#{message ? " MSG:#{message}" : ""}"
|
110
133
|
end
|
111
134
|
private :_report_status
|
112
135
|
|
113
136
|
def start()
|
114
137
|
puts "Starting Task: #{@name}"
|
115
138
|
|
116
|
-
|
117
|
-
|
139
|
+
if @targets.empty?
|
140
|
+
_report_status(:success, "No tasks to run!");
|
141
|
+
return
|
142
|
+
end
|
118
143
|
|
119
144
|
@executionThread = Thread.new do
|
120
145
|
_report_status(:pending);
|
@@ -122,8 +147,9 @@ module GitRestart
|
|
122
147
|
@targets.each do |target|
|
123
148
|
@statuschange_mutex.synchronize {
|
124
149
|
break if @exiting
|
150
|
+
_rm_logfile();
|
125
151
|
options = {
|
126
|
-
[:
|
152
|
+
[:out, :err] => "/tmp/TaskLog_#{@name}_#{current_commit()}"
|
127
153
|
}
|
128
154
|
options[:chdir] = @chdir if @chdir
|
129
155
|
|
@@ -139,11 +165,14 @@ module GitRestart
|
|
139
165
|
|
140
166
|
if(@lastStatus == 0)
|
141
167
|
_report_status(:success);
|
168
|
+
_rm_logfile();
|
142
169
|
elsif(!@exiting || @expect_clean_exit)
|
143
170
|
_report_status(:failure);
|
144
171
|
end
|
145
172
|
end
|
146
173
|
@executionThread.abort_on_exception = true;
|
174
|
+
|
175
|
+
sleep 0.01
|
147
176
|
end
|
148
177
|
|
149
178
|
def stop()
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-restart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xasin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mqtt-sub_handler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '0.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
26
|
+
version: '0.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: git
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: octokit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: minitest
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,7 +98,8 @@ description: |-
|
|
84
98
|
This gem can be used to (re)start scripts whenever a GitHub push event is recorded.
|
85
99
|
The exit status of scripts can be monitored, and a failure can be sent back, making this capable of running simple tests too!
|
86
100
|
email:
|
87
|
-
executables:
|
101
|
+
executables:
|
102
|
+
- git-restart
|
88
103
|
extensions: []
|
89
104
|
extra_rdoc_files: []
|
90
105
|
files:
|
@@ -106,9 +121,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
121
|
version: '0'
|
107
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
123
|
requirements:
|
109
|
-
- - "
|
124
|
+
- - ">="
|
110
125
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
126
|
+
version: '0'
|
112
127
|
requirements: []
|
113
128
|
rubyforge_project:
|
114
129
|
rubygems_version: 2.6.14.1
|