Populate HeadInclude.dm and TailInclude.dm on instance creation

This commit is contained in:
Dominion
2023-06-15 03:32:21 -04:00
parent 7db8db0ce7
commit 174ac5c760
5 changed files with 60 additions and 5 deletions
@@ -57,6 +57,16 @@ namespace Tgstation.Server.Host.Components.StaticFiles
/// </summary>
const string CodeModificationsTailFile = "TailInclude.dm";
/// <summary>
/// Default contents of <see cref="CodeModificationsHeadFile"/>.
/// </summary>
static readonly string DefaultHeadInclude = @$"// TGS AUTO GENERATED HeadInclude.dm{Environment.NewLine}// This file will be included BEFORE all code in your .dme IF a replacement .dme does not exist in this directory{Environment.NewLine}// Please note that changes need to be made available if you are hosting an AGPL licensed codebase{Environment.NewLine}// The presence file in its default state does not constitute a code change that needs to be published by licensing standards{Environment.NewLine}";
/// <summary>
/// Default contents of <see cref="CodeModificationsHeadFile"/>.
/// </summary>
static readonly string DefaultTailInclude = @$"// TGS AUTO GENERATED TailInclude.dm{Environment.NewLine}// This file will be included AFTER all code in your .dme IF a replacement .dme does not exist in this directory{Environment.NewLine}// Please note that changes need to be made available if you are hosting an AGPL licensed codebase{Environment.NewLine}// The presence file in its default state does not constitute a code change that needs to be published by licensing standards{Environment.NewLine}";
/// <summary>
/// Map of <see cref="EventType"/>s to the filename of the event scripts they trigger.
/// </summary>
@@ -648,8 +658,29 @@ namespace Tgstation.Server.Host.Components.StaticFiles
await ioManager.WriteAllBytes(staticIgnorePath, Array.Empty<byte>(), cancellationToken);
}
async Task ValidateCodeModsFolder()
{
if (await ioManager.DirectoryExists(CodeModificationsSubdirectory, cancellationToken))
return;
await ioManager.CreateDirectory(CodeModificationsSubdirectory, cancellationToken);
await Task.WhenAll(
ioManager.WriteAllBytes(
ioManager.ConcatPath(
CodeModificationsSubdirectory,
CodeModificationsHeadFile),
Encoding.UTF8.GetBytes(DefaultHeadInclude),
cancellationToken),
ioManager.WriteAllBytes(
ioManager.ConcatPath(
CodeModificationsSubdirectory,
CodeModificationsTailFile),
Encoding.UTF8.GetBytes(DefaultTailInclude),
cancellationToken));
}
await Task.WhenAll(
ioManager.CreateDirectory(CodeModificationsSubdirectory, cancellationToken),
ValidateCodeModsFolder(),
ioManager.CreateDirectory(EventScriptsSubdirectory, cancellationToken),
ValidateStaticFolder());
}
@@ -119,9 +119,32 @@ namespace Tgstation.Server.Tests.Live.Instance
);
}
Task TestPregeneratedFilesExist(CancellationToken cancellationToken) => Task.Factory.StartNew(
_ =>
{
var configDir = Path.Combine(instance.Path, "Configuration");
var baseDir = Path.Combine(configDir, "CodeModifications");
var path = Path.Combine(baseDir, "HeadInclude.dm");
var result = File.Exists(path);
Assert.IsTrue(result);
path = Path.Combine(baseDir, "TailInclude.dm");
result = File.Exists(path);
Assert.IsTrue(result);
var tgsIgnore = Path.Combine(configDir, "GameStaticFiles", ".tgsignore");
result = File.Exists(tgsIgnore);
Assert.IsTrue(result);
},
null,
cancellationToken,
TaskCreationOptions.LongRunning,
TaskScheduler.Current);
public Task RunPreWatchdog(CancellationToken cancellationToken)
{
return Task.WhenAll(TestUploadDownloadAndDeleteDirectory(cancellationToken), SetupDMApiTests(cancellationToken));
return Task.WhenAll(
TestUploadDownloadAndDeleteDirectory(cancellationToken),
SetupDMApiTests(cancellationToken),
TestPregeneratedFilesExist(cancellationToken));
}
}
}
@@ -26,7 +26,7 @@ namespace Tgstation.Server.Tests.Live.Instance
this.serverPort = serverPort;
}
public async Task RunTests(CancellationToken cancellationToken, bool highPrioDD, bool lowPrioDeployment)
public async Task RunTests(bool highPrioDD, bool lowPrioDeployment, CancellationToken cancellationToken)
{
var byondTest = new ByondTest(instanceClient.Byond, instanceClient.Jobs, fileDownloader, instanceClient.Metadata);
var chatTest = new ChatTest(instanceClient.ChatBots, instanceManagerClient, instanceClient.Jobs, instanceClient.Metadata);
@@ -40,6 +40,7 @@ namespace Tgstation.Server.Tests.Live.Instance
async Task<JobResponse> Rest()
{
await Task.Yield();
await ApiAssert.ThrowsException<ConflictException>(() => repositoryClient.Read(cancellationToken), ErrorCode.RepoCloning);
Assert.IsNotNull(clone);
Assert.AreEqual(cloneRequest.Origin, clone.Origin);
@@ -1052,9 +1052,9 @@ namespace Tgstation.Server.Tests.Live
GetInstanceManager(),
(ushort)server.Url.Port)
.RunTests(
cancellationToken,
server.HighPriorityDreamDaemon,
server.LowPriorityDeployments));
server.LowPriorityDeployments,
cancellationToken));
await Task.WhenAll(rootTest, adminTest, instancesTest, instanceTests, usersTest);