1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 15:32:54 +08:00

Add ability to bootstrap the releases directory using github release API.

This commit is contained in:
Dean Herbert 2017-02-13 12:31:55 +09:00
parent cef3454e9b
commit 2c95d7c67b
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
5 changed files with 163 additions and 24 deletions

View File

@ -3,4 +3,12 @@
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup> </startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration> </configuration>

View File

@ -0,0 +1,13 @@
using Newtonsoft.Json;
namespace osu.Desktop.Deploy
{
internal class GitHubObject
{
[JsonProperty(@"id")]
public int Id;
[JsonProperty(@"name")]
public string Name;
}
}

View File

@ -2,9 +2,11 @@
// 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;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using osu.Framework.IO.Network;
namespace osu.Desktop.Deploy namespace osu.Desktop.Deploy
{ {
@ -20,7 +22,9 @@ namespace osu.Desktop.Deploy
public static string ProjectName = "osu.Desktop"; public static string ProjectName = "osu.Desktop";
public static string CodeSigningCert => Path.Combine(homeDir, "deanherbert.pfx"); public static string CodeSigningCert => Path.Combine(homeDir, "deanherbert.pfx");
private static string codeSigningCmd => $"/a /f {CodeSigningCert} /p {codeSigningPassword} /t http://timestamp.comodoca.com/authenticode"; 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 homeDir => Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); private static string homeDir => Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
@ -28,68 +32,149 @@ namespace osu.Desktop.Deploy
private static string stagingPath => Path.Combine(solutionPath, StagingFolder); 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, "lazer.ico");
private static string nupkgFilename(string ver) => $"osulazer.{ver}.nupkg";
private static string nupkgDistroFilename(string ver) => $"osulazer-{ver}-full.nupkg";
private static string codeSigningPassword; private static string codeSigningPassword;
public static void Main(string[] args) public static void Main(string[] args)
{ {
findSolutionPath(); findSolutionPath();
if (Directory.Exists(StagingFolder))
Directory.Delete(StagingFolder, true);
Directory.CreateDirectory(StagingFolder);
string verBase = DateTime.Now.ToString("yyyy.Md.");
int increment = 0;
if (!Directory.Exists(ReleasesFolder)) if (!Directory.Exists(ReleasesFolder))
{ {
Console.WriteLine("WARNING: No files found in the release directory. Make sure you want this."); Console.WriteLine("WARNING: No files found in the release directory. Make sure you want this.");
Directory.CreateDirectory(ReleasesFolder); Directory.CreateDirectory(ReleasesFolder);
} }
else
Console.WriteLine("Checking github releases...");
var req = new JsonWebRequest<List<GitHubObject>>("https://api.github.com/repos/ppy/osu/releases");
req.BlockingPerform();
if (req.ResponseObject.Count > 0)
{ {
Console.WriteLine("Existing releases:"); var release = req.ResponseObject[0];
foreach (var l in File.ReadAllLines(Path.Combine(ReleasesFolder, "RELEASES"))) Console.WriteLine($"Last version pushed was {release.Name}");
Console.WriteLine(l);
Console.WriteLine(); 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;
//increment build number until we have a unique one. //increment build number until we have a unique one.
while (Directory.GetFiles(ReleasesFolder, $"*{verBase}{increment}*").Any()) while (Directory.GetFiles(ReleasesFolder, $"*{verBase}{increment}*").Any())
increment++; increment++;
string ver = $"{verBase}{increment}"; string version = $"{verBase}{increment}";
Console.Write(ver); Console.Write($"Ready to deploy {version}: ");
version += Console.ReadLine();
ver += Console.ReadLine();
Console.WriteLine("Enter code signing password:");
Console.Write("Enter code signing password: ");
var fg = Console.ForegroundColor;
Console.ForegroundColor = Console.BackgroundColor;
codeSigningPassword = Console.ReadLine(); codeSigningPassword = Console.ReadLine();
Console.ForegroundColor = fg;
Console.WriteLine("Restoring NuGet packages..."); Console.WriteLine("Restoring NuGet packages...");
runCommand(nuget_path, "restore " + solutionPath); runCommand(nuget_path, "restore " + solutionPath);
Console.WriteLine("Updating AssemblyInfo...");
updateAssemblyInfo(version);
Console.WriteLine("Running build process..."); 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:Client\\{ProjectName.Replace('.', '_')} /p:OutputPath={stagingPath};Configuration=Release osu.sln");
Console.WriteLine("Creating NuGet deployment package..."); Console.WriteLine("Creating NuGet deployment package...");
runCommand(nuget_path, $"pack osu.Desktop\\osu.nuspec -Version {ver} -Properties Configuration=Deploy -OutputDirectory {stagingPath} -BasePath {stagingPath}"); runCommand(nuget_path, $"pack osu.Desktop\\osu.nuspec -Version {version} -Properties Configuration=Deploy -OutputDirectory {stagingPath} -BasePath {stagingPath}");
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 fulls = releaseLines.Where(l => l.Filename.Contains("-full")).Reverse().Skip(1);
//remove any FULL releases (except most recent)
foreach (var l in fulls)
{
Console.WriteLine($"- Removing old release {l.Filename}");
File.Delete(Path.Combine(ReleasesFolder, l.Filename));
releaseLines.Remove(l);
}
//remove excess deltas
var deltas = releaseLines.Where(l => l.Filename.Contains("-delta"));
if (deltas.Count() > keep_delta_count)
{
foreach (var l in deltas.Take(deltas.Count() - keep_delta_count))
{
Console.WriteLine($"- Removing old delta {l.Filename}");
File.Delete(Path.Combine(ReleasesFolder, l.Filename));
releaseLines.Remove(l);
}
}
//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());
File.WriteAllLines(Path.Combine(ReleasesFolder, "RELEASES"), lines);
Console.WriteLine("Releasifying package..."); Console.WriteLine("Releasifying package...");
runCommand(squirrel_path, $"--releasify {stagingPath}\\osulazer.{ver}.nupkg --setupIcon {iconPath} --icon {iconPath} -n \"{codeSigningCmd}\" --no-msi"); runCommand(squirrel_path, $"--releasify {stagingPath}\\{nupkgFilename(version)} --setupIcon {iconPath} --icon {iconPath} {codeSigningCmd} --no-msi");
//rename setup to install. //rename setup to install.
File.Copy(Path.Combine(ReleasesFolder, "Setup.exe"), Path.Combine(ReleasesFolder, "install.exe"), true); File.Copy(Path.Combine(ReleasesFolder, "Setup.exe"), Path.Combine(ReleasesFolder, "install.exe"), true);
File.Delete(Path.Combine(ReleasesFolder, "Setup.exe")); File.Delete(Path.Combine(ReleasesFolder, "Setup.exe"));
Console.WriteLine("Done!"); Console.WriteLine("Done!");
Console.ReadLine(); Console.ReadLine();
} }
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);
}
/// <summary> /// <summary>
/// Find the base path of the osu! solution (git checkout location) /// Find the base path of the osu! solution (git checkout location)
/// </summary> /// </summary>
@ -136,4 +221,21 @@ namespace osu.Desktop.Deploy
Environment.Exit(-1); Environment.Exit(-1);
} }
} }
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}";
}
} }

View File

@ -68,6 +68,10 @@
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath> <HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Squirrel, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="NuGet.Squirrel, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\squirrel.windows.1.5.2\lib\Net45\NuGet.Squirrel.dll</HintPath> <HintPath>..\packages\squirrel.windows.1.5.2\lib\Net45\NuGet.Squirrel.dll</HintPath>
<Private>True</Private> <Private>True</Private>
@ -90,6 +94,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="GitHubObject.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
@ -97,6 +102,16 @@
<None Include="App.config" /> <None Include="App.config" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\osu-framework\osu.Framework.Desktop\osu.Framework.Desktop.csproj">
<Project>{65dc628f-a640-4111-ab35-3a5652bc1e17}</Project>
<Name>osu.Framework.Desktop</Name>
</ProjectReference>
<ProjectReference Include="..\osu-framework\osu.Framework\osu.Framework.csproj">
<Project>{C76BF5B3-985E-4D39-95FE-97C9C879B83A}</Project>
<Name>osu.Framework</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -2,6 +2,7 @@
<packages> <packages>
<package id="DeltaCompressionDotNet" version="1.0.0" targetFramework="net452" /> <package id="DeltaCompressionDotNet" version="1.0.0" targetFramework="net452" />
<package id="Mono.Cecil" version="0.9.6.1" targetFramework="net452" /> <package id="Mono.Cecil" version="0.9.6.1" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
<package id="NuGet.CommandLine" version="3.5.0" targetFramework="net452" developmentDependency="true" /> <package id="NuGet.CommandLine" version="3.5.0" targetFramework="net452" developmentDependency="true" />
<package id="Splat" version="1.6.2" targetFramework="net452" /> <package id="Splat" version="1.6.2" targetFramework="net452" />
<package id="squirrel.windows" version="1.5.2" targetFramework="net452" /> <package id="squirrel.windows" version="1.5.2" targetFramework="net452" />