Skip to content

Commit

Permalink
Merge 2362f04 into de80328
Browse files Browse the repository at this point in the history
  • Loading branch information
retailcoder authored Jun 16, 2023
2 parents de80328 + 2362f04 commit 3fdf44a
Show file tree
Hide file tree
Showing 5 changed files with 676 additions and 29 deletions.
1 change: 1 addition & 0 deletions Rubberduck.Core/Rubberduck.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<PackageReference Include="NLog.Schema">
<Version>4.5.10</Version>
</PackageReference>
<PackageReference Include="Octokit" Version="6.0.0" />
<PackageReference Include="System.IO.Abstractions" Version="12.2.1" />
<PackageReference Include="System.ValueTuple">
<Version>4.5.0</Version>
Expand Down
42 changes: 17 additions & 25 deletions Rubberduck.Core/VersionCheck/VersionCheckService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
using Rubberduck.Settings;
using System;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Octokit;
using System.Net;

namespace Rubberduck.VersionCheck
{
Expand All @@ -29,6 +30,8 @@ public async Task<Version> GetLatestVersionAsync(GeneralSettings settings, Cance

try
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

return settings.IncludePreRelease
? await GetGitHubNext()
: await GetGitHubMain();
Expand All @@ -43,38 +46,27 @@ public async Task<Version> GetLatestVersionAsync(GeneralSettings settings, Cance
public bool IsDebugBuild { get; }
public string VersionString { get; }

private const string GitHubOrgName = "rubberduck-vba";
private const string GitHubRepoName = "Rubberduck";
private const string UserAgentProductName = "Rubberduck";
private GitHubClient GetGitHubClient() => new GitHubClient(new ProductHeaderValue(UserAgentProductName, CurrentVersion.ToString(3)));

private async Task<Version> GetGitHubMain()
{
var url = new Uri("https://github.com/repos/rubberduck-vba/Rubberduck/releases/latest");
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("rubberduck.version-check"));
using (var response = await client.GetAsync(url))
{
var content = await response.Content.ReadAsStringAsync();
var tagName = (string)JsonConvert.DeserializeObject<dynamic>(content).tag_name;
var client = GetGitHubClient();
var response = await client.Repository.Release.GetLatest(GitHubOrgName, GitHubRepoName);
var tagName = response.TagName;

// assumes a tag name like "v2.5.3.0"
return new Version(tagName.Substring("v".Length));
}
}
return new Version(tagName.Substring("v".Length));
}

private async Task<Version> GetGitHubNext()
{
var url = new Uri("https://github.com/repos/rubberduck-vba/Rubberduck/releases");
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("rubberduck.version-check"));
using (var response = await client.GetAsync(url))
{
var content = await response.Content.ReadAsStringAsync();
var tagName = (string)JsonConvert.DeserializeObject<dynamic>(content)[0].tag_name;
var client = GetGitHubClient();
var response = await client.Repository.Release.GetAll(GitHubOrgName, GitHubRepoName);
var tagName = response.FirstOrDefault()?.TagName ?? "Prerelease-v0.0.0";

// assumes a tag name like "Prerelease-v2.5.2.1234"
return new Version(tagName.Substring("Prerelease-v".Length));
}
}
return new Version(tagName.Substring("Prerelease-v".Length));
}
}
}
2 changes: 1 addition & 1 deletion RubberduckBaseProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<!-- Ignore VisualStudio whining about the CodeAnalysis assembly changing (IDE1001) -->
<DisabledWarnings>$(DisabledWarnings);4011;1001;1591</DisabledWarnings>
<!-- Declare a Version if it's not already declared as a global property through MSBuild invocation -->
<Version Condition=" '$(Version)' == '' ">2.5.2</Version>
<Version Condition=" '$(Version)' == '' ">2.5.9</Version>
<!-- all other relevant version numbers are computed from Version automagically -->
</PropertyGroup>

Expand Down
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: '2.5.2.{build}'
version: '2.5.9.{build}'

# enforce crlf fixing
init:
git config --global core.autocrlf true
- git config --global core.autocrlf true

# history limited to 15 commits, since we ran into trouble with a limit of 3
# the limit can be rather generous
Expand Down Expand Up @@ -36,7 +36,7 @@ cache:
- '%USERPROFILE%/.gradle/wrapper/dists'

install:
set PATH=C:\Program Files (x86)\MSBuild\15.0\Bin;C:\Program Files (x86)\Java\jdk1.8.0;%PATH%
- set PATH=C:\Program Files (x86)\MSBuild\15.0\Bin;C:\Program Files (x86)\Java\jdk1.8.0;%PATH%

# set up the environment variables used later in the build process
environment:
Expand Down
Loading

0 comments on commit 3fdf44a

Please sign in to comment.