Пример #1
0
        private static GitHubRelease getLastGithubRelease(bool includeDrafts = false)
        {
            var req = new JsonWebRequest <List <GitHubRelease> >($"{GitHubApiEndpoint}");

            req.AuthenticatedBlockingPerform();
            return(req.ResponseObject.FirstOrDefault(r => includeDrafts || !r.Draft));
        }
Пример #2
0
        private static GitHubRelease getLastGithubRelease()
        {
            var req = new JsonWebRequest <List <GitHubRelease> >($"{GitHubApiEndpoint}");

            req.AuthenticatedBlockingPerform();
            return(req.ResponseObject.FirstOrDefault());
        }
Пример #3
0
        private static List <GitHubPullRequest> GetPullRequests()
        {
            // Gets the last release
            var previousVersion = GetLastGithubRelease();
            var reqMinified     = new JsonWebRequest <List <GitHubMinifiedPullRequest> >($"{GitHubApiEndpoint}pulls?state=closed");

            reqMinified.AuthenticatedBlockingPerform();

            List <GitHubMinifiedPullRequest> minifiedPullRequests = reqMinified.ResponseObject;
            List <GitHubPullRequest>         requests             = new List <GitHubPullRequest>();

            foreach (var pr in minifiedPullRequests)
            {
                // We want to ignore all previous pr's from the last release
                if (pr.MergedAt < previousVersion.PublishedAt)
                {
                    continue;
                }

                var req = new JsonWebRequest <GitHubPullRequest>($"{GitHubApiEndpoint}pulls/{pr.Number}");
                req.AuthenticatedBlockingPerform();

                requests.Add(req.ResponseObject);
            }

            pullRequests = requests;
            return(requests);
        }
Пример #4
0
        /// <summary>
        /// Download assets from a previous release into the releases folder.
        /// </summary>
        /// <param name="release"></param>
        private static void getAssetsFromRelease(GitHubRelease release)
        {
            if (!canGitHub)
            {
                return;
            }

            //there's a previous release for this project.
            var assetReq = new JsonWebRequest <List <GitHubObject> >($"{GitHubApiEndpoint}/{release.Id}/assets");

            assetReq.AuthenticatedBlockingPerform();
            var assets = assetReq.ResponseObject;

            //make sure our RELEASES file is the same as the last build on the server.
            var releaseAsset = assets.FirstOrDefault(a => a.Name == "RELEASES");

            //if we don't have a RELEASES asset then the previous release likely wasn't a Squirrel one.
            if (releaseAsset == null)
            {
                return;
            }

            bool requireDownload = false;

            if (!File.Exists(Path.Combine(releases_folder, $"{PackageName}-{release.Name}-full.nupkg")))
            {
                write("Last version's package not found locally.", ConsoleColor.Red);
                requireDownload = true;
            }
            else
            {
                var lastReleases = new RawFileWebRequest($"{GitHubApiEndpoint}/assets/{releaseAsset.Id}");
                lastReleases.AuthenticatedBlockingPerform();
                if (File.ReadAllText(Path.Combine(releases_folder, "RELEASES")) != lastReleases.ResponseString)
                {
                    write("Server's RELEASES differed from ours.", ConsoleColor.Red);
                    requireDownload = true;
                }
            }

            if (!requireDownload)
            {
                return;
            }

            write("Refreshing local releases directory...");
            refreshDirectory(releases_folder);

            foreach (var a in assets)
            {
                if (a.Name.EndsWith(".exe") || a.Name.EndsWith(".app.zip"))
                {
                    continue;
                }

                write($"- Downloading {a.Name}...", ConsoleColor.Yellow);
                new FileWebRequest(Path.Combine(releases_folder, a.Name), $"{GitHubApiEndpoint}/assets/{a.Id}").AuthenticatedBlockingPerform();
            }
        }
Пример #5
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();
        }
Пример #6
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();
        }
Пример #7
0
        private static void checkGitHubReleases()
        {
            if (!canGitHub)
            {
                return;
            }

            write("Checking GitHub releases...");
            var req = new JsonWebRequest <List <GitHubRelease> >($"{GitHubApiEndpoint}");

            req.AuthenticatedBlockingPerform();

            var lastRelease = req.ResponseObject.FirstOrDefault();

            if (lastRelease == null)
            {
                return;
            }

            if (lastRelease.Draft)
            {
                openGitHubReleasePage();
                error("There's a pending draft release! You probably don't want to push a build with this present.");
            }

            //there's a previous release for this project.
            var assetReq = new JsonWebRequest <List <GitHubObject> >($"{GitHubApiEndpoint}/{lastRelease.Id}/assets");

            assetReq.AuthenticatedBlockingPerform();
            var assets = assetReq.ResponseObject;

            //make sure our RELEASES file is the same as the last build on the server.
            var releaseAsset = assets.FirstOrDefault(a => a.Name == "RELEASES");

            //if we don't have a RELEASES asset then the previous release likely wasn't a Squirrel one.
            if (releaseAsset == null)
            {
                return;
            }

            write($"Last GitHub release was {lastRelease.Name}.");

            bool requireDownload = false;

            if (!File.Exists(Path.Combine(ReleasesFolder, nupkgDistroFilename(lastRelease.Name))))
            {
                write("Last version's package not found locally.", ConsoleColor.Red);
                requireDownload = true;
            }
            else
            {
                var lastReleases = new RawFileWebRequest($"{GitHubApiEndpoint}/assets/{releaseAsset.Id}");
                lastReleases.AuthenticatedBlockingPerform();
                if (File.ReadAllText(Path.Combine(ReleasesFolder, "RELEASES")) != lastReleases.ResponseString)
                {
                    write("Server's RELEASES differed from ours.", ConsoleColor.Red);
                    requireDownload = true;
                }
            }

            if (!requireDownload)
            {
                return;
            }

            write("Refreshing local releases directory...");
            refreshDirectory(ReleasesFolder);

            foreach (var a in assets)
            {
                if (a.Name.EndsWith(".exe"))
                {
                    continue;
                }

                write($"- Downloading {a.Name}...", ConsoleColor.Yellow);
                new FileWebRequest(Path.Combine(ReleasesFolder, a.Name), $"{GitHubApiEndpoint}/assets/{a.Id}").AuthenticatedBlockingPerform();
            }
        }
Пример #8
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();
        }