-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoDeployServer.rb
More file actions
34 lines (30 loc) · 1.01 KB
/
AutoDeployServer.rb
File metadata and controls
34 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'sinatra'
require 'json'
require_relative 'LoadConfig'
config = load()
#this will start up the servers before we start listening.
config["repos"].each do |repo|
puts "Executing startScript for "+repo["name"]
#TODO: Replace this with a method to run commands. Take the dir and/or a list of commands to run afterwards.
system "cd "+repo["workingDir"]+" && "+repo["startScript"]+" &"
puts "Done"
end
#TODO: load port from config
set :port, 8765
post '/payload' do
#if its a push, we care about it.
if env['HTTP_X_GITHUB_EVENT']=='push' then
#Printing this stuff so i can debug easily
webHook = JSON.parse(params[:payload])
#lets check out what repo it was
payloadRepo = webHook['repository']['url']
config["repos"].each do |repo|
if (repo["name"]==payloadRepo) then
script = repo['script']
puts script
puts "Detected push to "+payloadRepo+" running script at "+script
system "cd "+repo["workingDir"]+" && "+repo["script"]+" &"
end
end
end
end