git-restart 0.0.1 → 0.0.2.pre.dev

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
  SHA1:
3
- metadata.gz: d2731a1fddf96cb0555902773ea66010ae28ec5a
4
- data.tar.gz: ba700b8d5c346ac619ff1f848706b4d7f3e8a7b9
3
+ metadata.gz: 3eb20ef129d1ed50ae3348dc2748756dcd1d3c71
4
+ data.tar.gz: eef358e9ba6e66df2a32f510066d5cfe26aa1895
5
5
  SHA512:
6
- metadata.gz: e58995f9e245b556d013fd96044fd30372e8bb823ec2c13f17c8e1c7890421b0e1766e255dfb08a3620191c4f58dcc0973f66cc9b10e649946d834b1ec8b5b70
7
- data.tar.gz: 760c16c44d23c4e54e586e6969682e9b8079dbd600c12197e5e60dc1d90b3810fcf3833e039c85acee28d02dfb54a88edc7bca47faa2e19fc4dfdde615016fd2
6
+ metadata.gz: e725a7c1714c65cc4add13a1c852c76e72d9018dc0c4b22477c015772b8d79d658e07819495b76475fa067b1890a1c9796a97ae2acd7f92d26785808cb07c4e9
7
+ data.tar.gz: 9ac642c7ade58005e9f92ecd3110b64165bde9ad7c3f2e73afe559f3fc9e2bc7107ee86474482b6b6e54d908db0715948b73562efe8792eae0b00d00b659ea62
data/bin/git-restart CHANGED
@@ -5,18 +5,10 @@ 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(File.extname(t) == ".gitrun")
12
- target = t;
13
- elsif(File.extname(t) == ".gittask")
14
- $taskfiles << t;
15
- end
16
- end
8
+ target = ARGV[0] | ".gitrun"
17
9
 
18
- raise ArgumentError, "No valid runner file specified!" unless File.exist? target
10
+ raise ArgumentError, "No valid task file specified!" unless File.exist? target
19
11
 
20
12
  load target
21
13
 
22
- GitRestart::Task.runner.mqtt.lockAndListen
14
+ 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
 
@@ -17,6 +17,8 @@ module GitRestart
17
17
  attr_reader :lastStatus
18
18
  attr_reader :status_message
19
19
 
20
+ attr_reader :mqtt
21
+
20
22
  def self.runner=(runner)
21
23
  @runner = runner;
22
24
  end
@@ -30,9 +32,6 @@ module GitRestart
30
32
  def branch()
31
33
  runner().current_branch();
32
34
  end
33
- def current_commit()
34
- runner().current_commit();
35
- end
36
35
  def modified()
37
36
  runner().current_modified();
38
37
  end
@@ -70,8 +69,6 @@ module GitRestart
70
69
 
71
70
  valid?
72
71
 
73
- @status_file ||= "/tmp/TaskLog_#{@name}_#{current_commit()}";
74
-
75
72
  if(runner().next_tasks[@name])
76
73
  raise TaskValidityError, "A task of name #{@name} already exists!"
77
74
  else
@@ -85,12 +82,8 @@ module GitRestart
85
82
 
86
83
  @watched.each do |regEx|
87
84
  modified().each do |f|
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
85
+ next unless f =~ /#{Regexp.quote(@chdir)}(.*)/
86
+ return true if $1 =~ regEx;
94
87
  end
95
88
  end
96
89
 
@@ -107,39 +100,21 @@ module GitRestart
107
100
  end
108
101
  end
109
102
 
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
-
126
103
  def _report_status(status, message = nil)
127
- message ||= _get_statusline();
128
- @status_message = message;
104
+ @status_message = ""
129
105
 
130
106
  return unless @report_status
131
107
 
132
108
  runner().update_status(@name, status, message);
109
+ puts "Task #{@name} assumed a new status: #{status}#{message ? " MSG:#{message}" : ""}"
133
110
  end
134
111
  private :_report_status
135
112
 
136
113
  def start()
137
114
  puts "Starting Task: #{@name}"
138
115
 
139
- if @targets.empty?
140
- _report_status(:success, "No tasks to run!");
141
- return
142
- end
116
+ return if @targets.empty?
117
+ sleep 0.01
143
118
 
144
119
  @executionThread = Thread.new do
145
120
  _report_status(:pending);
@@ -147,9 +122,8 @@ module GitRestart
147
122
  @targets.each do |target|
148
123
  @statuschange_mutex.synchronize {
149
124
  break if @exiting
150
- _rm_logfile();
151
125
  options = {
152
- [:out, :err] => "/tmp/TaskLog_#{@name}_#{current_commit()}"
126
+ [:in, :out, :err] => "/dev/null"
153
127
  }
154
128
  options[:chdir] = @chdir if @chdir
155
129
 
@@ -165,14 +139,11 @@ module GitRestart
165
139
 
166
140
  if(@lastStatus == 0)
167
141
  _report_status(:success);
168
- _rm_logfile();
169
142
  elsif(!@exiting || @expect_clean_exit)
170
143
  _report_status(:failure);
171
144
  end
172
145
  end
173
146
  @executionThread.abort_on_exception = true;
174
-
175
- sleep 0.01
176
147
  end
177
148
 
178
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.1
4
+ version: 0.0.2.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-08-28 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
@@ -98,8 +84,7 @@ description: |-
98
84
  This gem can be used to (re)start scripts whenever a GitHub push event is recorded.
99
85
  The exit status of scripts can be monitored, and a failure can be sent back, making this capable of running simple tests too!
100
86
  email:
101
- executables:
102
- - git-restart
87
+ executables: []
103
88
  extensions: []
104
89
  extra_rdoc_files: []
105
90
  files:
@@ -121,9 +106,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
106
  version: '0'
122
107
  required_rubygems_version: !ruby/object:Gem::Requirement
123
108
  requirements:
124
- - - ">="
109
+ - - ">"
125
110
  - !ruby/object:Gem::Version
126
- version: '0'
111
+ version: 1.3.1
127
112
  requirements: []
128
113
  rubyforge_project:
129
114
  rubygems_version: 2.6.14.1