mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-24 21:46:52 +01:00
Merge pull request #157 from JamieH/master
Adds a preaction framework so we can run a .bat file before or after compiling the code
This commit is contained in:
@@ -102,6 +102,9 @@ The service supports updates while running a DreamDaemon instance. Simply instal
|
||||
* `RepoKey/`
|
||||
* This contains ssh key information for automatic changelog pushing.
|
||||
|
||||
* `EventHandlers/`
|
||||
* This contains batch files that run after certain events, currently only precompile and postcompile events are implemented. If you'd like an event handler you should create a file in this folder with the following name: `{event_name}.bat` for example: if I want an event handler for precompile, I would name it `precompile.bat`.
|
||||
|
||||
* `BYOND/`
|
||||
* This contains the actual BYOND installation the server uses
|
||||
|
||||
|
||||
@@ -383,6 +383,14 @@ namespace TGServerService
|
||||
}
|
||||
}
|
||||
|
||||
if (!PrecompileHook())
|
||||
{
|
||||
lastCompilerError = "The precompile hook failed";
|
||||
compilerCurrentStatus = TGCompilerStatus.Initialized; //still fairly valid
|
||||
TGServerService.WriteWarning("Precompile hook failed!", TGServerService.EventID.DMCompileError);
|
||||
return;
|
||||
}
|
||||
|
||||
using (var DM = new Process()) //will kill the process if the thread is terminated
|
||||
{
|
||||
DM.StartInfo.FileName = ByondDirectory + "/bin/dm.exe";
|
||||
@@ -473,6 +481,13 @@ namespace TGServerService
|
||||
}
|
||||
}
|
||||
var staged = DaemonStatus() != TGDreamDaemonStatus.Offline;
|
||||
if (!PostcompileHook())
|
||||
{
|
||||
lastCompilerError = "The postcompile hook failed";
|
||||
compilerCurrentStatus = TGCompilerStatus.Initialized; //still fairly valid
|
||||
TGServerService.WriteWarning("Postcompile hook failed!", TGServerService.EventID.DMCompileError);
|
||||
return;
|
||||
}
|
||||
var msg = String.Format("Compile complete!{0}", !staged ? "" : " Server will update next round.");
|
||||
SendMessage("DM: " + msg, ChatMessageType.DeveloperInfo);
|
||||
TGServerService.WriteInfo(msg, TGServerService.EventID.DMCompileSuccess);
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace TGServerService
|
||||
{
|
||||
// Some useful functions for triggering pre action events
|
||||
partial class TGStationServer
|
||||
{
|
||||
const string EventFolder = "EventHandlers/";
|
||||
|
||||
string GetPath(string eventName)
|
||||
{
|
||||
return string.Format("{0}{1}.bat", EventFolder, eventName);
|
||||
}
|
||||
|
||||
bool EventHandlerExists(string eventName)
|
||||
{
|
||||
return File.Exists(GetPath(eventName));
|
||||
}
|
||||
|
||||
bool HandleEvent(string eventName)
|
||||
{
|
||||
if (!EventHandlerExists(eventName))
|
||||
{
|
||||
// We don't need a handler, so let's just fail semi-silently.
|
||||
TGServerService.WriteWarning(String.Format("Preaction Event: {0} not running due to missing event handler: {1}", eventName, GetPath(eventName)), TGServerService.EventID.PreactionFail);
|
||||
return true;
|
||||
}
|
||||
|
||||
var process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = GetPath(eventName),
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true
|
||||
}
|
||||
};
|
||||
process.Start();
|
||||
process.WaitForExit();
|
||||
|
||||
var stdout = process.StandardOutput.ReadToEnd();
|
||||
var stderr = process.StandardError.ReadToEnd();
|
||||
|
||||
TGServerService.WriteInfo(
|
||||
String.Format("Preaction Event: {0} @ {1} ran. Stdout:\n{2}\nStderr:\n{3}", eventName, GetPath(eventName), stdout, stderr),
|
||||
process.ExitCode == 0 ? TGServerService.EventID.PreactionEvent : TGServerService.EventID.PreactionFail
|
||||
);
|
||||
|
||||
return process.ExitCode == 0 ? true : false;
|
||||
}
|
||||
|
||||
public bool PrecompileHook()
|
||||
{
|
||||
return HandleEvent("precompile");
|
||||
}
|
||||
|
||||
public bool PostcompileHook()
|
||||
{
|
||||
return HandleEvent("postcompile");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,8 @@ namespace TGServerService
|
||||
IRCLogModes = 6500,
|
||||
SubmoduleReclone = 6600,
|
||||
Authentication = 6700,
|
||||
PreactionEvent = 6800,
|
||||
PreactionFail = 6900
|
||||
}
|
||||
|
||||
static TGServerService ActiveService; //So everyone else can write to our eventlog
|
||||
|
||||
@@ -95,6 +95,7 @@
|
||||
<Compile Include="InterfaceBase.cs" />
|
||||
<Compile Include="IRC.cs" />
|
||||
<Compile Include="Interop.cs" />
|
||||
<Compile Include="PreactionHandler.cs" />
|
||||
<Compile Include="ProcessExtension.cs" />
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
|
||||
Reference in New Issue
Block a user