mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: commit
This commit is contained in:
1 parent
57a2daa5e4
commit
8c7f851692
5 files changed
+184
-6
No files matched your search
@@ -32,7 +32,9 @@ export async function commitMultipleFiles(
|
|||||||
|
|
||||||
// we discard blob if they're the same size; it's unlikely their
|
// we discard blob if they're the same size; it's unlikely their
|
||||||
// contents will be different; I love playing russian roulette!
|
// contents will be different; I love playing russian roulette!
|
||||||
const equal = buffer.length === change.content.length || buffer.equals(change.content);
|
const equal =
|
||||||
|
buffer.length === change.content.length ||
|
||||||
|
buffer.equals(change.content);
|
||||||
if (!equal) {
|
if (!equal) {
|
||||||
const diff = change.content.length - buffer.length;
|
const diff = change.content.length - buffer.length;
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DotNet.Glob" Version="3.1.3" />
|
<PackageReference Include="DotNet.Glob" Version="3.1.3" />
|
||||||
|
<PackageReference Include="DotNetEnv" Version="3.1.1" />
|
||||||
<PackageReference Include="Google.Protobuf" Version="3.29.3" />
|
<PackageReference Include="Google.Protobuf" Version="3.29.3" />
|
||||||
|
<PackageReference Include="Octokit" Version="14.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -5,6 +5,7 @@ using CUE4Parse.UE4.Assets.Exports;
|
|||||||
using CUE4Parse.UE4.Assets.Exports.Engine;
|
using CUE4Parse.UE4.Assets.Exports.Engine;
|
||||||
using CUE4Parse.UE4.Assets.Exports.StaticMesh;
|
using CUE4Parse.UE4.Assets.Exports.StaticMesh;
|
||||||
using CUE4Parse.UE4.Assets.Objects;
|
using CUE4Parse.UE4.Assets.Objects;
|
||||||
|
using CUE4Parse.UE4.Objects.UObject;
|
||||||
using Google.Protobuf.Collections;
|
using Google.Protobuf.Collections;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
@@ -14,8 +15,9 @@ namespace BlitzKit.CLI.Functions
|
|||||||
{
|
{
|
||||||
readonly Tanks tanks = new();
|
readonly Tanks tanks = new();
|
||||||
readonly BlitzProvider provider = new();
|
readonly BlitzProvider provider = new();
|
||||||
|
readonly List<FileChange> changes = [];
|
||||||
|
|
||||||
public void Mangle()
|
public async Task Mangle()
|
||||||
{
|
{
|
||||||
var nationDirs = provider.RootDirectory.GetDirectory("Blitz/Content/Tanks").Directories;
|
var nationDirs = provider.RootDirectory.GetDirectory("Blitz/Content/Tanks").Directories;
|
||||||
|
|
||||||
@@ -26,6 +28,8 @@ namespace BlitzKit.CLI.Functions
|
|||||||
|
|
||||||
MangleNation(nationDir.Value);
|
MangleNation(nationDir.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await BlitzKitAssets.CommitAssets("ue assets", changes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MangleNation(VFS nation)
|
void MangleNation(VFS nation)
|
||||||
@@ -48,6 +52,9 @@ namespace BlitzKit.CLI.Functions
|
|||||||
{
|
{
|
||||||
var pdaName = $"PDA_{tankDir.Name}";
|
var pdaName = $"PDA_{tankDir.Name}";
|
||||||
var pda = provider.LoadObject($"{tankDir.Path}/{pdaName}.{pdaName}");
|
var pda = provider.LoadObject($"{tankDir.Path}/{pdaName}.{pdaName}");
|
||||||
|
|
||||||
|
var tankId = PropertyUtil.Get<FName>(pda, "TankId").Text;
|
||||||
|
|
||||||
var hulls = PropertyUtil.Get<UDataTable>(pda, "DT_Hulls");
|
var hulls = PropertyUtil.Get<UDataTable>(pda, "DT_Hulls");
|
||||||
UDataTableUtility.TryGetDataTableRow(hulls, "hull", StringComparison.Ordinal, out var hull);
|
UDataTableUtility.TryGetDataTableRow(hulls, "hull", StringComparison.Ordinal, out var hull);
|
||||||
var hullVisualData = PropertyUtil.Get<UObject>(hull, "VisualData");
|
var hullVisualData = PropertyUtil.Get<UObject>(hull, "VisualData");
|
||||||
@@ -55,9 +62,9 @@ namespace BlitzKit.CLI.Functions
|
|||||||
var hullCollision = PropertyUtil.Get<UStaticMesh>(hullMeshSettings, "CollisionMesh");
|
var hullCollision = PropertyUtil.Get<UStaticMesh>(hullMeshSettings, "CollisionMesh");
|
||||||
MonoGltf hullCollisionGltf = new(hullCollision);
|
MonoGltf hullCollisionGltf = new(hullCollision);
|
||||||
|
|
||||||
hullCollisionGltf.Write();
|
changes.Add(new($"tanks/{tankId}/collision/hull.glb", hullCollisionGltf.Write()));
|
||||||
|
|
||||||
return new() { Id = "" };
|
return new() { Id = tankId };
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<string, CrewType> CrewTypes = new()
|
Dictionary<string, CrewType> CrewTypes = new()
|
||||||
|
|||||||
@@ -0,0 +1,162 @@
|
|||||||
|
using System.Net;
|
||||||
|
using BlitzKit.CLI.Utils;
|
||||||
|
using DotNetEnv;
|
||||||
|
using Octokit;
|
||||||
|
|
||||||
|
namespace BlitzKit.CLI.Models
|
||||||
|
{
|
||||||
|
public static class BlitzKitAssets
|
||||||
|
{
|
||||||
|
public static int TIME_PER_BLOB = (int)Math.Pow(2, 4) * 10000;
|
||||||
|
public static int TIME_BETWEEN_BLOBS = (int)(60 * 60 * 1000 / 5000 / 0.9);
|
||||||
|
|
||||||
|
public static async Task CommitAssets(string message, List<FileChange> changes)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Committing \"{message}\"... with {changes.Count} proposed changes");
|
||||||
|
|
||||||
|
if (changes.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
await CommitMultipleFiles(
|
||||||
|
Env.GetString("PUBLIC_ASSET_REPO"),
|
||||||
|
Env.GetString("PUBLIC_ASSET_BRANCH"),
|
||||||
|
message,
|
||||||
|
changes
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task CommitMultipleFiles(
|
||||||
|
string repoRaw,
|
||||||
|
string branch,
|
||||||
|
string message,
|
||||||
|
List<FileChange> changesRaw
|
||||||
|
)
|
||||||
|
{
|
||||||
|
using HttpClient httpClient = new();
|
||||||
|
|
||||||
|
GitHubClient octokit = new(new ProductHeaderValue("MyAmazingApp"))
|
||||||
|
{
|
||||||
|
Credentials = new(Env.GetString("GH_TOKEN")),
|
||||||
|
};
|
||||||
|
List<FileChange> changes = [];
|
||||||
|
|
||||||
|
await Task.WhenAll(
|
||||||
|
changesRaw
|
||||||
|
.Select(async change =>
|
||||||
|
{
|
||||||
|
var blobPath = $"{repoRaw}/{branch}/{change.Path}";
|
||||||
|
|
||||||
|
HttpResponseMessage response = await httpClient.GetAsync(
|
||||||
|
$"https://raw.githubusercontent.com/{blobPath}"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||||
|
{
|
||||||
|
Console.WriteLine(
|
||||||
|
$"🟢 (+{change.Content.Count.ToString("N0", Program.Culture)}B) {blobPath}"
|
||||||
|
);
|
||||||
|
changes.Add(change);
|
||||||
|
}
|
||||||
|
else if (response.StatusCode == HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
var bytes = await response.Content.ReadAsByteArrayAsync();
|
||||||
|
|
||||||
|
// we discard blob if they're the same size; it's unlikely their
|
||||||
|
// contents will be different; I love playing russian roulette!
|
||||||
|
var equal =
|
||||||
|
bytes.Length == change.Content.Count || bytes.SequenceEqual([.. change.Content]);
|
||||||
|
if (!equal)
|
||||||
|
{
|
||||||
|
var diff = change.Content.Count - bytes.Length;
|
||||||
|
|
||||||
|
Console.WriteLine(
|
||||||
|
$"🟡 ({(diff > 0 ? '+' : "")}{diff.ToString("N0", Program.Culture)}B) {blobPath}"
|
||||||
|
);
|
||||||
|
|
||||||
|
changes.Add(change);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"Unexpected status code {response.StatusCode} for {blobPath}");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ToList()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (changes.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var repoRawSplit = repoRaw.Split('/');
|
||||||
|
var owner = repoRawSplit[0];
|
||||||
|
var repo = repoRawSplit[1];
|
||||||
|
var latestCommitSha = (await octokit.Git.Reference.Get(owner, repo, $"heads/{branch}"))
|
||||||
|
.Object
|
||||||
|
.Sha;
|
||||||
|
var treeSha = (await octokit.Git.Commit.Get(owner, repo, latestCommitSha)).Tree.Sha;
|
||||||
|
NewTree newTree = new() { BaseTree = treeSha };
|
||||||
|
|
||||||
|
foreach (var change in changes)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var blobSha = octokit
|
||||||
|
.Git.Blob.Create(
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Encoding = EncodingType.Base64,
|
||||||
|
Content = Convert.ToBase64String(change.Content),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.Result.Sha;
|
||||||
|
|
||||||
|
await Task.Delay(TIME_BETWEEN_BLOBS);
|
||||||
|
|
||||||
|
newTree.Tree.Add(
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Sha = blobSha,
|
||||||
|
Path = change.Path,
|
||||||
|
Mode = "100644",
|
||||||
|
Type = TreeType.Blob,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
PrettyLog.Warn($"Failed blob {change.Path}; retrying in {TIME_PER_BLOB}ms...");
|
||||||
|
await Task.Delay(TIME_PER_BLOB);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var treeData = await octokit.Git.Tree.Create(owner, repo, newTree);
|
||||||
|
var newCommit = await octokit.Git.Commit.Create(
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
new(message, treeData.Sha, latestCommitSha)
|
||||||
|
);
|
||||||
|
await octokit.Git.Reference.Update(owner, repo, $"heads/{branch}", new(newCommit.Sha, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GithubChangeBlob
|
||||||
|
{
|
||||||
|
public required string Sha;
|
||||||
|
public required string Path;
|
||||||
|
public required string Mode;
|
||||||
|
public required string Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FileChange(string path, ArraySegment<byte> content)
|
||||||
|
{
|
||||||
|
public string Path = path;
|
||||||
|
public ArraySegment<byte> Content = content;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,17 @@
|
|||||||
using BlitzKit.CLI.Functions;
|
using System.Globalization;
|
||||||
|
using BlitzKit.CLI.Functions;
|
||||||
using BlitzKit.CLI.Utils;
|
using BlitzKit.CLI.Utils;
|
||||||
|
using DotNetEnv;
|
||||||
|
|
||||||
namespace BlitzKit.CLI
|
namespace BlitzKit.CLI
|
||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
public static CultureInfo Culture = new("en-US");
|
||||||
|
|
||||||
static async Task Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
|
Env.Load();
|
||||||
await AgnosticHelpers.Initialize();
|
await AgnosticHelpers.Initialize();
|
||||||
|
|
||||||
switch (args[0])
|
switch (args[0])
|
||||||
@@ -21,7 +26,7 @@ namespace BlitzKit.CLI
|
|||||||
{
|
{
|
||||||
Mangler mangler = new();
|
Mangler mangler = new();
|
||||||
|
|
||||||
mangler.Mangle();
|
await mangler.Mangle();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user