示例#1
0
        public static Version GetLatestReleaseVersion()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            HttpWebRequest request = WebRequest.Create("https://api.github.com/repos/Kreyu/dayz-rich-presence/releases/latest") as HttpWebRequest;

            request.Method    = "GET";
            request.Accept    = "application/vnd.github.v3+json";
            request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36";
            request.ServicePoint.Expect100Continue = false;

            try
            {
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        ReleaseMetadata metadata = reader.ReadToEnd().FromJson <ReleaseMetadata>();
                        string          version  = Regex.Replace(metadata.TagName, "[^0-9.]", "");

                        return(new Version(version));
                    }
                }
            }
            catch
            {
                return(null);
            }
        }
        public DiagnosticsManifestGenerator(ReleaseMetadata productReleaseMetadata, FileInfo toolManifest, ILogger logger)
        {
            _productReleaseMetadata = productReleaseMetadata;
            string manifestContent = File.ReadAllText(toolManifest.FullName);

            _assetManifestManifestDom = JsonDocument.Parse(manifestContent);
            _logger = logger;
        }
示例#3
0
 private static bool TryGetExtraData(ReleaseMetadata releaseMetadata, out ReleaseMetadataExtraData?extraData)
 {
     extraData = default;
     try
     {
         extraData = releaseMetadata.GetExtraData <ReleaseMetadataExtraData>();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        internal async static Task <int> PrepareRelease(Config releaseConfig, bool verbose, CancellationToken ct)
        {
            // TODO: This will throw if invalid drop path is given.
            var darcLayoutHelper = new DarcHelpers(releaseConfig.DropPath);

            ILogger logger = GetDiagLogger(verbose);

            var layoutWorkerList = new List <ILayoutWorker>
            {
                // TODO: We may want to inject a logger.
                new NugetLayoutWorker(stagingPath: releaseConfig.StagingDirectory.FullName),
                new SymbolPackageLayoutWorker(stagingPath: releaseConfig.StagingDirectory.FullName),
                new ZipLayoutWorker(
                    shouldHandleFileFunc: DiagnosticsRepoHelpers.IsBundledToolArchive,
                    getRelativePathFromZipAndInnerFileFunc: DiagnosticsRepoHelpers.GetToolPublishRelativePath,
                    getMetadataForInnerFileFunc: DiagnosticsRepoHelpers.GetMetadataForToolFile,
                    stagingPath: releaseConfig.StagingDirectory.FullName
                    )
            };

            var verifierList = new List <IReleaseVerifier> {
            };

            if (releaseConfig.ShouldVerifyManifest)
            {
                // TODO: add verifier.
                // verifierList.Add();
            }

            // TODO: Probably should use BAR ID instead as an identifier for the metadata to gather.
            ReleaseMetadata releaseMetadata      = darcLayoutHelper.GetDropMetadataForSingleRepoVariants(DiagnosticsRepoHelpers.RepositoryUrls);
            DirectoryInfo   basePublishDirectory = darcLayoutHelper.GetShippingDirectoryForSingleProjectVariants(DiagnosticsRepoHelpers.ProductNames);
            string          publishManifestPath  = Path.Combine(releaseConfig.StagingDirectory.FullName, ManifestName);

            IPublisher         releasePublisher  = new AzureBlobBublisher(releaseConfig.AccountName, releaseConfig.AccountKey, releaseConfig.ContainerName, releaseConfig.ReleaseName, releaseConfig.SasValidDays, logger);
            IManifestGenerator manifestGenerator = new DiagnosticsManifestGenerator(releaseMetadata, releaseConfig.ToolManifest, logger);

            using var diagnosticsRelease = new Release(
                      productBuildPath: basePublishDirectory,
                      layoutWorkers: layoutWorkerList,
                      verifiers: verifierList,
                      publisher: releasePublisher,
                      manifestGenerator: manifestGenerator,
                      manifestSavePath: publishManifestPath
                      );

            diagnosticsRelease.UseLogger(logger);

            return(await diagnosticsRelease.RunAsync(ct));
        }
示例#5
0
        internal ReleaseMetadata GetDropMetadataForSingleRepoVariants(IEnumerable <string> repoUrls)
        {
            string releaseVersion;

            using (Stream darcReleaseFile = File.OpenRead(ReleaseFilePath))
                using (JsonDocument jsonDoc = JsonDocument.Parse(darcReleaseFile))
                {
                    JsonElement releaseVersionElement = jsonDoc.RootElement[0].GetProperty("release");
                    releaseVersion = releaseVersionElement.GetString();
                }

            using (Stream darcManifest = File.OpenRead(ManifestFilePath))
                using (JsonDocument jsonDoc = JsonDocument.Parse(darcManifest))
                {
                    // TODO: Schema validation.
                    JsonElement buildList = jsonDoc.RootElement.GetProperty("builds");

                    // This iteration is necessary due to the public/private nature repos.
                    var repoBuilds = buildList.EnumerateArray()
                                     .Where(build =>
                    {
                        var buildUri = new Uri(build.GetProperty("repo").GetString());
                        return(repoUrls.Any(repoUrl => buildUri == new Uri(repoUrl)));
                    });

                    if (repoBuilds.Count() != 1)
                    {
                        throw new InvalidOperationException(
                                  $"There's either no build for requested repos or more than one. Can't retrieve metadata.");
                    }

                    JsonElement build = repoBuilds.First();

                    var releaseMetadata = new ReleaseMetadata(
                        releaseVersion: releaseVersion,
                        repoUrl: build.GetProperty("repo").GetString(),
                        branch: build.GetProperty("branch").GetString(),
                        commit: build.GetProperty("commit").GetString(),
                        dateProduced: build.GetProperty("produced").GetString(),
                        buildNumber: build.GetProperty("buildNumber").GetString(),
                        barBuildId: build.GetProperty("barBuildId").GetInt32()
                        );

                    return(releaseMetadata);
                }
        }
示例#6
0
        internal ReleaseMetadata GetDropMetadata(string repoUrl)
        {
            string releaseVersion;

            using (Stream darcReleaseFile = File.OpenRead(ReleaseFilePath))
                using (JsonDocument jsonDoc = JsonDocument.Parse(darcReleaseFile))
                {
                    JsonElement releaseVersionElement = jsonDoc.RootElement[0].GetProperty("release");
                    releaseVersion = releaseVersionElement.GetString();
                }

            using (Stream darcManifest = File.OpenRead(ManifestFilePath))
                using (JsonDocument jsonDoc = JsonDocument.Parse(darcManifest))
                {
                    // TODO: Schema validation.
                    JsonElement buildList = jsonDoc.RootElement.GetProperty("builds");

                    // TODO: This should be using Uri.Compare...
                    var repoBuilds = buildList.EnumerateArray()
                                     .Where(build => build.GetProperty("repo").GetString() == repoUrl);

                    if (repoBuilds.Count() != 1)
                    {
                        throw new InvalidOperationException(
                                  $"There's either no build for {repoUrl} or more than one. Can't retrieve metadata.");
                    }

                    JsonElement build = repoBuilds.ElementAt(0);

                    // TODO: If any of these were to fail...
                    var releaseMetadata = new ReleaseMetadata(
                        releaseVersion: releaseVersion,
                        repoUrl: repoUrl,
                        branch: build.GetProperty("branch").GetString(),
                        commit: build.GetProperty("commit").GetString(),
                        dateProduced: build.GetProperty("produced").GetString(),
                        buildNumber: build.GetProperty("buildNumber").GetString(),
                        barBuildId: build.GetProperty("barBuildId").GetInt32()
                        );

                    return(releaseMetadata);
                }
        }
示例#7
0
 public ReleaseListTests()
 {
     this.data = TestHelper.Get <ReleaseMetadata>("release-search.xml", false);
 }