From 9325c729e98810b15217c03392dfe3443cd0e7cc Mon Sep 17 00:00:00 2001 From: Matthew John Cheetham Date: Wed, 30 Oct 2019 12:40:06 +0000 Subject: [PATCH] Replace smart-download of GCM Core with dumb-download We get rate limited querying the GitHub API for the release assets to download GCM Core for Mac. Replace this with a simple hardcoding of the GCM Core macOS installer package URL. --- .../Scalar.Distribution.Mac.csproj | 15 +- Scalar.MSBuild/GetGitHubReleaseAssets.cs | 159 ------------------ Scalar.MSBuild/Scalar.targets | 28 --- 3 files changed, 10 insertions(+), 192 deletions(-) delete mode 100644 Scalar.MSBuild/GetGitHubReleaseAssets.cs diff --git a/Scalar.Distribution.Mac/Scalar.Distribution.Mac.csproj b/Scalar.Distribution.Mac/Scalar.Distribution.Mac.csproj index 95b32991..894dfc0d 100644 --- a/Scalar.Distribution.Mac/Scalar.Distribution.Mac.csproj +++ b/Scalar.Distribution.Mac/Scalar.Distribution.Mac.csproj @@ -3,30 +3,35 @@ netcoreapp3.0 $(ProjectOutPath)dist\$(Configuration)\ + v2.0.79-beta + gcmcore-osx-2.0.79.64449.pkg - + + + + - - + %(ScalarPackage.Filename)%(ScalarPackage.Extension) %(GitPackage.Filename)%(GitPackage.Extension) - %(GcmCorePackage.Filename)%(GcmCorePackage.Extension) - (); - - ReleaseInfo releaseInfo; - - try - { - this.Log.LogMessage(MessageImportance.Normal, $"Getting release information for '{this.Repository}' (tag: '{this.Version}')"); - releaseInfo = GetReleaseInfo(this.Repository, this.Version); - } - catch (Exception ex) - { - var errorMessage = new StringBuilder(); - errorMessage.AppendLine($"Failed to retrieve release information for '{this.Repository}' (tag: {this.Version}):"); - errorMessage.AppendLine(ex.ToString()); - - if (ex is WebException wex) - { - using (var rs = wex.Response.GetResponseStream()) - { - if (rs != null) - { - using (var reader = new StreamReader(rs)) - { - errorMessage.AppendLine("Response:"); - errorMessage.Append(reader.ReadToEnd()); - } - } - } - } - - this.Log.LogError(errorMessage.ToString()); - return false; - } - - this.Log.LogMessage(MessageImportance.Low, $"Release contains {releaseInfo.Assets.Length} assets:"); - - if (!string.IsNullOrWhiteSpace(this.Filter)) - { - this.Log.LogMessage(MessageImportance.Low, $"(Filtering assets with pattern: '{this.Filter}')"); - } - - foreach (AssetInfo asset in releaseInfo.Assets) - { - if (!string.IsNullOrWhiteSpace(this.Filter) && !Regex.IsMatch(asset.Name, this.Filter)) - { - this.Log.LogMessage(MessageImportance.Low, $" [skipped] {asset.Name} ({asset.Size} bytes)"); - } - else - { - this.Log.LogMessage(MessageImportance.Low, $" [include] {asset.Name} ({asset.Size} bytes)"); - - var item = new TaskItem(asset.Name, new Dictionary - { - ["Repository"] = this.Repository, - ["Version"] = this.Version, - ["Size"] = asset.Size.ToString(), - ["Url"] = asset.DownloadUrl - }); - - assetItems.Add(item); - } - } - - this.Assets = assetItems.ToArray(); - return true; - } - - private ReleaseInfo GetReleaseInfo(string repository, string version) - { - var client = new WebClient - { - Headers = new WebHeaderCollection - { - {HttpRequestHeader.UserAgent, "MSBuild"}, - {HttpRequestHeader.Accept, "application/json"} - } - }; - - Uri releaseTagUri = CreateApiUri($"repos/{repository}/releases/tags/{version}"); - - this.Log.LogMessage(MessageImportance.Low, $"GET {releaseTagUri}"); - string releaseJson = client.DownloadString(releaseTagUri); - - this.Log.LogMessage(MessageImportance.Low, $"Response: {releaseJson}"); - return Deserialize(releaseJson); - } - - private static Uri CreateApiUri(string uriStem) - { - return new Uri(new Uri(GitHubApiBase), uriStem); - } - - private static T Deserialize(string json) - { - var serializer = new DataContractJsonSerializer(typeof(T), new DataContractJsonSerializerSettings - { - DateTimeFormat = new DateTimeFormat("yyyy-MM-dd'T'HH:mm:ssZ") - }); - - byte[] bytes = Encoding.UTF8.GetBytes(json); - using (var ms = new MemoryStream(bytes)) - { - return (T)serializer.ReadObject(ms); - } - } - -#pragma warning disable CS0649 - [DataContract] - private class ReleaseInfo - { - [DataMember(Name = "assets")] - public AssetInfo[] Assets; - } - - [DataContract] - private class AssetInfo - { - [DataMember(Name = "name")] - public string Name; - - [DataMember(Name = "browser_download_url")] - public string DownloadUrl; - - [DataMember(Name = "size")] - public int Size; - } -#pragma warning restore CS0649 - } -} diff --git a/Scalar.MSBuild/Scalar.targets b/Scalar.MSBuild/Scalar.targets index 4667afc2..17c18d85 100644 --- a/Scalar.MSBuild/Scalar.targets +++ b/Scalar.MSBuild/Scalar.targets @@ -20,32 +20,4 @@ - - - - $(HOME)\.githubassets\ - $(USERPROFILE)\.githubassets\ - - - - - - - - - - - - - - - -