private static bool UploadBuildToSteamworks(SteamSettings steamSettings) { var steamworksDir = ConfigurationSettings.AppSettings["STEAMWORKS_DIRECTORY"]; Trace.TraceInformation("Invoking Steamworks SDK to upload build"); string command = string.Format( @"{0}\Publish-Build.bat {1} ""{2}"" {3}", steamworksDir, steamSettings.Username, steamSettings.Password, steamSettings.AppScript); //string command = string.Format( // @"{0}\Publish-Build.bat {1} ""{2}"" {3} {4} ""{5}""", // steamworksDir, // steamSettings.Username, // steamSettings.Password, // steamSettings.AppId, // steamSettings.AppScript, // Environment.CurrentDirectory + "\\" + steamSettings.ExecutablePath); int exitCode; ProcessStartInfo processInfo; Process process; processInfo = new ProcessStartInfo("cmd.exe", "/c " + command); processInfo.WorkingDirectory = Environment.CurrentDirectory; processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; // *** Redirect the output *** processInfo.RedirectStandardError = true; processInfo.RedirectStandardOutput = true; process = Process.Start(processInfo); process.WaitForExit(); // *** Read the streams *** // Warning: This approach can lead to deadlocks, see Edit #2 string output = process.StandardOutput.ReadToEnd(); string error = process.StandardError.ReadToEnd(); exitCode = process.ExitCode; Trace.TraceInformation(output); if (exitCode == 0) { Trace.TraceInformation("Steaworks SDK finished successfully"); } else { Trace.TraceError(error); Trace.TraceError("Steaworks SDK failed"); } process.Close(); return(exitCode == 0); }
private static bool DownloadUnityCloudBuild(SteamSettings steamSettings, BuildDefinition latestBuild) { bool success = true; Trace.TraceInformation("Checking whether latest build has already been processed"); var downloadDir = ConfigurationSettings.AppSettings["DOWNLOAD_DIRECTORY"]; var filePath = Path.Combine(downloadDir, latestBuild.FileName); if (File.Exists(filePath)) { Trace.TraceInformation("Build already processed"); success = false; } else { Trace.TraceInformation("Downloading new build"); using (var webClient = new WebClient()) { webClient.DownloadFile(new Uri(latestBuild.DownloadUrl), filePath); } Trace.TraceInformation("Downloaded new build"); if (Directory.Exists(steamSettings.ContentDir)) { Trace.TraceInformation("Deleting existing Steamworks content"); Directory.Delete(steamSettings.ContentDir, true); } Trace.TraceInformation("Unzipping build"); ZipFile.ExtractToDirectory(filePath, steamSettings.ContentDir); Trace.TraceInformation("Unzipped build"); Trace.TraceInformation("Deleting download {0}", filePath); File.Delete(filePath); success = true; } return(success); }
private static void TryNotifySlack(SlackSettings slackSettings, SteamSettings steamSettings, BuildDefinition latestBuild, bool success, string errorMessage) { var slackUrl = ConfigurationSettings.AppSettings["SLACK_NOTIFICATION_URL"]; if (slackSettings != null) { slackUrl = slackSettings.Url; } if (!string.IsNullOrEmpty(slackUrl)) { Trace.TraceInformation("Sending Slack notification"); string payload; if (success) { payload = string.Format( "{0} build {1:N0} has been uploaded to the {2} branch on Steam.", steamSettings.DisplayName, latestBuild.BuildNumber, steamSettings.BranchName ?? "default"); } else { payload = string.Format( "Failed to upload {0} build {1:N0} to the {2} branch on Steam: \n{3}", steamSettings.DisplayName, latestBuild.BuildNumber, steamSettings.BranchName ?? "default", errorMessage ?? "Unknown error"); } var message = @"{""text"": """ + payload + @"""}"; using (var client = new HttpClient()) { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, slackUrl); request.Content = new StringContent(message, Encoding.UTF8, "application/json"); var task = client.SendAsync(request); task.Wait(); } } }
private static void BuildFinalAppScript(SteamSettings steamSettings, BuildDefinition buildDefinition) { var steamworksDir = ConfigurationSettings.AppSettings["STEAMWORKS_DIRECTORY"]; var appScriptTemplatePath = Path.Combine(steamworksDir, "scripts", steamSettings.AppScriptTemplate); if (File.Exists(appScriptTemplatePath)) { var allText = File.ReadAllText(appScriptTemplatePath); allText = allText.Replace("$buildNumber$", buildDefinition.BuildNumber.ToString()); allText = allText.Replace("$fileName$", buildDefinition.FileName); allText = allText.Replace("$commitId$", buildDefinition.CommitId); allText = allText.Replace("$commitMessage$", buildDefinition.CommitMessage); allText = allText.Replace("$scmBranch$", buildDefinition.ScmBranch); steamSettings.AppScript = steamSettings.AppScriptTemplate.Replace("template", buildDefinition.BuildNumber.ToString()); var appScriptPath = Path.Combine(steamworksDir, "scripts", steamSettings.AppScript); File.WriteAllText(appScriptPath, allText); } else { Trace.TraceError("App Script Template not found {0}", appScriptTemplatePath); } }
private static bool UploadBuildToSteamworks(SteamSettings steamSettings, BuildDefinition buildDefinition) { var steamworksDir = ConfigurationSettings.AppSettings["STEAMWORKS_DIRECTORY"]; lastSteamErrorMessage = null; BuildFinalAppScript(steamSettings, buildDefinition); Trace.TraceInformation("Invoking Steamworks SDK to upload build"); string command = string.Format( @"{0}\Publish-Build.bat {1} ""{2}"" {3} {4} ""{5}"" {6}", steamworksDir, steamSettings.Username, steamSettings.Password, steamSettings.AppId, steamSettings.AppScript, Environment.CurrentDirectory + "\\" + steamSettings.ExecutablePath, steamSettings.UseDRM); int exitCode; ProcessStartInfo processInfo; Process process; processInfo = new ProcessStartInfo("cmd.exe", "/c " + command); processInfo.WorkingDirectory = Environment.CurrentDirectory; processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; // *** Redirect the output *** processInfo.RedirectStandardError = true; processInfo.RedirectStandardOutput = true; process = Process.Start(processInfo); process.WaitForExit(); // *** Read the streams *** // Warning: This approach can lead to deadlocks, see Edit #2 string output = process.StandardOutput.ReadToEnd(); string error = process.StandardError.ReadToEnd(); lastSteamErrorMessage = output + "\n" + error; exitCode = process.ExitCode; Trace.TraceInformation(output); if (exitCode == 0) { Trace.TraceInformation("Steamworks SDK finished successfully"); } else { Trace.TraceError(error); Trace.TraceError("Steamworks SDK failed"); } process.Close(); var appScriptPath = Path.Combine(steamworksDir, "scripts", steamSettings.AppScript); if (File.Exists(appScriptPath)) { Trace.TraceInformation("Removing temporary App Script file"); File.Delete(appScriptPath); } return(exitCode == 0); }