Exemple #1
0
        public static async Task UploadGithubRelease(All.Version packages)
        {
#if !LOCAL
            if (!(GitNet.Push(force: false) && GitNet.Push(force: true, tags: true)))
            {
                return;
            }

            var result = await GetOrCreateRelease();

            var client = Globals.Tmp.File("client.jar");
            await UploadRelease(client, $"client_{packages.Id}.jar");

            var server = Globals.Tmp.File("server.jar");
            if (server.Exists)
            {
                await UploadRelease(server, $"server_{packages.Id}.jar");
            }

            await CreateZip("assets");
            await CreateZip("data");

            var updateRelease = result.ToUpdate();
            updateRelease.Draft      = false;
            updateRelease.Prerelease = !(packages.Type is VersionType.Release);
            await Github.Repository.Release.Edit("FaustVX", "MinecraftVanillaDatapack", result.Id, updateRelease);


            async Task CreateZip(string folderName)
            {
                var git1   = ((DirectoryInfo)Globals.Git);
                var folder = git1.Then(folderName);
                var buffer = new byte[8 * 1024];

                if (folder.Exists)
                {
                    var zipFile = Globals.Tmp.File($"{folderName}_{packages.Id}.zip");
                    using (var zip = new ZipOutputStream(zipFile.OpenWrite()))
                    {
                        if (git1.File("pack.png") is FileInfo {
                            Exists : true, Name : var namePng
                        } packPng)
                        {
                            PutEntry(packPng, namePng);
                        }

                        foreach (var file in folder.EnumerateFiles("*", SearchOption.AllDirectories))
                        {
                            PutEntry(file, file.MakeRelativeTo(Globals.Git)[2..]);
Exemple #2
0
        private static async Task Main()
        {
#if DEBUG
            Debugger.Break();
#endif
            Environment.CurrentDirectory = ((DirectoryInfo)Globals.Git).FullName;
            System.Console.WriteLine(Environment.CurrentDirectory);
            (GitNet.Clone(Options.GitRepo.ToString(), checkout: false, localDirectory: ".") || GitNet.Reset(GitNet.Ref.HEAD))
            .ThrowIfNonZero(new Exception());

            ((DirectoryInfo)Globals.Git).Then(".git", "info").File("exclude").AppendAllText("*.nbt" + Environment.NewLine);

            if (Options.OnlyTags)
            {
                var  lastMessage = GitNet.GetLastCommit()?.message;
                bool?is1_8       = null;
                foreach (var(version, indexFromHead) in (await MinecraftHelper.GetVersionsInfoAsync(reverse: false))
                         .WithIndex()
                         .SkipWhile(v => v.item.Id != lastMessage)
                         .If(Options.LongRun && !Options.Debug, versions => versions.DoEvery(10, after: _ => GitNet.Push(tags: true, force: true))))
                {
                    var packages = await version.Version;
#if DEBUG
                    var versionType = packages.Type switch
                    {
                        VersionType.Alpha => "α",
                        VersionType.Beta => "β",
                        _ => ""
                    };
                    System.Console.WriteLine($"{versionType}[{packages.Type} - {packages.Assets}] {version.Id}");
#endif
                    if (packages.Assets == "1.8")
                    {
                        is1_8 = true;
                    }
                    else if (is1_8 is true && packages.Assets != "1.9")
                    {
                        break;
                    }

                    GitNet.Tag($"Version_{packages.Assets}", @ref: ^ indexFromHead, force: false);
                    if (packages.Type is VersionType.Release)
                    {
                        GitNet.Tag($"Release_{packages.Id}", @ref: ^ indexFromHead, force: false);
                    }
                }
                GitNet.Push(tags: true, force: true);
                return;
            }
#if DEBUG
            GitNet.Reset(^ 1, GitNet.ResetMode.Mixed);
#endif
            var lastCommit = LastCommitMessage();
            var java       = FaustVX.Process.Process.CreateProcess("java");
            foreach (var version in (await MinecraftHelper.GetVersionsInfoAsync(reverse: true))
                     .SkipWhile(v => v.Id != lastCommit)
                     .Skip(1)
                     .Where(version => Regex.IsMatch(version.Id, @"^(\d\.\d+(?:\.\d+)?(?:[- ](?:pre(?:-release )?|rc)\d+)?|\d{2}w\d{2}\w)$", RegexOptions.IgnoreCase)))
            {
                var startTime = Stopwatch.GetTimestamp();
                Console.WriteLine($"Next version: {version.Id}");
                Console.Title = $"{lastCommit} => {version.Id}";
                lastCommit    = version.Id;

                DeleteFiles();

                var packages = await version.Version;

                var generated = ((DirectoryInfo)Globals.Git).CreateSubdirectory("generated");

                var server = Globals.Tmp.File("server.jar");
                await Task.WhenAll(packages.Server !.JAR.DownloadFileAsync(server), packages.Client.JAR.DownloadFileAsync(Globals.Tmp), Task.Run(async() =>
                {
                    if (packages.Client.TXT is Uri txtClient)
                    {
                        generated.File("clientMapping.txt").WriteAllText(await txtClient.GetStringAsync());
                    }

                    if (packages.Server?.TXT is Uri txtServer)
                    {
                        generated.File("serverMapping.txt").WriteAllText(await txtServer.GetStringAsync());
                    }
                }), Task.Run(async() =>
                {
                    using var jarStream = await packages.Client.JAR.GetStreamAsync();
                    UnzipFromStream(jarStream, "assets data pack. version.json".Split(' '));
                }));

                GitNet.Add(all: true);

                System.Console.WriteLine("Create 'generated' files");
                java($"-cp {server.MakeRelativeTo(Globals.Git)} net.minecraft.data.Main --dev --reports --input {((DirectoryInfo)Globals.Git).MakeRelativeTo(Globals.Git)}")
                .StartAndWaitForExit();

                var reports = generated.Then("reports");

                ExtractItems(reports.File("items.json"));
                ExtractRegisties(reports.File("registries.json"));
                ExtractBlocks(reports.File("blocks.json"));
                ExtractRecipes(reports.File("recipes.json"), ((DirectoryInfo)Globals.Git).Then("data", "minecraft", "tags", "items"), ((DirectoryInfo)Globals.Git).Then("data", "minecraft", "recipes"));
                ExtractLootTables((DirectoryInfo)Globals.Git, generated, "data", "minecraft", "loot_tables");
                AddPackMcmeta(JObject.Parse(File.ReadAllText(Path.Combine("assets", "minecraft", "lang", "en_us.json"))), JObject.Parse(File.ReadAllText("version.json")));
                generated.File(version.Id + ".json").WriteAllText((await version.Json.Value).ToString(Formatting.Indented));

                using (var serverDir = new FaustVX.Temp.TemporaryDirectory(generated.Then("server"), true))
                {
                    java($"-jar {server.MakeRelativeTo(serverDir)} --nogui").StartAndWaitForExit();
                    GitNet.Add("*.properties");
                }

                GitNet.Add(reports.MakeRelativeTo(Globals.Git));
                GitNet.Add(generated.Then("assets").MakeRelativeTo(Globals.Git));
                GitNet.Add(generated.Then("data").MakeRelativeTo(Globals.Git));
                GitNet.Add("*.mcmeta");
                GitNet.Add(generated.File("*.json").MakeRelativeTo(Globals.Git));
                GitNet.Commit(version.Id, allowEmpty: true, date: version.ReleaseTime);

                GitNet.Tag($"Version_{packages.Assets}", force: true);
                if (version.Type is VersionType.Release)
                {
                    GitNet.Tag($"Release_{packages.Id}", force: true);
                }

                await Globals.UploadGithubRelease(packages);

                Console.WriteLine(TimeSpan.FromTicks(Stopwatch.GetTimestamp() - startTime));
#if DEBUG
                return;
#endif
            }

            DeleteFiles();

#if !DEBUG
            if (GitNet.Push(force: false))
            {
                GitNet.Push(force: true, tags: true);
            }