2018-01-05 11:21:19 +00:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-03-08 06:50:52 +00:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2017-02-13 01:06:19 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
2017-02-13 03:31:55 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-02-13 07:48:53 +00:00
|
|
|
|
using System.Configuration;
|
2017-02-12 16:02:44 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2017-02-13 07:48:53 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2017-02-13 03:31:55 +00:00
|
|
|
|
using osu.Framework.IO.Network;
|
2017-02-13 07:48:53 +00:00
|
|
|
|
using FileWebRequest = osu.Framework.IO.Network.FileWebRequest;
|
|
|
|
|
using WebRequest = osu.Framework.IO.Network.WebRequest;
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Desktop.Deploy
|
|
|
|
|
{
|
2017-02-13 01:06:19 +00:00
|
|
|
|
internal static class Program
|
2017-02-12 16:02:44 +00:00
|
|
|
|
{
|
2017-09-13 12:02:07 +00:00
|
|
|
|
private const string nuget_path = @"packages\NuGet.CommandLine.4.3.0\tools\NuGet.exe";
|
|
|
|
|
private const string squirrel_path = @"packages\squirrel.windows.1.7.8\tools\Squirrel.exe";
|
2017-10-24 13:11:20 +00:00
|
|
|
|
private const string msbuild_path = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe";
|
2017-02-13 01:06:19 +00:00
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
public static string StagingFolder = ConfigurationManager.AppSettings["StagingFolder"];
|
|
|
|
|
public static string ReleasesFolder = ConfigurationManager.AppSettings["ReleasesFolder"];
|
|
|
|
|
public static string GitHubAccessToken = ConfigurationManager.AppSettings["GitHubAccessToken"];
|
|
|
|
|
public static string GitHubUsername = ConfigurationManager.AppSettings["GitHubUsername"];
|
|
|
|
|
public static string GitHubRepoName = ConfigurationManager.AppSettings["GitHubRepoName"];
|
|
|
|
|
public static string SolutionName = ConfigurationManager.AppSettings["SolutionName"];
|
|
|
|
|
public static string ProjectName = ConfigurationManager.AppSettings["ProjectName"];
|
|
|
|
|
public static string NuSpecName = ConfigurationManager.AppSettings["NuSpecName"];
|
2017-09-19 14:35:23 +00:00
|
|
|
|
public static string TargetNames = ConfigurationManager.AppSettings["TargetName"];
|
2017-02-13 07:48:53 +00:00
|
|
|
|
public static string PackageName = ConfigurationManager.AppSettings["PackageName"];
|
|
|
|
|
public static string IconName = ConfigurationManager.AppSettings["IconName"];
|
|
|
|
|
public static string CodeSigningCertificate = ConfigurationManager.AppSettings["CodeSigningCertificate"];
|
|
|
|
|
|
|
|
|
|
public static string GitHubApiEndpoint => $"https://api.github.com/repos/{GitHubUsername}/{GitHubRepoName}/releases";
|
|
|
|
|
public static string GitHubReleasePage => $"https://github.com/{GitHubUsername}/{GitHubRepoName}/releases";
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// How many previous build deltas we want to keep when publishing.
|
|
|
|
|
/// </summary>
|
2017-03-07 01:59:19 +00:00
|
|
|
|
private const int keep_delta_count = 3;
|
2017-02-13 03:31:55 +00:00
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
private static string codeSigningCmd => string.IsNullOrEmpty(codeSigningPassword) ? "" : $"-n \"/a /f {codeSigningCertPath} /p {codeSigningPassword} /t http://timestamp.comodoca.com/authenticode\"";
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
2017-02-13 01:06:19 +00:00
|
|
|
|
private static string homeDir => Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
2017-02-13 07:48:53 +00:00
|
|
|
|
private static string codeSigningCertPath => Path.Combine(homeDir, CodeSigningCertificate);
|
2017-02-13 01:06:19 +00:00
|
|
|
|
private static string solutionPath => Environment.CurrentDirectory;
|
|
|
|
|
private static string stagingPath => Path.Combine(solutionPath, StagingFolder);
|
2017-02-13 07:48:53 +00:00
|
|
|
|
private static string iconPath => Path.Combine(solutionPath, ProjectName, IconName);
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
private static string nupkgFilename(string ver) => $"{PackageName}.{ver}.nupkg";
|
|
|
|
|
private static string nupkgDistroFilename(string ver) => $"{PackageName}-{ver}-full.nupkg";
|
2017-02-13 03:31:55 +00:00
|
|
|
|
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private static readonly Stopwatch sw = new Stopwatch();
|
2017-02-13 08:40:41 +00:00
|
|
|
|
|
2017-02-13 01:06:19 +00:00
|
|
|
|
private static string codeSigningPassword;
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
2017-02-13 01:06:19 +00:00
|
|
|
|
public static void Main(string[] args)
|
2017-02-12 16:02:44 +00:00
|
|
|
|
{
|
2017-02-13 08:40:41 +00:00
|
|
|
|
displayHeader();
|
|
|
|
|
|
2017-02-13 01:06:19 +00:00
|
|
|
|
findSolutionPath();
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
2017-02-13 01:06:19 +00:00
|
|
|
|
if (!Directory.Exists(ReleasesFolder))
|
|
|
|
|
{
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write("WARNING: No release directory found. Make sure you want this!", ConsoleColor.Yellow);
|
2017-02-13 01:06:19 +00:00
|
|
|
|
Directory.CreateDirectory(ReleasesFolder);
|
|
|
|
|
}
|
2017-02-13 03:31:55 +00:00
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
checkGitHubReleases();
|
2017-02-13 03:31:55 +00:00
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
refreshDirectory(StagingFolder);
|
2017-02-13 03:31:55 +00:00
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
//increment build number until we have a unique one.
|
2017-03-02 11:08:01 +00:00
|
|
|
|
string verBase = DateTime.Now.ToString("yyyy.Mdd.");
|
2017-02-13 03:31:55 +00:00
|
|
|
|
int increment = 0;
|
2017-02-13 01:06:19 +00:00
|
|
|
|
while (Directory.GetFiles(ReleasesFolder, $"*{verBase}{increment}*").Any())
|
2017-02-12 16:02:44 +00:00
|
|
|
|
increment++;
|
|
|
|
|
|
2017-02-13 03:31:55 +00:00
|
|
|
|
string version = $"{verBase}{increment}";
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.White;
|
2017-02-13 03:31:55 +00:00
|
|
|
|
Console.Write($"Ready to deploy {version}: ");
|
2017-02-13 07:48:53 +00:00
|
|
|
|
Console.ReadLine();
|
2017-02-13 03:31:55 +00:00
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
sw.Start();
|
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(CodeSigningCertificate))
|
|
|
|
|
{
|
|
|
|
|
Console.Write("Enter code signing password: ");
|
2017-02-13 08:40:41 +00:00
|
|
|
|
codeSigningPassword = readLineMasked();
|
2017-02-13 07:48:53 +00:00
|
|
|
|
}
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write("Restoring NuGet packages...");
|
2017-02-13 01:06:19 +00:00
|
|
|
|
runCommand(nuget_path, "restore " + solutionPath);
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write("Updating AssemblyInfo...");
|
2017-02-13 03:31:55 +00:00
|
|
|
|
updateAssemblyInfo(version);
|
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write("Running build process...");
|
2017-09-19 14:35:23 +00:00
|
|
|
|
foreach (string targetName in TargetNames.Split(','))
|
|
|
|
|
runCommand(msbuild_path, $"/v:quiet /m /t:{targetName.Replace('.', '_')} /p:OutputPath={stagingPath};Targets=\"Clean;Build\";Configuration=Release {SolutionName}.sln");
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write("Creating NuGet deployment package...");
|
2017-02-13 07:48:53 +00:00
|
|
|
|
runCommand(nuget_path, $"pack {NuSpecName} -Version {version} -Properties Configuration=Deploy -OutputDirectory {stagingPath} -BasePath {stagingPath}");
|
|
|
|
|
|
|
|
|
|
//prune once before checking for files so we can avoid erroring on files which aren't even needed for this build.
|
|
|
|
|
pruneReleases();
|
2017-02-13 03:31:55 +00:00
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
checkReleaseFiles();
|
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write("Running squirrel build...");
|
2017-02-13 07:48:53 +00:00
|
|
|
|
runCommand(squirrel_path, $"--releasify {stagingPath}\\{nupkgFilename(version)} --setupIcon {iconPath} --icon {iconPath} {codeSigningCmd} --no-msi");
|
|
|
|
|
|
|
|
|
|
//prune again to clean up before upload.
|
|
|
|
|
pruneReleases();
|
|
|
|
|
|
|
|
|
|
//rename setup to install.
|
|
|
|
|
File.Copy(Path.Combine(ReleasesFolder, "Setup.exe"), Path.Combine(ReleasesFolder, "install.exe"), true);
|
|
|
|
|
File.Delete(Path.Combine(ReleasesFolder, "Setup.exe"));
|
|
|
|
|
|
|
|
|
|
uploadBuild(version);
|
|
|
|
|
|
2017-02-15 04:40:13 +00:00
|
|
|
|
//reset assemblyinfo.
|
|
|
|
|
updateAssemblyInfo("0.0.0");
|
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write("Done!", ConsoleColor.White);
|
2017-02-13 07:48:53 +00:00
|
|
|
|
Console.ReadLine();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
private static void displayHeader()
|
|
|
|
|
{
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
Console.WriteLine(" Please note that OSU! and PPY are registered trademarks and as such covered by trademark law.");
|
|
|
|
|
Console.WriteLine(" Do not distribute builds of this project publicly that make use of these.");
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ensure we have all the files in the release directory which are expected to be there.
|
|
|
|
|
/// This should have been accounted for in earlier steps, and just serves as a verification step.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static void checkReleaseFiles()
|
|
|
|
|
{
|
2017-11-25 14:05:46 +00:00
|
|
|
|
if (!canGitHub) return;
|
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
var releaseLines = getReleaseLines();
|
|
|
|
|
|
|
|
|
|
//ensure we have all files necessary
|
|
|
|
|
foreach (var l in releaseLines)
|
|
|
|
|
if (!File.Exists(Path.Combine(ReleasesFolder, l.Filename)))
|
|
|
|
|
error($"Local file missing {l.Filename}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IEnumerable<ReleaseLine> getReleaseLines() => File.ReadAllLines(Path.Combine(ReleasesFolder, "RELEASES")).Select(l => new ReleaseLine(l));
|
|
|
|
|
|
|
|
|
|
private static void pruneReleases()
|
|
|
|
|
{
|
2017-11-25 14:05:46 +00:00
|
|
|
|
if (!canGitHub) return;
|
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write("Pruning RELEASES...");
|
2017-02-13 03:31:55 +00:00
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
var releaseLines = getReleaseLines().ToList();
|
2017-02-13 03:31:55 +00:00
|
|
|
|
|
|
|
|
|
var fulls = releaseLines.Where(l => l.Filename.Contains("-full")).Reverse().Skip(1);
|
|
|
|
|
|
|
|
|
|
//remove any FULL releases (except most recent)
|
|
|
|
|
foreach (var l in fulls)
|
|
|
|
|
{
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write($"- Removing old release {l.Filename}", ConsoleColor.Yellow);
|
2017-02-13 03:31:55 +00:00
|
|
|
|
File.Delete(Path.Combine(ReleasesFolder, l.Filename));
|
|
|
|
|
releaseLines.Remove(l);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//remove excess deltas
|
2017-03-07 01:59:19 +00:00
|
|
|
|
var deltas = releaseLines.Where(l => l.Filename.Contains("-delta")).ToArray();
|
|
|
|
|
if (deltas.Length > keep_delta_count)
|
2017-02-13 03:31:55 +00:00
|
|
|
|
{
|
2017-03-07 01:59:19 +00:00
|
|
|
|
foreach (var l in deltas.Take(deltas.Length - keep_delta_count))
|
2017-02-13 03:31:55 +00:00
|
|
|
|
{
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write($"- Removing old delta {l.Filename}", ConsoleColor.Yellow);
|
2017-02-13 03:31:55 +00:00
|
|
|
|
File.Delete(Path.Combine(ReleasesFolder, l.Filename));
|
|
|
|
|
releaseLines.Remove(l);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
var lines = new List<string>();
|
|
|
|
|
releaseLines.ForEach(l => lines.Add(l.ToString()));
|
2017-02-13 03:31:55 +00:00
|
|
|
|
File.WriteAllLines(Path.Combine(ReleasesFolder, "RELEASES"), lines);
|
2017-02-13 07:48:53 +00:00
|
|
|
|
}
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
private static void uploadBuild(string version)
|
|
|
|
|
{
|
2017-11-25 14:05:46 +00:00
|
|
|
|
if (!canGitHub || string.IsNullOrEmpty(CodeSigningCertificate))
|
2017-02-13 07:48:53 +00:00
|
|
|
|
return;
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write("Publishing to GitHub...");
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write($"- Creating release {version}...", ConsoleColor.Yellow);
|
2017-02-13 07:48:53 +00:00
|
|
|
|
var req = new JsonWebRequest<GitHubRelease>($"{GitHubApiEndpoint}")
|
|
|
|
|
{
|
2017-03-14 11:23:18 +00:00
|
|
|
|
Method = HttpMethod.POST,
|
2017-02-13 07:48:53 +00:00
|
|
|
|
};
|
|
|
|
|
req.AddRaw(JsonConvert.SerializeObject(new GitHubRelease
|
|
|
|
|
{
|
|
|
|
|
Name = version,
|
|
|
|
|
Draft = true,
|
|
|
|
|
PreRelease = true
|
|
|
|
|
}));
|
|
|
|
|
req.AuthenticatedBlockingPerform();
|
|
|
|
|
|
|
|
|
|
var assetUploadUrl = req.ResponseObject.UploadUrl.Replace("{?name,label}", "?name={0}");
|
2017-02-13 08:40:41 +00:00
|
|
|
|
foreach (var a in Directory.GetFiles(ReleasesFolder).Reverse()) //reverse to upload RELEASES first.
|
2017-02-13 07:48:53 +00:00
|
|
|
|
{
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write($"- Adding asset {a}...", ConsoleColor.Yellow);
|
2017-02-13 07:48:53 +00:00
|
|
|
|
var upload = new WebRequest(assetUploadUrl, Path.GetFileName(a))
|
|
|
|
|
{
|
|
|
|
|
Method = HttpMethod.POST,
|
2017-03-14 11:23:18 +00:00
|
|
|
|
Timeout = 240000,
|
2017-02-13 07:48:53 +00:00
|
|
|
|
ContentType = "application/octet-stream",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
upload.AddRaw(File.ReadAllBytes(a));
|
|
|
|
|
upload.AuthenticatedBlockingPerform();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openGitHubReleasePage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void openGitHubReleasePage() => Process.Start(GitHubReleasePage);
|
|
|
|
|
|
2017-11-25 14:05:46 +00:00
|
|
|
|
private static bool canGitHub => !string.IsNullOrEmpty(GitHubAccessToken);
|
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
private static void checkGitHubReleases()
|
|
|
|
|
{
|
2017-11-25 14:05:46 +00:00
|
|
|
|
if (!canGitHub) return;
|
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write("Checking GitHub releases...");
|
2017-02-13 07:48:53 +00:00
|
|
|
|
var req = new JsonWebRequest<List<GitHubRelease>>($"{GitHubApiEndpoint}");
|
|
|
|
|
req.AuthenticatedBlockingPerform();
|
|
|
|
|
|
|
|
|
|
var lastRelease = req.ResponseObject.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (lastRelease == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (lastRelease.Draft)
|
|
|
|
|
{
|
|
|
|
|
openGitHubReleasePage();
|
|
|
|
|
error("There's a pending draft release! You probably don't want to push a build with this present.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//there's a previous release for this project.
|
|
|
|
|
var assetReq = new JsonWebRequest<List<GitHubObject>>($"{GitHubApiEndpoint}/{lastRelease.Id}/assets");
|
|
|
|
|
assetReq.AuthenticatedBlockingPerform();
|
|
|
|
|
var assets = assetReq.ResponseObject;
|
|
|
|
|
|
|
|
|
|
//make sure our RELEASES file is the same as the last build on the server.
|
|
|
|
|
var releaseAsset = assets.FirstOrDefault(a => a.Name == "RELEASES");
|
|
|
|
|
|
|
|
|
|
//if we don't have a RELEASES asset then the previous release likely wasn't a Squirrel one.
|
|
|
|
|
if (releaseAsset == null) return;
|
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write($"Last GitHub release was {lastRelease.Name}.");
|
2017-02-13 07:48:53 +00:00
|
|
|
|
|
|
|
|
|
bool requireDownload = false;
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(Path.Combine(ReleasesFolder, nupkgDistroFilename(lastRelease.Name))))
|
|
|
|
|
{
|
2017-03-14 11:23:58 +00:00
|
|
|
|
write("Last version's package not found locally.", ConsoleColor.Red);
|
2017-02-13 07:48:53 +00:00
|
|
|
|
requireDownload = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var lastReleases = new RawFileWebRequest($"{GitHubApiEndpoint}/assets/{releaseAsset.Id}");
|
|
|
|
|
lastReleases.AuthenticatedBlockingPerform();
|
|
|
|
|
if (File.ReadAllText(Path.Combine(ReleasesFolder, "RELEASES")) != lastReleases.ResponseString)
|
|
|
|
|
{
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write("Server's RELEASES differed from ours.", ConsoleColor.Red);
|
2017-02-13 07:48:53 +00:00
|
|
|
|
requireDownload = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!requireDownload) return;
|
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write("Refreshing local releases directory...");
|
2017-02-13 07:48:53 +00:00
|
|
|
|
refreshDirectory(ReleasesFolder);
|
|
|
|
|
|
|
|
|
|
foreach (var a in assets)
|
|
|
|
|
{
|
2017-03-14 11:23:37 +00:00
|
|
|
|
if (a.Name.EndsWith(".exe")) continue;
|
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write($"- Downloading {a.Name}...", ConsoleColor.Yellow);
|
2017-02-13 07:48:53 +00:00
|
|
|
|
new FileWebRequest(Path.Combine(ReleasesFolder, a.Name), $"{GitHubApiEndpoint}/assets/{a.Id}").AuthenticatedBlockingPerform();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void refreshDirectory(string directory)
|
|
|
|
|
{
|
|
|
|
|
if (Directory.Exists(directory))
|
|
|
|
|
Directory.Delete(directory, true);
|
|
|
|
|
Directory.CreateDirectory(directory);
|
2017-02-12 16:02:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 03:31:55 +00:00
|
|
|
|
private static void updateAssemblyInfo(string version)
|
|
|
|
|
{
|
|
|
|
|
string file = Path.Combine(ProjectName, "Properties", "AssemblyInfo.cs");
|
|
|
|
|
|
|
|
|
|
var l1 = File.ReadAllLines(file);
|
|
|
|
|
List<string> l2 = new List<string>();
|
|
|
|
|
foreach (var l in l1)
|
|
|
|
|
{
|
|
|
|
|
if (l.StartsWith("[assembly: AssemblyVersion("))
|
|
|
|
|
l2.Add($"[assembly: AssemblyVersion(\"{version}\")]");
|
|
|
|
|
else if (l.StartsWith("[assembly: AssemblyFileVersion("))
|
|
|
|
|
l2.Add($"[assembly: AssemblyFileVersion(\"{version}\")]");
|
|
|
|
|
else
|
|
|
|
|
l2.Add(l);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File.WriteAllLines(file, l2);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-12 16:02:44 +00:00
|
|
|
|
/// <summary>
|
2017-02-13 07:48:53 +00:00
|
|
|
|
/// Find the base path of the active solution (git checkout location)
|
2017-02-12 16:02:44 +00:00
|
|
|
|
/// </summary>
|
2017-02-13 01:06:19 +00:00
|
|
|
|
private static void findSolutionPath()
|
2017-02-12 16:02:44 +00:00
|
|
|
|
{
|
|
|
|
|
string path = Path.GetDirectoryName(Environment.CommandLine.Replace("\"", "").Trim());
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
|
path = Environment.CurrentDirectory;
|
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
while (!File.Exists(Path.Combine(path, $"{SolutionName}.sln")))
|
2017-02-12 16:02:44 +00:00
|
|
|
|
path = path.Remove(path.LastIndexOf('\\'));
|
|
|
|
|
path += "\\";
|
|
|
|
|
|
|
|
|
|
Environment.CurrentDirectory = path;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 01:06:19 +00:00
|
|
|
|
private static bool runCommand(string command, string args)
|
2017-02-12 16:02:44 +00:00
|
|
|
|
{
|
2017-02-13 01:06:19 +00:00
|
|
|
|
var psi = new ProcessStartInfo(command, args)
|
2017-02-12 16:02:44 +00:00
|
|
|
|
{
|
2017-02-13 01:06:19 +00:00
|
|
|
|
WorkingDirectory = solutionPath,
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
RedirectStandardOutput = true,
|
2017-03-14 11:23:53 +00:00
|
|
|
|
RedirectStandardError = true,
|
2017-02-13 01:06:19 +00:00
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
WindowStyle = ProcessWindowStyle.Hidden
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Process p = Process.Start(psi);
|
2017-03-07 05:57:49 +00:00
|
|
|
|
if (p == null) return false;
|
2017-03-07 01:59:19 +00:00
|
|
|
|
|
2017-02-13 01:06:19 +00:00
|
|
|
|
string output = p.StandardOutput.ReadToEnd();
|
2017-03-14 11:23:53 +00:00
|
|
|
|
output += p.StandardError.ReadToEnd();
|
2017-02-13 01:06:19 +00:00
|
|
|
|
|
2017-03-07 05:57:49 +00:00
|
|
|
|
if (p.ExitCode == 0) return true;
|
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
write(output);
|
2017-02-13 01:06:19 +00:00
|
|
|
|
error($"Command {command} {args} failed!");
|
2017-02-12 16:02:44 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
private static string readLineMasked()
|
|
|
|
|
{
|
|
|
|
|
var fg = Console.ForegroundColor;
|
|
|
|
|
Console.ForegroundColor = Console.BackgroundColor;
|
|
|
|
|
var ret = Console.ReadLine();
|
|
|
|
|
Console.ForegroundColor = fg;
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void error(string message)
|
2017-02-12 16:02:44 +00:00
|
|
|
|
{
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
2017-02-13 08:40:41 +00:00
|
|
|
|
Console.WriteLine($"FATAL ERROR: {message}");
|
2017-02-12 16:02:44 +00:00
|
|
|
|
|
|
|
|
|
Console.ReadLine();
|
|
|
|
|
Environment.Exit(-1);
|
|
|
|
|
}
|
2017-02-13 07:48:53 +00:00
|
|
|
|
|
2017-02-13 08:40:41 +00:00
|
|
|
|
private static void write(string message, ConsoleColor col = ConsoleColor.Gray)
|
|
|
|
|
{
|
|
|
|
|
if (sw.ElapsedMilliseconds > 0)
|
|
|
|
|
{
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
|
|
|
|
Console.Write(sw.ElapsedMilliseconds.ToString().PadRight(8));
|
|
|
|
|
}
|
|
|
|
|
Console.ForegroundColor = col;
|
|
|
|
|
Console.WriteLine(message);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 07:48:53 +00:00
|
|
|
|
public static void AuthenticatedBlockingPerform(this WebRequest r)
|
|
|
|
|
{
|
2017-10-30 12:23:47 +00:00
|
|
|
|
r.AddHeader("Authorization", $"token {GitHubAccessToken}");
|
2017-10-23 05:46:17 +00:00
|
|
|
|
r.Perform();
|
2017-02-13 07:48:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class RawFileWebRequest : WebRequest
|
|
|
|
|
{
|
|
|
|
|
public RawFileWebRequest(string url) : base(url)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-23 05:46:17 +00:00
|
|
|
|
protected override string Accept => "application/octet-stream";
|
2017-02-12 16:02:44 +00:00
|
|
|
|
}
|
2017-02-13 03:31:55 +00:00
|
|
|
|
|
|
|
|
|
internal class ReleaseLine
|
|
|
|
|
{
|
|
|
|
|
public string Hash;
|
|
|
|
|
public string Filename;
|
|
|
|
|
public int Filesize;
|
|
|
|
|
|
|
|
|
|
public ReleaseLine(string line)
|
|
|
|
|
{
|
|
|
|
|
var split = line.Split(' ');
|
|
|
|
|
Hash = split[0];
|
|
|
|
|
Filename = split[1];
|
|
|
|
|
Filesize = int.Parse(split[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString() => $"{Hash} {Filename} {Filesize}";
|
|
|
|
|
}
|
2017-02-12 16:02:44 +00:00
|
|
|
|
}
|