Exemplo n.º 1
0
        private static void AnnounceToDiscord(string version)
        {
            if (!AnnounceDiscord)
            {
                return;
            }

            var req = new JsonWebRequest <DiscordWebhook>(DiscordWebhookURL)
            {
                Method      = HttpMethod.Post,
                ContentType = "application/json"
            };

            // Get all of the previous PR's name
            var body = $"Version {version} for {GitHubRepoName} has been released! this now fixes and adds:\r\n";

            // Adds every pull requests after the last release
            pullRequests.ForEach(pr => { body += $"- {pr.Title} | {pr.User.Name}\r\n"; });

            body += $"\r\nDownload:\r\n<https://github.com/{GitHubUsername}/{GitHubRepoName}/releases>\r\n<https://www.nuget.org/packages/{GitHubRepoName}/{version}>";

            req.AddRaw(JsonConvert.SerializeObject(new DiscordWebhook
            {
                Content = body
            }));

            req.Perform();
        }
Exemplo n.º 2
0
        public void TestPostWithJsonRequest([Values(true, false)] bool async)
        {
            var request = new JsonWebRequest <HttpBinPostResponse>($"{default_protocol}://{host}/post")
            {
                Method = HttpMethod.Post,
                AllowInsecureRequests = true,
            };

            var testObject = new TestObject();

            request.AddRaw(JsonConvert.SerializeObject(testObject));

            if (async)
            {
                Assert.DoesNotThrowAsync(request.PerformAsync);
            }
            else
            {
                Assert.DoesNotThrow(request.Perform);
            }

            var responseObject = request.ResponseObject;

            Assert.IsTrue(request.Completed);
            Assert.IsFalse(request.Aborted);

            Assert.IsTrue(responseObject.Headers.ContentLength > 0);
            Assert.IsTrue(responseObject.Json != null);
            Assert.AreEqual(testObject.TestString, responseObject.Json.TestString);

            Assert.IsTrue(responseObject.Headers.ContentType == null);
        }
Exemplo n.º 3
0
        public void TestPostWithJsonRequest(bool async)
        {
            var request = new JsonWebRequest <HttpBinPostResponse>("https://httpbin.org/post")
            {
                Method = HttpMethod.POST
            };

            var testObject = new TestObject();

            request.AddRaw(JsonConvert.SerializeObject(testObject));

            if (async)
            {
                Assert.DoesNotThrowAsync(request.PerformAsync);
            }
            else
            {
                Assert.DoesNotThrow(request.Perform);
            }

            var responseObject = request.ResponseObject;

            Assert.IsTrue(request.Completed);
            Assert.IsFalse(request.Aborted);

            Assert.IsTrue(responseObject.Headers.ContentLength > 0);
            Assert.IsTrue(responseObject.Json != null);
            Assert.AreEqual(testObject.TestString, responseObject.Json.TestString);

            Assert.IsTrue(responseObject.Headers.ContentType == null);
        }
Exemplo n.º 4
0
        private static void uploadBuild(string version)
        {
            if (!canGitHub || string.IsNullOrEmpty(CodeSigningCertificate))
            {
                return;
            }

            write("Publishing to GitHub...");

            var req = new JsonWebRequest <GitHubRelease>($"{GitHubApiEndpoint}")
            {
                Method = HttpMethod.Post,
            };

            GitHubRelease targetRelease = getLastGithubRelease();

            if (targetRelease == null || targetRelease.TagName != version)
            {
                write($"- Creating release {version}...", ConsoleColor.Yellow);
                req.AddRaw(JsonConvert.SerializeObject(new GitHubRelease
                {
                    Name  = version,
                    Draft = true,
                }));
                req.AuthenticatedBlockingPerform();

                targetRelease = req.ResponseObject;
            }
            else
            {
                write($"- Adding to existing release {version}...", ConsoleColor.Yellow);
            }

            var assetUploadUrl = targetRelease.UploadUrl.Replace("{?name,label}", "?name={0}");

            foreach (var a in Directory.GetFiles(releases_folder).Reverse()) //reverse to upload RELEASES first.
            {
                if (Path.GetFileName(a).StartsWith('.'))
                {
                    continue;
                }

                write($"- Adding asset {a}...", ConsoleColor.Yellow);
                var upload = new WebRequest(assetUploadUrl, Path.GetFileName(a))
                {
                    Method      = HttpMethod.Post,
                    Timeout     = 240000,
                    ContentType = "application/octet-stream",
                };

                upload.AddRaw(File.ReadAllBytes(a));
                upload.AuthenticatedBlockingPerform();
            }

            openGitHubReleasePage();
        }
Exemplo n.º 5
0
        private static void uploadBuild(string version)
        {
            if (string.IsNullOrEmpty(GitHubAccessToken) || string.IsNullOrEmpty(codeSigningCertPath))
            {
                return;
            }

            write("Publishing to GitHub...");

            write($"- Creating release {version}...", ConsoleColor.Yellow);
            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).Reverse()) //reverse to upload RELEASES first.
            {
                write($"- Adding asset {a}...", ConsoleColor.Yellow);
                var upload = new WebRequest(assetUploadUrl, Path.GetFileName(a))
                {
                    Method      = HttpMethod.POST,
                    Timeout     = 240000,
                    ContentType = "application/octet-stream",
                };

                upload.AddRaw(File.ReadAllBytes(a));
                upload.AuthenticatedBlockingPerform();
            }

            openGitHubReleasePage();
        }
Exemplo n.º 6
0
        private static void UploadBuild(string version)
        {
            if (!CanGitHub)
            {
                return;
            }

            Write("Publishing to GitHub...");

            var req = new JsonWebRequest <GitHubRelease>($"{GitHubApiEndpoint}releases")
            {
                Method = HttpMethod.Post,
            };

            GitHubRelease targetRelease = GetLastGithubRelease();

            if (targetRelease == null || targetRelease.TagName != version)
            {
                Write($"- Creating release {version}...", ConsoleColor.Yellow);

                // Get all of the previous PR's name
                string body     = $"Version {version} for {GitHubRepoName} has been released! this now fixes and adds:\r\n";
                var    requests = GetPullRequests();

                // Adds every pull requests after the last release
                requests.ForEach(pr => { body += $"- {pr.Title} | [{pr.User.Name}]({pr.User.Link})\r\n"; });

                req.AddRaw(JsonConvert.SerializeObject(new GitHubRelease
                {
                    Name        = $"{GitHubRepoName} v{version}",
                    TagName     = version,
                    Description = body,
                    Draft       = true,
                    PublishedAt = DateTime.Now
                }));

                req.AuthenticatedBlockingPerform();

                targetRelease = req.ResponseObject;
            }
            else
            {
                Write($"- Adding to existing release {version}...", ConsoleColor.Yellow);
            }

            var assetUploadUrl = targetRelease.UploadUrl.Replace("{?name,label}", "?name={0}");

            foreach (var a in Directory.GetFiles(staging_folder).Reverse())
            {
                if (Path.GetFileName(a).StartsWith('.'))
                {
                    continue;
                }

                if (!Path.GetFileName(a).EndsWith(".nupkg"))
                {
                    continue;
                }

                var upload = new WebRequest(assetUploadUrl, Path.GetFileName(a))
                {
                    Method      = HttpMethod.Post,
                    Timeout     = 240000,
                    ContentType = "application/octet-stream",
                };

                upload.AddRaw(File.ReadAllBytes(a));
                upload.AuthenticatedBlockingPerform();
            }

            OpenGitHubReleasePage();
        }
Exemplo n.º 7
0
        private static void Main()
        {
            var currentDirectory  = new NativeStorage(".");
            var solutionDirectory = new NativeStorage("..");

            currentDirectory.DeleteDirectory("./staging");

            if (!Directory.Exists("releases"))
            {
                Directory.CreateDirectory("releases");
            }

            var stagingDirectory = currentDirectory.GetStorageForDirectory("staging");
            var currentDate      = DateTime.Now.ToString("yyyy.Mdd.");

            currentDate += currentDirectory.GetDirectories("releases").Count(s => s.Contains(currentDate));

            var releaseDirectory = currentDirectory.GetStorageForDirectory($"./releases/App-{currentDate}");

            Console.WriteLine($"Package: Qsor");
            Console.WriteLine($"Release Version: {currentDate}");
            Console.WriteLine($"Release Directory: {releaseDirectory.GetFullPath(".")}");
            Console.WriteLine($"Changelog: \n{ChangelogGenerator.GenerateChangelog()}");

            var logo = solutionDirectory.GetFullPath("Qsor.Game/Resources/Textures/Logo-256x256.png");
            var icon = solutionDirectory.GetFullPath("Qsor.Desktop/icon.ico");

            RunCommand("dotnet", $"publish -f netcoreapp3.1 Qsor.Desktop --configuration Release --runtime win-x64 -p:Version={currentDate} -o {stagingDirectory.GetFullPath(".")}",
                       solutionDirectory.GetFullPath("."));

            RunCommand("./tools/rcedit-x64.exe", $"\"{stagingDirectory.GetFullPath(".")}\\Qsor.exe\" --set-icon \"{icon}\"");

            RunCommand(NugetPath, $"pack Qsor.Desktop/qsor.nuspec -Version {currentDate} -Properties Configuration=Release -OutputDirectory {stagingDirectory.GetFullPath(".")} -BasePath {stagingDirectory.GetFullPath(".")}",
                       solutionDirectory.GetFullPath("."));

            RunCommand(SquirrelPath, $"--releasify {stagingDirectory.GetFullPath($"./Qsor.{currentDate}.nupkg")} --releaseDir {releaseDirectory.GetFullPath(".")} --no-msi --icon {icon} --setupIcon {icon} --loadingGif {logo}",
                       stagingDirectory.GetFullPath("."));

            RunCommand("git", $"tag {currentDate}");
            RunCommand("git", $"push origin {currentDate}");

            File.Move(releaseDirectory.GetFullPath("Setup.exe"), releaseDirectory.GetFullPath("install.exe"));

            stagingDirectory.DeleteDirectory(".");

            var req = new JsonWebRequest <GitHubRelease>($"https://api.github.com/repos/Mempler/Qsor/releases")
            {
                Method = HttpMethod.Post,
            };

            Console.WriteLine($"Creating release {currentDate}...");

            req.AddRaw(JsonConvert.SerializeObject(new GitHubRelease
            {
                Name  = currentDate,
                Draft = true,
                Body  = ChangelogGenerator.GenerateChangelog()
            }));

            req.AddHeader("Authorization", $"token {GithubAccessToken}");
            req.Perform();

            var targetRelease = req.ResponseObject;

            var assetUploadUrl = targetRelease.UploadUrl.Replace("{?name,label}", "?name={0}");

            foreach (var a in Directory.GetFiles(releaseDirectory.GetFullPath(".")).Reverse())
            {
                if (Path.GetFileName(a).StartsWith('.'))
                {
                    continue;
                }

                Console.WriteLine($"- Pushing asset {a}...");
                var upload = new WebRequest(assetUploadUrl, Path.GetFileName(a))
                {
                    Method      = HttpMethod.Post,
                    Timeout     = 240000,
                    ContentType = "application/octet-stream",
                };

                upload.AddRaw(File.ReadAllBytes(a));
                upload.AddHeader("Authorization", $"token {GithubAccessToken}");
                upload.Perform();
            }
        }