git-restart 0.0.3 → 0.0.4.pre.dev

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6e1ed81be5f1e1b88b5f03998ed168bb3cea967
4
- data.tar.gz: 64ecf291feb17510fdaf4e95eb310da327bfa0dd
3
+ metadata.gz: c99d1fbfa58de92874eb59f9b49e6ca080e0b5a1
4
+ data.tar.gz: 8651e7bcf6fa826f158e0dfd15bcd82a66a7f703
5
5
  SHA512:
6
- metadata.gz: 5fed7452a908ac52db44e2b32ae5d5c773d839ffdeb7f956b44f1dbbbd409fc3e1a7bf4ce8d8587c05bd1a4ee14c5b1acd6c29eaf77c633c98b3c3aa340c7191
7
- data.tar.gz: d1779c9e0efedceeb64fc65c34901d659beec6ab3c1cbb80734328a2f9754a76f106343ff7b04f76bd80f79b74a5cef62b4d0d6b2886e28cb1063609ae118e8e
6
+ metadata.gz: 7e0c1e3adf4b6ebe1317a276a104363e4b27e617f646ec5f283f75303822d2d1afa75179aac180b5daf9ab591aea25e48be06ef639eb7e09933e0d6bf0d29663
7
+ data.tar.gz: 615bbed3fad0442ac9b988d0333d126bd9b52ab4e562a90454400a9a158bacd16f7065c8b7822d5871f6b4f48c6a37ec19f363ca3b074afe6809d402c918503e
data/bin/git-restart CHANGED
@@ -5,18 +5,11 @@ require 'git-restart/runner.rb'
5
5
 
6
6
  puts "Starting runner ..."
7
7
 
8
- $taskfiles = Array.new();
9
- target = ".gitrun"
10
- ARGV.each do |t|
11
- if(t =~ /\.gitrun$/)
12
- target = t;
13
- else
14
- $taskfiles << t;
15
- end
16
- end
8
+ target = ARGV[0]
9
+ target ||= ".gitrun"
17
10
 
18
- raise ArgumentError, "No valid runner file specified!" unless File.exist? target
11
+ raise ArgumentError, "No valid task file specified!" unless File.exist? target
19
12
 
20
13
  load target
21
14
 
22
- GitRestart::Task.runner.mqtt.lockAndListen
15
+ GitRestart::Task.runner.mqtt.lock_and_listen
@@ -1,8 +1,6 @@
1
1
 
2
2
  require 'mqtt/sub_handler'
3
-
4
3
  require 'git'
5
- require 'octokit'
6
4
 
7
5
  require_relative "task.rb"
8
6
 
@@ -11,16 +9,12 @@ module GitRestart
11
9
  attr_accessor :name
12
10
 
13
11
  attr_accessor :repo, :branches, :exclude_branches, :start_on
14
- attr_accessor :allowed_tasks
15
12
 
16
13
  attr_reader :next_tasks
17
14
  attr_reader :current_task_file
18
15
 
19
- attr_reader :mqtt
20
- attr_accessor :octokit
21
-
22
16
  def current_commit()
23
- @git.object("HEAD").sha;
17
+ @git.object("HEAD^").sha;
24
18
  end
25
19
  def current_branch()
26
20
  @git.current_branch();
@@ -29,15 +23,9 @@ module GitRestart
29
23
  @current_modified;
30
24
  end
31
25
 
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
-
26
+ def initialize()
35
27
  GitRestart::Task.runner = self;
36
28
 
37
- @allowed_tasks = Array.new();
38
- @allowed_tasks << fileList if(fileList);
39
- @allowed_tasks << $taskfiles unless($taskfiles.empty?)
40
-
41
29
  @current_tasks = Hash.new();
42
30
  @next_tasks = Hash.new();
43
31
 
@@ -50,15 +38,16 @@ module GitRestart
50
38
 
51
39
  yield(self);
52
40
 
53
- @allowed_tasks.flatten!
54
-
55
41
  @listenedSub = @mqtt.subscribe_to "GitHub/#{@repo}" do |data|
42
+ puts "Received data: #{data}"
56
43
  begin
57
44
  data = JSON.parse(data, symbolize_names: true);
58
45
  rescue
59
46
  next;
60
47
  end
61
48
 
49
+ puts "Processing data #{data}"
50
+
62
51
  next unless data[:branch];
63
52
  if(not @branches.empty?)
64
53
  next unless @branches.include? data[:branch];
@@ -66,29 +55,16 @@ module GitRestart
66
55
  next if @exclude_branches.include? data[:branch];
67
56
  end
68
57
 
58
+ puts "Queueing data!"
59
+
69
60
  @branchQueue << data;
70
61
  end
71
62
 
72
63
  autostart();
73
64
  _start_task_thread();
74
-
75
- at_exit {
76
- _stop_all_tasks();
77
- }
78
65
  end
79
66
 
80
67
  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
92
68
  end
93
69
 
94
70
  def _start_task_thread()
@@ -96,6 +72,8 @@ module GitRestart
96
72
  loop do
97
73
  newData = @branchQueue.pop;
98
74
 
75
+ puts "Popped data: #{newData}"
76
+
99
77
  @current_modified = newData[:touched];
100
78
  _switch_to(newData[:branch], newData[:head_commit]);
101
79
  end
@@ -128,28 +106,23 @@ module GitRestart
128
106
  t.gsub!(/^\.\//,"");
129
107
  @current_task_file = t;
130
108
 
131
- unless(@allowed_tasks.empty?)
132
- next unless @allowed_tasks.include? @current_task_file
133
- end
134
-
109
+ # TODO Add proper error reporting
135
110
  begin
136
111
  load(t);
137
112
  rescue ScriptError, StandardError
138
- update_status("File #{t}", :failure, "File could not be parsed!")
139
113
  puts("File #{t} could not be loaded!");
140
114
  rescue GitRestart::TaskValidityError
141
- update_status("File #{t}", :failure, "Task-file not configured properly!")
142
115
  puts("Task-File #{t} is not configured properly!");
143
116
  end
144
117
  end
145
118
 
146
- puts "Finished loading! Next tasks: #{@next_tasks.keys}"
119
+ puts "Finished loading! Next tasks are: #{@next_tasks}"
147
120
  end
148
121
 
149
122
  def _start_next_tasks()
150
123
  _generate_next_tasks();
151
124
 
152
- puts "\nStarting next tasks!"
125
+ puts "Starting next tasks!"
153
126
  @next_tasks.each do |name, t|
154
127
  next unless t.active;
155
128
  next unless t.triggered?
@@ -160,24 +133,19 @@ module GitRestart
160
133
  end
161
134
 
162
135
  def _switch_to(branch, commit = nil)
163
- puts "\n\nSwitching to branch: #{branch}#{commit ? ",commit: #{commit}" : ""}"
164
-
165
- begin
166
- @git.fetch();
167
- rescue
168
- end
136
+ puts "Switching to branch: #{branch}, commit: #{commit}"
137
+ @git.fetch();
169
138
 
170
139
  if(branch != current_branch())
171
140
  _stop_all_tasks();
172
141
  else
173
142
  _stop_triggered_tasks();
174
143
  end
175
- @git.reset_hard();
176
144
  @git.checkout(branch);
177
- @git.merge("origin/#{branch}");
178
-
179
145
  @git.reset_hard(commit);
180
146
 
147
+ @git.merge("origin/#{branch}");
148
+
181
149
  _start_next_tasks();
182
150
  end
183
151
 
@@ -1,58 +1,27 @@
1
1
 
2
- # @author Xasin
3
2
  module GitRestart
4
- # The Error-Class used to signal when a Task is set up wrong
5
3
  class TaskValidityError < StandardError
6
4
  end
7
5
 
8
- # This class is used to define "Tasks". Each task represents
9
- # a set of commands, which it executes in chronological order, or until
10
- # a task errors.
11
- # Additionally, it will kill execution of tasks with a specified kill-signal
12
- # when an update was detected from GitHub.
13
- # The failure-status of the tasks can also be reported via Octokit, allowing this
14
- # to be used as a simple CI or Test system for various languages.
15
6
  class Task
16
- # The array of tasks to execute. Each target will be executed in the given
17
- # order via `Process.spawn`.
18
- # @return [Array<String>]
19
7
  attr_reader :targets
20
8
 
21
- # The signal (as String, like Signal.list) to use to kill the process.
22
- # Can be nil to disable killing
23
9
  attr_accessor :signal
24
- # Whether or not to report failure if the currently running target
25
- # has a non-zero exit status after having been killed. Only makes sense
26
- # together with report_status
27
10
  attr_accessor :expect_clean_exit
28
- # Whether or not to report failure/success status to GitHub using Octokit
29
11
  attr_accessor :report_status
30
- # Defines this as a "CI_Task". Such a task will always run on an update,
31
- # regardless what files changed. Useful if you always want a status report
32
- # on GitHub.
33
12
  attr_accessor :ci_task
34
- # Name of the Task. *Required*. Used as *unique* ID, and to report status to GitHub
35
- attr_accessor :name
36
- # The file to use to retrieve a single-line status info for the "description"
37
- # string of the GitHub status. Only the last *non-indented* line is used,
38
- # which allows the output of Minitest to be used directly.
39
- attr_accessor :status_file
40
-
41
- # Whether or not this task is active. Usually set via #on_branches,
42
- # but can be used to manually disable or enable this task based on
43
- # config files, ENV variables etc.
13
+ attr_accessor :name, :status_file
14
+
44
15
  attr_accessor :active
45
16
 
46
- # The last status-code of this Task. Used internally.
47
17
  attr_reader :lastStatus
48
- # The last status-message of this task. Used internally.
49
18
  attr_reader :status_message
50
19
 
51
- # @api private
20
+ attr_reader :mqtt
21
+
52
22
  def self.runner=(runner)
53
23
  @runner = runner;
54
24
  end
55
- # @api private
56
25
  def self.runner()
57
26
  return @runner;
58
27
  end
@@ -63,10 +32,6 @@ module GitRestart
63
32
  def branch()
64
33
  runner().current_branch();
65
34
  end
66
- def current_commit()
67
- runner().current_commit();
68
- end
69
-
70
35
  def modified()
71
36
  runner().current_modified();
72
37
  end
@@ -104,8 +69,6 @@ module GitRestart
104
69
 
105
70
  valid?
106
71
 
107
- @status_file ||= "/tmp/TaskLog_#{@name}_#{current_commit()}";
108
-
109
72
  if(runner().next_tasks[@name])
110
73
  raise TaskValidityError, "A task of name #{@name} already exists!"
111
74
  else
@@ -119,12 +82,8 @@ module GitRestart
119
82
 
120
83
  @watched.each do |regEx|
121
84
  modified().each do |f|
122
- if regEx.to_s =~ /^\(\?\-mix:\\\/(.*)\)$/ then
123
- return true if f =~ Regexp.new($1);
124
- else
125
- next unless f =~ /#{Regexp.quote(@chdir)}(.*)/
126
- return true if $1 =~ regEx;
127
- end
85
+ next unless f =~ /#{Regexp.quote(@chdir)}(.*)/
86
+ return true if $1 =~ regEx;
128
87
  end
129
88
  end
130
89
 
@@ -141,55 +100,30 @@ module GitRestart
141
100
  end
142
101
  end
143
102
 
144
- def _rm_logfile()
145
- if File.exist?("/tmp/TaskLog_#{@name}_#{current_commit()}") then
146
- File.delete("/tmp/TaskLog_#{@name}_#{current_commit()}");
147
- end
148
- end
149
- def _get_statusline()
150
- return "No status specified" unless File.exist? @status_file
151
-
152
- sMsg = ""
153
- File.open(@status_file, "r") do |sFile|
154
- sFile.each_line do |l|
155
- l.chomp!
156
- next if l == "";
157
- next if l =~ /^\s+/;
158
-
159
- sMsg = l;
160
- end
161
- end
162
-
163
- return sMsg;
164
- end
165
-
166
103
  def _report_status(status, message = nil)
167
- message ||= _get_statusline();
168
- @status_message = message;
104
+ @status_message = ""
169
105
 
170
106
  return unless @report_status
171
107
 
172
108
  runner().update_status(@name, status, message);
109
+ puts "Task #{@name} assumed a new status: #{status}#{message ? " MSG:#{message}" : ""}"
173
110
  end
174
111
  private :_report_status
175
112
 
176
113
  def start()
177
114
  puts "Starting Task: #{@name}"
178
115
 
179
- if @targets.empty?
180
- _report_status(:success, "No tasks to run!");
181
- return
182
- end
116
+ return if @targets.empty?
117
+ sleep 0.01
183
118
 
184
119
  @executionThread = Thread.new do
185
120
  _report_status(:pending);
186
121
 
187
- _rm_logfile();
188
122
  @targets.each do |target|
189
123
  @statuschange_mutex.synchronize {
190
124
  break if @exiting
191
125
  options = {
192
- [:out, :err] => "/tmp/TaskLog_#{@name}_#{current_commit()}"
126
+ [:out, :err] => "/dev/null"
193
127
  }
194
128
  options[:chdir] = @chdir if @chdir
195
129
 
@@ -205,14 +139,11 @@ module GitRestart
205
139
 
206
140
  if(@lastStatus == 0)
207
141
  _report_status(:success);
208
- _rm_logfile();
209
142
  elsif(!@exiting || @expect_clean_exit)
210
143
  _report_status(:failure);
211
144
  end
212
145
  end
213
146
  @executionThread.abort_on_exception = true;
214
-
215
- sleep 0.01
216
147
  end
217
148
 
218
149
  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.3
4
+ version: 0.0.4.pre.dev
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xasin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-03 00:00:00.000000000 Z
11
+ date: 2018-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mqtt-sub_handler
@@ -38,20 +38,6 @@ 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'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: minitest
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -121,12 +107,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
107
  version: '0'
122
108
  required_rubygems_version: !ruby/object:Gem::Requirement
123
109
  requirements:
124
- - - ">="
110
+ - - ">"
125
111
  - !ruby/object:Gem::Version
126
- version: '0'
112
+ version: 1.3.1
127
113
  requirements: []
128
114
  rubyforge_project:
129
- rubygems_version: 2.5.2.1
115
+ rubygems_version: 2.6.14.1
130
116
  signing_key:
131
117
  specification_version: 4
132
118
  summary: "(Re)start scripts and monitor them on a GitHub push"