-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSteamDeployBuildTask.cs
More file actions
366 lines (318 loc) · 10.5 KB
/
SteamDeployBuildTask.cs
File metadata and controls
366 lines (318 loc) · 10.5 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
using System.Collections.Generic;
using System.Threading.Tasks;
using System;
using System.IO;
using System.IO.Compression;
using System.Xml;
using EpicGames.Core;
using Microsoft.Extensions.Logging;
using UnrealBuildBase;
using IdentityModel.Client;
namespace AutomationTool.Tasks
{
/// <summary>
/// Parameters for a <see cref="SteamAuthTask"/>.
/// </summary>
public class SteamAuthTaskParameters
{
/// <summary>
/// Environment Variable name which contains the Base64 encoded config.vdf file authenticated for the build account
/// </summary>
[TaskParameter(Optional = true)] public string ConfigVdfEnvVar = "SteamConfigVdf";
}
/// <summary>
/// Load the steamcmd config.vdf from an base64 encoded zip file in an environment variable
/// </summary>
[TaskElement("Steam-Auth", typeof(SteamAuthTaskParameters))]
public class SteamAuthTask : SteamTaskBase
{
private SteamAuthTaskParameters Parameters;
/// <summary>
/// Constructor
/// </summary>
public SteamAuthTask(SteamAuthTaskParameters InParameters)
{
Parameters = InParameters;
}
/// <inheritdoc />
public override Task ExecuteAsync(JobContext Job, HashSet<FileReference> BuildProducts, Dictionary<string, HashSet<FileReference>> TagNameToFileSet)
{
Logger.LogInformation("Creating SteamCmd config.vdf from environment");
List<FileReference> OutputFiles = new List<FileReference>();
string base64 = System.Environment.GetEnvironmentVariable(Parameters.ConfigVdfEnvVar);
if (string.IsNullOrEmpty(base64))
{
throw new AutomationException("Environment variable {0} not set", Parameters.ConfigVdfEnvVar);
}
DirectoryReference ConfigDir = DirectoryReference.Combine(SteamContentBuilderDir, "config");
byte[] bytes = Convert.FromBase64String(base64);
try
{
using (MemoryStream ms = new MemoryStream(bytes))
{
using (ZipArchive ZipArchive = new ZipArchive(ms, ZipArchiveMode.Read))
{
foreach (ZipArchiveEntry Entry in ZipArchive.Entries)
{
if(Entry.FullName.EndsWith("/"))
{
// ignore directories
continue;
}
FileReference OutputFile = FileReference.Combine(ConfigDir, Entry.FullName);
Logger.LogInformation($"Extracting {Entry.FullName} to {OutputFile.FullName}");
DirectoryReference.CreateDirectory(OutputFile.Directory);
Entry.ExtractToFile_CrossPlatform(OutputFile.FullName, true);
OutputFiles.Add(OutputFile);
}
}
}
}
catch (Exception e)
{
throw new AutomationException(ExitCode.Error_UnknownDeployFailure, e, "Failed extracting steam config.vdf");
}
return Task.CompletedTask;
}
/// <inheritdoc />
public override void Write(XmlWriter Writer)
{
Write(Writer, Parameters);
}
/// <inheritdoc />
public override IEnumerable<string> FindConsumedTagNames()
{
yield break;
}
/// <inheritdoc />
public override IEnumerable<string> FindProducedTagNames()
{
yield break;
}
}
/// <summary>
/// Parameters for a <see cref="SteamCreateAppManifestTask"/>.
/// </summary>
public class SteamCreateAppManifestTaskParameters
{
/// <summary>
/// Steam AppId
/// </summary>
[TaskParameter] public int AppId;
/// <summary>
/// Description of the build in the steamworks build database
/// </summary>
[TaskParameter(Optional = true)] public string BuildDescription = string.Empty;
/// <summary>
/// Root directory for content. Depot path(s) will be relative to this path.
/// </summary>
[TaskParameter] public DirectoryReference ContentRootDir = null!;
/// <summary>
/// Directory containing the files to be uploaded to the first depot. Path is relative to <see cref="ContentRootDir"/>.
/// </summary>
[TaskParameter] public string Depot1LocalDir = string.Empty;
/// <summary>
/// Relative path in the installed Steam depot. Corresponds to Depot1.FileMapping.DepotPath in the app manifest.
/// </summary>
[TaskParameter] public string Depot1DepotPath = string.Empty;
/// <summary>
/// Set this build live on the specified branch
/// </summary>
[TaskParameter] public string ReleaseBranch = string.Empty;
/// <summary>
/// Path to write the manifest file to
/// </summary>
[TaskParameter] public string ManifestOutputFile = null!;
/// <summary>
/// Build cache and log file output directory
/// </summary>
[TaskParameter(Optional = true)] public string BuildOutputDir = "BuildOutput";
/// <summary>
/// Tag to be applied to build products of this task.
/// </summary>
[TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.TagList)]
public string Tag = string.Empty;
}
/// <summary>
/// Write deployment and depot manifests for a Steam build upload.
/// </summary>
[TaskElement("Steam-CreateAppManifest", typeof(SteamCreateAppManifestTaskParameters))]
public class SteamCreateAppManifestTask : SteamTaskBase
{
private SteamCreateAppManifestTaskParameters Parameters;
/// <summary>
/// Constructor
/// </summary>
/// <param name="InParameters"></param>
public SteamCreateAppManifestTask(SteamCreateAppManifestTaskParameters InParameters)
{
Parameters = InParameters;
}
/// <inheritdoc />
public override async Task ExecuteAsync(JobContext Job, HashSet<FileReference> BuildProducts, Dictionary<string, HashSet<FileReference>> TagNameToFileSet)
{
if (Parameters.Depot1DepotPath == "")
{
Logger.Log(LogLevel.Information, "Depot1DepotPath parameter not set. Defaulting to root directory ('.')");
Parameters.Depot1DepotPath = ".";
}
int depot1Id = Parameters.AppId + 1;
string AppManifestText = $@"
""AppBuild""
{{
""AppID"" ""{Parameters.AppId}""
""Desc"" ""{Parameters.BuildDescription}""
""SetLive"" ""{Parameters.ReleaseBranch}""
""ContentRoot"" ""{Parameters.ContentRootDir}""
""BuildOutput"" ""{Parameters.BuildOutputDir}""
""Depots""
{{
""{depot1Id}""
{{
""FileMapping""
{{
""LocalPath"" ""{Parameters.Depot1LocalDir}/*""
""DepotPath"" ""{Parameters.Depot1DepotPath}""
""Recursive"" ""1""
}}
}}
}}
}}";
if (!Directory.Exists(Parameters.ContentRootDir.FullName))
{
throw new AutomationException($"{nameof(Parameters.ContentRootDir)} must exist.");
}
if (!Directory.Exists(Path.Combine(Parameters.ContentRootDir.FullName, Parameters.Depot1LocalDir)))
{
throw new AutomationException(
$"{nameof(Parameters.Depot1LocalDir)} must be relative to {nameof(Parameters.ContentRootDir)}, and must exist.");
}
FileReference AppManifestFile = ResolveFile(Parameters.ManifestOutputFile);
if (!DirectoryReference.Exists(AppManifestFile.Directory))
{
DirectoryReference.CreateDirectory(AppManifestFile.Directory);
}
await FileReference.WriteAllTextAsync(AppManifestFile, AppManifestText);
foreach (string TagName in FindTagNamesFromList(Parameters.Tag))
{
FindOrAddTagSet(TagNameToFileSet, TagName).Add(AppManifestFile);
}
BuildProducts.Add(AppManifestFile);
}
/// <inheritdoc />
public override void Write(XmlWriter Writer)
{
Write(Writer, Parameters);
}
/// <inheritdoc />
public override IEnumerable<string> FindConsumedTagNames()
{
yield break;
}
/// <inheritdoc />
public override IEnumerable<string> FindProducedTagNames()
{
return FindTagNamesFromList(Parameters.Tag);
}
}
/// <summary>
/// Parameters for a <see cref="SteamDeployBuildTask"/>.
/// </summary>
public class SteamDeployBuildTaskParameters
{
/// <summary>
/// Steam username for build account
/// </summary>
[TaskParameter] public string Username = string.Empty;
/// <summary>
/// Path to the application manifest which should be uploaded
/// </summary>
[TaskParameter] public string AppManifestFile;
}
/// <summary>
/// Write deployment and depot manifests for a Steam build upload.
/// </summary>
[TaskElement("Steam-DeployBuild", typeof(SteamDeployBuildTaskParameters))]
public class SteamDeployBuildTask : SteamTaskBase
{
private SteamDeployBuildTaskParameters Parameters;
/// <summary>
/// Constructor
/// </summary>
/// <param name="InParameters"></param>
public SteamDeployBuildTask(SteamDeployBuildTaskParameters InParameters)
{
Parameters = InParameters;
if (string.IsNullOrEmpty(Parameters.Username))
{
throw new AutomationException("Steam build username not set");
}
}
/// <inheritdoc />
public override Task ExecuteAsync(JobContext Job, HashSet<FileReference> BuildProducts, Dictionary<string, HashSet<FileReference>> TagNameToFileSet)
{
FileReference AppManifest = ResolveFile(Parameters.AppManifestFile);
if (!File.Exists(AppManifest.FullName))
{
throw new AutomationException($"AppManifest file not found: {AppManifest.FullName}");
}
DirectoryReference SteamCmdLogs = DirectoryReference.Combine(SteamContentBuilderDir, "logs");
try
{
FileUtils.ForceDeleteDirectoryContents(SteamCmdLogs);
// TODO(jesse): Change paths based on platform
FileReference SteamCmdExe = FileReference.Combine(SteamContentBuilderDir, "steamcmd.exe");
if (!FileReference.Exists(SteamCmdExe))
{
throw new AutomationException($"SteamCmd is missing from deployment. Check AutoSDK. Searched {SteamCmdExe.FullName}");
}
return ExecuteAsync(SteamCmdExe.FullName, $"+login \"{Parameters.Username}\" +run_app_build \"{AppManifest.FullName}\" +quit", SteamCmdExe.Directory.FullName);
}
catch
{
// TODO: Tag steamcmd output as build artifacts?
throw;
}
}
/// <inheritdoc />
public override void Write(XmlWriter Writer)
{
Write(Writer, Parameters);
}
/// <inheritdoc />
public override IEnumerable<string> FindConsumedTagNames()
{
foreach(string TagName in FindTagNamesFromFilespec(Parameters.AppManifestFile))
{
yield return TagName;
}
}
/// <inheritdoc />
public override IEnumerable<string> FindProducedTagNames()
{
yield break;
}
}
/// <summary>
/// Base class for Steam tasks
/// </summary>
public abstract class SteamTaskBase : SpawnTaskBase
{
/// <summary>
/// Directory containing the Steam Content Builder part of the sdk
/// </summary>
protected readonly DirectoryReference SteamContentBuilderDir;
/// <summary>
/// Constructor
/// </summary>
protected SteamTaskBase()
{
string AutoSdkRoot = Environment.GetEnvironmentVariable("UE_SDKS_ROOT");
if (string.IsNullOrEmpty(AutoSdkRoot))
{
throw new AutomationException("Environment variable UE_SDKS_ROOT not set");
}
SteamContentBuilderDir = new DirectoryReference(Path.Combine(AutoSdkRoot, "HostWin64/Win64/steam/tools/ContentBuilder/builder"));
}
}
}