mirror of
https://github.com/ppy/osu
synced 2025-01-02 04:12:13 +00:00
Add complete publish automation.
Uses AppSettings to allow for secret storage.
This commit is contained in:
parent
2c95d7c67b
commit
05a014958f
@ -1,8 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
<appSettings>
|
||||
<add key="StagingFolder" value="Staging" />
|
||||
<add key="ReleasesFolder" value="Releases" />
|
||||
<add key="GitHubAccessToken" value="" />
|
||||
<add key="GitHubUsername" value="ppy" />
|
||||
<add key="GitHubRepoName" value="osu" />
|
||||
<add key="ProjectName" value="osu.Desktop" />
|
||||
<add key="NuSpecName" value="osu.Desktop\osu.nuspec" />
|
||||
<add key="SolutionName" value="osu" />
|
||||
<add key="TargetName" value="Client\osu.Desktop" />
|
||||
<add key="PackageName" value="osulazer" />
|
||||
<add key="IconName" value="lazer.ico" />
|
||||
<add key="CodeSigningCertificate" value="" />
|
||||
</appSettings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
|
25
osu.Desktop.Deploy/GitHubRelease.cs
Normal file
25
osu.Desktop.Deploy/GitHubRelease.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace osu.Desktop.Deploy
|
||||
{
|
||||
internal class GitHubRelease
|
||||
{
|
||||
[JsonProperty(@"id")]
|
||||
public int Id;
|
||||
|
||||
[JsonProperty(@"tag_name")]
|
||||
public string TagName => $"v{Name}";
|
||||
|
||||
[JsonProperty(@"name")]
|
||||
public string Name;
|
||||
|
||||
[JsonProperty(@"draft")]
|
||||
public bool Draft;
|
||||
|
||||
[JsonProperty(@"prerelease")]
|
||||
public bool PreRelease;
|
||||
|
||||
[JsonProperty(@"upload_url")]
|
||||
public string UploadUrl;
|
||||
}
|
||||
}
|
@ -1,12 +1,17 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
|
||||
// Licensed under the MIT Licence - https://raw.GitHubusercontent.com/ppy/osu-framework/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.IO.Network;
|
||||
using FileWebRequest = osu.Framework.IO.Network.FileWebRequest;
|
||||
using WebRequest = osu.Framework.IO.Network.WebRequest;
|
||||
|
||||
namespace osu.Desktop.Deploy
|
||||
{
|
||||
@ -16,24 +21,37 @@ namespace osu.Desktop.Deploy
|
||||
private const string squirrel_path = @"packages\squirrel.windows.1.5.2\tools\Squirrel.exe";
|
||||
private const string msbuild_path = @"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe";
|
||||
|
||||
public static string StagingFolder = "Staging";
|
||||
public static string ReleasesFolder = "Releases";
|
||||
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"];
|
||||
public static string TargetName = ConfigurationManager.AppSettings["TargetName"];
|
||||
public static string PackageName = ConfigurationManager.AppSettings["PackageName"];
|
||||
public static string IconName = ConfigurationManager.AppSettings["IconName"];
|
||||
public static string CodeSigningCertificate = ConfigurationManager.AppSettings["CodeSigningCertificate"];
|
||||
|
||||
public static string ProjectName = "osu.Desktop";
|
||||
public static string CodeSigningCert => Path.Combine(homeDir, "deanherbert.pfx");
|
||||
public static string GitHubApiEndpoint => $"https://api.github.com/repos/{GitHubUsername}/{GitHubRepoName}/releases";
|
||||
public static string GitHubReleasePage => $"https://github.com/{GitHubUsername}/{GitHubRepoName}/releases";
|
||||
|
||||
/// <summary>
|
||||
/// How many previous build deltas we want to keep when publishing.
|
||||
/// </summary>
|
||||
const int keep_delta_count = 3;
|
||||
|
||||
private static string codeSigningCmd => string.IsNullOrEmpty(codeSigningPassword) ? "" : $"-n \"/a /f {CodeSigningCert} /p {codeSigningPassword} /t http://timestamp.comodoca.com/authenticode\"";
|
||||
private static string codeSigningCmd => string.IsNullOrEmpty(codeSigningPassword) ? "" : $"-n \"/a /f {codeSigningCertPath} /p {codeSigningPassword} /t http://timestamp.comodoca.com/authenticode\"";
|
||||
|
||||
private static string homeDir => Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
|
||||
private static string codeSigningCertPath => Path.Combine(homeDir, CodeSigningCertificate);
|
||||
private static string solutionPath => Environment.CurrentDirectory;
|
||||
private static string stagingPath => Path.Combine(solutionPath, StagingFolder);
|
||||
private static string iconPath => Path.Combine(solutionPath, ProjectName, "lazer.ico");
|
||||
private static string iconPath => Path.Combine(solutionPath, ProjectName, IconName);
|
||||
|
||||
private static string nupkgFilename(string ver) => $"osulazer.{ver}.nupkg";
|
||||
private static string nupkgDistroFilename(string ver) => $"osulazer-{ver}-full.nupkg";
|
||||
private static string nupkgFilename(string ver) => $"{PackageName}.{ver}.nupkg";
|
||||
private static string nupkgDistroFilename(string ver) => $"{PackageName}-{ver}-full.nupkg";
|
||||
|
||||
private static string codeSigningPassword;
|
||||
|
||||
@ -47,54 +65,29 @@ namespace osu.Desktop.Deploy
|
||||
Directory.CreateDirectory(ReleasesFolder);
|
||||
}
|
||||
|
||||
Console.WriteLine("Checking github releases...");
|
||||
checkGitHubReleases();
|
||||
|
||||
var req = new JsonWebRequest<List<GitHubObject>>("https://api.github.com/repos/ppy/osu/releases");
|
||||
req.BlockingPerform();
|
||||
|
||||
if (req.ResponseObject.Count > 0)
|
||||
{
|
||||
var release = req.ResponseObject[0];
|
||||
Console.WriteLine($"Last version pushed was {release.Name}");
|
||||
|
||||
if (!File.Exists(Path.Combine(ReleasesFolder, nupkgDistroFilename(release.Name))))
|
||||
{
|
||||
Console.WriteLine("Not found locally; let's pull down last release data.");
|
||||
|
||||
req = new JsonWebRequest<List<GitHubObject>>($"https://api.github.com/repos/ppy/osu/releases/{release.Id}/assets");
|
||||
req.BlockingPerform();
|
||||
|
||||
foreach (var asset in req.ResponseObject)
|
||||
{
|
||||
Console.WriteLine($"Downloading {asset.Name}...");
|
||||
var dl = new FileWebRequest(Path.Combine(ReleasesFolder, asset.Name), $"https://api.github.com/repos/ppy/osu/releases/assets/{asset.Id}");
|
||||
dl.BlockingPerform();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Directory.Exists(StagingFolder))
|
||||
Directory.Delete(StagingFolder, true);
|
||||
Directory.CreateDirectory(StagingFolder);
|
||||
|
||||
string verBase = DateTime.Now.ToString("yyyy.Md.");
|
||||
int increment = 0;
|
||||
refreshDirectory(StagingFolder);
|
||||
|
||||
//increment build number until we have a unique one.
|
||||
string verBase = DateTime.Now.ToString("yyyy.Md.");
|
||||
int increment = 0;
|
||||
while (Directory.GetFiles(ReleasesFolder, $"*{verBase}{increment}*").Any())
|
||||
increment++;
|
||||
|
||||
string version = $"{verBase}{increment}";
|
||||
|
||||
Console.Write($"Ready to deploy {version}: ");
|
||||
version += Console.ReadLine();
|
||||
|
||||
Console.Write("Enter code signing password: ");
|
||||
var fg = Console.ForegroundColor;
|
||||
Console.ForegroundColor = Console.BackgroundColor;
|
||||
codeSigningPassword = Console.ReadLine();
|
||||
Console.ForegroundColor = fg;
|
||||
Console.ReadLine();
|
||||
|
||||
if (!string.IsNullOrEmpty(CodeSigningCertificate))
|
||||
{
|
||||
Console.Write("Enter code signing password: ");
|
||||
var fg = Console.ForegroundColor;
|
||||
Console.ForegroundColor = Console.BackgroundColor;
|
||||
codeSigningPassword = Console.ReadLine();
|
||||
Console.ForegroundColor = fg;
|
||||
}
|
||||
|
||||
Console.WriteLine("Restoring NuGet packages...");
|
||||
runCommand(nuget_path, "restore " + solutionPath);
|
||||
@ -103,15 +96,53 @@ namespace osu.Desktop.Deploy
|
||||
updateAssemblyInfo(version);
|
||||
|
||||
Console.WriteLine("Running build process...");
|
||||
runCommand(msbuild_path, $"/v:quiet /m /t:Client\\{ProjectName.Replace('.', '_')} /p:OutputPath={stagingPath};Configuration=Release osu.sln");
|
||||
runCommand(msbuild_path, $"/v:quiet /m /t:{TargetName.Replace('.', '_')} /p:OutputPath={stagingPath};Configuration=Release {SolutionName}.sln");
|
||||
|
||||
Console.WriteLine("Creating NuGet deployment package...");
|
||||
runCommand(nuget_path, $"pack osu.Desktop\\osu.nuspec -Version {version} -Properties Configuration=Deploy -OutputDirectory {stagingPath} -BasePath {stagingPath}");
|
||||
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();
|
||||
|
||||
checkReleaseFiles();
|
||||
|
||||
Console.WriteLine("Releasifying package...");
|
||||
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);
|
||||
|
||||
Console.WriteLine("Done!");
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
/// <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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
Console.WriteLine("Pruning RELEASES...");
|
||||
|
||||
var releaseLines = new List<ReleaseLine>();
|
||||
foreach (var l in File.ReadAllLines(Path.Combine(ReleasesFolder, "RELEASES"))) releaseLines.Add(new ReleaseLine(l));
|
||||
var releaseLines = getReleaseLines().ToList();
|
||||
|
||||
var fulls = releaseLines.Where(l => l.Filename.Contains("-full")).Reverse().Skip(1);
|
||||
|
||||
@ -135,25 +166,115 @@ namespace osu.Desktop.Deploy
|
||||
}
|
||||
}
|
||||
|
||||
//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}");
|
||||
|
||||
List<string> lines = new List<string>();
|
||||
foreach (var l in releaseLines)
|
||||
lines.Add(l.ToString());
|
||||
var lines = new List<string>();
|
||||
releaseLines.ForEach(l => lines.Add(l.ToString()));
|
||||
File.WriteAllLines(Path.Combine(ReleasesFolder, "RELEASES"), lines);
|
||||
}
|
||||
|
||||
Console.WriteLine("Releasifying package...");
|
||||
runCommand(squirrel_path, $"--releasify {stagingPath}\\{nupkgFilename(version)} --setupIcon {iconPath} --icon {iconPath} {codeSigningCmd} --no-msi");
|
||||
private static void uploadBuild(string version)
|
||||
{
|
||||
if (string.IsNullOrEmpty(GitHubAccessToken) || string.IsNullOrEmpty(codeSigningCertPath))
|
||||
return;
|
||||
|
||||
//rename setup to install.
|
||||
File.Copy(Path.Combine(ReleasesFolder, "Setup.exe"), Path.Combine(ReleasesFolder, "install.exe"), true);
|
||||
File.Delete(Path.Combine(ReleasesFolder, "Setup.exe"));
|
||||
Console.WriteLine("Publishing to GitHub...");
|
||||
|
||||
Console.WriteLine("Done!");
|
||||
Console.ReadLine();
|
||||
Console.WriteLine($"- Creating release {version}...");
|
||||
var req = new JsonWebRequest<GitHubRelease>($"{GitHubApiEndpoint}")
|
||||
{
|
||||
Method = HttpMethod.POST
|
||||
};
|
||||
req.AddRaw(JsonConvert.SerializeObject(new GitHubRelease
|
||||
{
|
||||
Name = version,
|
||||
Draft = true,
|
||||
PreRelease = true
|
||||
}));
|
||||
req.AuthenticatedBlockingPerform();
|
||||
|
||||
var assetUploadUrl = req.ResponseObject.UploadUrl.Replace("{?name,label}", "?name={0}");
|
||||
foreach (var a in Directory.GetFiles(ReleasesFolder))
|
||||
{
|
||||
Console.WriteLine($"- Adding asset {a}...");
|
||||
var upload = new WebRequest(assetUploadUrl, Path.GetFileName(a))
|
||||
{
|
||||
Method = HttpMethod.POST,
|
||||
ContentType = "application/octet-stream",
|
||||
};
|
||||
|
||||
upload.AddRaw(File.ReadAllBytes(a));
|
||||
upload.AuthenticatedBlockingPerform();
|
||||
}
|
||||
|
||||
openGitHubReleasePage();
|
||||
}
|
||||
|
||||
private static void openGitHubReleasePage() => Process.Start(GitHubReleasePage);
|
||||
|
||||
private static void checkGitHubReleases()
|
||||
{
|
||||
Console.WriteLine("Checking GitHub releases...");
|
||||
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;
|
||||
|
||||
Console.WriteLine($"Last GitHub release was {lastRelease.Name}.");
|
||||
|
||||
bool requireDownload = false;
|
||||
|
||||
if (!File.Exists(Path.Combine(ReleasesFolder, nupkgDistroFilename(lastRelease.Name))))
|
||||
{
|
||||
Console.WriteLine($"! Last verion's package not found locally.");
|
||||
requireDownload = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var lastReleases = new RawFileWebRequest($"{GitHubApiEndpoint}/assets/{releaseAsset.Id}");
|
||||
lastReleases.AuthenticatedBlockingPerform();
|
||||
if (File.ReadAllText(Path.Combine(ReleasesFolder, "RELEASES")) != lastReleases.ResponseString)
|
||||
{
|
||||
Console.WriteLine("! Server's RELEASES differed from ours.");
|
||||
requireDownload = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!requireDownload) return;
|
||||
|
||||
Console.WriteLine("Refreshing local releases directory...");
|
||||
refreshDirectory(ReleasesFolder);
|
||||
|
||||
foreach (var a in assets)
|
||||
{
|
||||
Console.WriteLine($"- Downloading {a.Name}...");
|
||||
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);
|
||||
}
|
||||
|
||||
private static void updateAssemblyInfo(string version)
|
||||
@ -176,7 +297,7 @@ namespace osu.Desktop.Deploy
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the base path of the osu! solution (git checkout location)
|
||||
/// Find the base path of the active solution (git checkout location)
|
||||
/// </summary>
|
||||
private static void findSolutionPath()
|
||||
{
|
||||
@ -185,7 +306,7 @@ namespace osu.Desktop.Deploy
|
||||
if (string.IsNullOrEmpty(path))
|
||||
path = Environment.CurrentDirectory;
|
||||
|
||||
while (!File.Exists(path + "\\osu.sln"))
|
||||
while (!File.Exists(Path.Combine(path, $"{SolutionName}.sln")))
|
||||
path = path.Remove(path.LastIndexOf('\\'));
|
||||
path += "\\";
|
||||
|
||||
@ -220,6 +341,26 @@ namespace osu.Desktop.Deploy
|
||||
Console.ReadLine();
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
|
||||
public static void AuthenticatedBlockingPerform(this WebRequest r)
|
||||
{
|
||||
r.AddHeader("Authorization", $"token {GitHubAccessToken}");
|
||||
r.BlockingPerform();
|
||||
}
|
||||
}
|
||||
|
||||
internal class RawFileWebRequest : WebRequest
|
||||
{
|
||||
public RawFileWebRequest(string url) : base(url)
|
||||
{
|
||||
}
|
||||
|
||||
protected override HttpWebRequest CreateWebRequest(string requestString = null)
|
||||
{
|
||||
var req = base.CreateWebRequest(requestString);
|
||||
req.Accept = "application/octet-stream";
|
||||
return req;
|
||||
}
|
||||
}
|
||||
|
||||
internal class ReleaseLine
|
||||
|
@ -85,6 +85,7 @@
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
@ -95,6 +96,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GitHubObject.cs" />
|
||||
<Compile Include="GitHubRelease.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user