Skip to content

Commit

Permalink
Merge pull request #6 from smoogipoo/rename-assets
Browse files Browse the repository at this point in the history
  • Loading branch information
smallketchup82 authored Aug 31, 2024
2 parents 2cd4e0a + fab6a45 commit 2076306
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Builders/LinuxBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public LinuxBuilder(string version)
protected override string TargetFramework => "net8.0";
protected override string RuntimeIdentifier => $"{os_name}-x64";

public override Uploader CreateUploader() => new VelopackUploader(app_name, os_name, RuntimeIdentifier, RuntimeIdentifier, stagingPath: stagingTarget);
public override Uploader CreateUploader() => new LinuxVelopackUploader(app_name, os_name, RuntimeIdentifier, RuntimeIdentifier, stagingPath: stagingTarget);

public override void Build()
{
Expand Down
2 changes: 1 addition & 1 deletion Builders/MacOSBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override Uploader CreateUploader()
if (!string.IsNullOrEmpty(Program.AppleKeyChainPath))
extraArgs += $" --keychain=\"{Program.AppleKeyChainPath}\"";

return new VelopackUploader(app_name, os_name, RuntimeIdentifier, RuntimeIdentifier, extraArgs: extraArgs, stagingPath: stagingTarget);
return new MacOSVelopackUploader(app_name, os_name, RuntimeIdentifier, RuntimeIdentifier, extraArgs: extraArgs, stagingPath: stagingTarget);
}

public override void Build()
Expand Down
2 changes: 1 addition & 1 deletion Builders/WindowsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override Uploader CreateUploader()
if (!string.IsNullOrEmpty(Program.WindowsCodeSigningCertPath))
extraArgs += $" --signParams=\"/td sha256 /fd sha256 /f {Program.WindowsCodeSigningCertPath} /p {codeSigningPassword} /tr http://timestamp.comodoca.com\"";

return new VelopackUploader(app_name, os_name, RuntimeIdentifier, channel, extraArgs: extraArgs);
return new WindowsVelopackUploader(app_name, os_name, RuntimeIdentifier, channel, extraArgs: extraArgs);
}

public override void Build()
Expand Down
9 changes: 6 additions & 3 deletions GitHubObject.cs → GitHubAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@

namespace osu.Desktop.Deploy
{
public class GitHubObject
public class GitHubAsset
{
[JsonProperty(@"id")]
[JsonProperty("url")]
public string Url = string.Empty;

[JsonProperty("id")]
public int Id;

[JsonProperty(@"name")]
[JsonProperty("name")]
public string Name = string.Empty;
}
}
16 changes: 10 additions & 6 deletions GitHubRelease.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using Newtonsoft.Json;

namespace osu.Desktop.Deploy
{
public class GitHubRelease
{
[JsonProperty(@"id")]
[JsonProperty("id")]
public int Id;

[JsonProperty(@"tag_name")]
[JsonProperty("tag_name")]
public string TagName => $"{Name}";

[JsonProperty(@"name")]
[JsonProperty("name")]
public string Name = string.Empty;

[JsonProperty(@"draft")]
[JsonProperty("draft")]
public bool Draft;

[JsonProperty(@"prerelease")]
[JsonProperty("prerelease")]
public bool PreRelease;

[JsonProperty(@"upload_url")]
[JsonProperty("upload_url")]
public string UploadUrl = string.Empty;

[JsonProperty("assets")]
public GitHubAsset[] Assets = Array.Empty<GitHubAsset>();
}
}
22 changes: 22 additions & 0 deletions Uploaders/LinuxVelopackUploader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

namespace osu.Desktop.Deploy.Uploaders
{
public class LinuxVelopackUploader : VelopackUploader
{
private readonly string channel;

public LinuxVelopackUploader(string applicationName, string operatingSystemName, string runtimeIdentifier, string channel, string? extraArgs = null, string? stagingPath = null)
: base(applicationName, operatingSystemName, runtimeIdentifier, channel, extraArgs, stagingPath)
{
this.channel = channel;
}

public override void PublishBuild(string version)
{
base.PublishBuild(version);
RenameAsset($"{Program.PackageName}-{channel}.AppImage", "osu.AppImage");
}
}
}
41 changes: 41 additions & 0 deletions Uploaders/MacOSVelopackUploader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;

namespace osu.Desktop.Deploy.Uploaders
{
public class MacOSVelopackUploader : VelopackUploader
{
private readonly string channel;

public MacOSVelopackUploader(string applicationName, string operatingSystemName, string runtimeIdentifier, string channel, string? extraArgs = null, string? stagingPath = null)
: base(applicationName, operatingSystemName, runtimeIdentifier, channel, extraArgs, stagingPath)
{
this.channel = channel;
}

public override void PublishBuild(string version)
{
base.PublishBuild(version);

string suffix;

switch (channel)
{
case "osx-arm64":
suffix = "Apple.Silicon";
break;

case "osx-x64":
suffix = "Intel";
break;

default:
throw new Exception($"Unrecognised channel: {channel}");
}

RenameAsset($"{Program.PackageName}-{channel}-Portable.zip", $"osu.app.{suffix}.zip");
}
}
}
31 changes: 31 additions & 0 deletions Uploaders/VelopackUploader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using System.Net.Http;
using osu.Framework.IO.Network;

namespace osu.Desktop.Deploy.Uploaders
{
public class VelopackUploader : Uploader
Expand Down Expand Up @@ -63,5 +68,31 @@ public override void PublishBuild(string version)
useSolutionPath: false);
}
}

protected void RenameAsset(string fromName, string toName)
{
if (!Program.CanGitHub || !Program.GitHubUpload)
return;

Logger.Write($"Renaming asset '{fromName}' to '{toName}'");

GitHubRelease targetRelease = Program.GetLastGithubRelease(true)
?? throw new Exception("Release not found.");

GitHubAsset asset = targetRelease.Assets.SingleOrDefault(a => a.Name == fromName)
?? throw new Exception($"Asset '{fromName}' not found in the release.");

var req = new WebRequest(asset.Url)
{
Method = HttpMethod.Patch,
};

req.AddRaw(
$$"""
{ "name": "{{toName}}" }
""");

req.AuthenticatedBlockingPerform();
}
}
}
22 changes: 22 additions & 0 deletions Uploaders/WindowsVelopackUploader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

namespace osu.Desktop.Deploy.Uploaders
{
public class WindowsVelopackUploader : VelopackUploader
{
private readonly string channel;

public WindowsVelopackUploader(string applicationName, string operatingSystemName, string runtimeIdentifier, string channel, string? extraArgs = null, string? stagingPath = null)
: base(applicationName, operatingSystemName, runtimeIdentifier, channel, extraArgs, stagingPath)
{
this.channel = channel;
}

public override void PublishBuild(string version)
{
base.PublishBuild(version);
RenameAsset($"{Program.PackageName}-{channel}-Setup.exe", "install.exe");
}
}
}

0 comments on commit 2076306

Please sign in to comment.