Skip to content

Commit

Permalink
Migrating to net6.0 (#182)
Browse files Browse the repository at this point in the history
* More

* Move to net6.0

* fix
  • Loading branch information
jaredpar committed Apr 12, 2023
1 parent 3643c61 commit 4a79e6a
Show file tree
Hide file tree
Showing 27 changed files with 64 additions and 173 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/azure-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ jobs:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v2

- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101

- name: Setup .NET Core 6.0
uses: actions/setup-dotnet@v1
with:
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ jobs:
- name: 'Checkout'
uses: actions/checkout@v2

- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101

- name: Setup .NET Core 6.0
uses: actions/setup-dotnet@v1
with:
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/nuget-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101

- name: Setup .NET Core 6.0
uses: actions/setup-dotnet@v1
Expand Down
6 changes: 3 additions & 3 deletions DevOps.Functions/DevOps.Functions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.1.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.3.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.24" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DevOps.Util.DotNet\DevOps.Util.DotNet.csproj" />
Expand Down
28 changes: 14 additions & 14 deletions DevOps.Functions/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public async Task<IActionResult> OnBuild(
string requestBody = await new StreamReader(req.Body).ReadToEndAsync().ConfigureAwait(false);
logger.LogInformation(requestBody);

dynamic data = JsonConvert.DeserializeObject(requestBody);
dynamic? data = JsonConvert.DeserializeObject(requestBody);
try
{
string url = data.resource.url;
if (url.Contains("https://dev.azure.com/dnceng/"))
var url = data?.resource.url;
if (url is not null && url.Contains("https://dev.azure.com/dnceng/"))
{
return new OkResult();
}
Expand All @@ -99,8 +99,8 @@ public async Task<IActionResult> OnBuild(

var message = new BuildInfoMessage()
{
BuildNumber = data.resource.id,
ProjectId = data.resourceContainers.project.id
BuildNumber = data!.resource.id,
ProjectId = data!.resourceContainers.project.id
};

await completeCollector.AddAsync(JsonConvert.SerializeObject(message));
Expand All @@ -119,8 +119,8 @@ public async Task BuildCompleteAsync(
{
var logger = LoggerFactory.CreateLogger(nameof(BuildCompleteAsync));
var buildInfoMessage = JsonConvert.DeserializeObject<BuildInfoMessage>(message);
var projectName = buildInfoMessage.ProjectName;
var buildNumber = buildInfoMessage.BuildNumber;
var projectName = buildInfoMessage!.ProjectName;
var buildNumber = buildInfoMessage!.BuildNumber;
if (projectName is null)
{
var projectId = buildInfoMessage.ProjectId;
Expand Down Expand Up @@ -154,7 +154,7 @@ public async Task BuildRetryAsync(
[QueueTrigger(QueueNameBuildRetry, Connection = ConfigurationAzureBlobConnectionString)] string message)
{
var logger = LoggerFactory.CreateLogger(nameof(BuildRetryAsync));
var buildAttemptMessage = JsonConvert.DeserializeObject<BuildAttemptMessage>(message);
var buildAttemptMessage = JsonConvert.DeserializeObject<BuildAttemptMessage>(message)!;
if (buildAttemptMessage.BuildAttemptKey is { } buildAttemptKey)
{
var util = new BuildRetryUtil(Server, Context, logger);
Expand All @@ -174,7 +174,7 @@ public async Task TriageTrackingIssueAsync(
[QueueTrigger(QueueNameTriageTrackingIssue, Connection = ConfigurationAzureBlobConnectionString)] string message)
{
var logger = LoggerFactory.CreateLogger(nameof(TriageTrackingIssueAsync));
var issueMessage = JsonConvert.DeserializeObject<TriageTrackingIssueMessage>(message);
var issueMessage = JsonConvert.DeserializeObject<TriageTrackingIssueMessage>(message)!;
if (issueMessage.BuildMessage?.BuildKey is { } buildKey && issueMessage.ModelTrackingIssueId is { } trackingIssueId)
{
logger.LogInformation($"Triaging issue {trackingIssueId} against build {buildKey}");
Expand All @@ -197,7 +197,7 @@ public async Task TriageTrackingIssueRangeAsync(
[Queue(QueueNameTriageTrackingIssue, Connection = ConfigurationAzureBlobConnectionString)] IAsyncCollector<string> triageCollector)
{
var logger = LoggerFactory.CreateLogger(nameof(TriageTrackingIssueRangeAsync));
var rangeMessage = JsonConvert.DeserializeObject<TriageTrackingIssueRangeMessage>(message);
var rangeMessage = JsonConvert.DeserializeObject<TriageTrackingIssueRangeMessage>(message)!;
if (rangeMessage.ModelTrackingIssueId is { } issueId && rangeMessage.BuildMessages is { } buildMessages)
{
var list = new List<Task>();
Expand Down Expand Up @@ -230,7 +230,7 @@ public async Task TriageBuildAsync(
[Queue(QueueNameTriageTrackingIssue, Connection = ConfigurationAzureBlobConnectionString)] IAsyncCollector<string> triageCollector)
{
var logger = LoggerFactory.CreateLogger(nameof(TriageBuildAsync));
var buildMessage = JsonConvert.DeserializeObject<BuildMessage>(message);
var buildMessage = JsonConvert.DeserializeObject<BuildMessage>(message)!;
if (buildMessage.BuildKey is { } buildKey)
{
logger.LogInformation($"Triaging build: {buildKey}");
Expand Down Expand Up @@ -272,7 +272,7 @@ public async Task IssuesUpdateManualAsync(
[QueueTrigger(QueueNameIssueUpdateManual, Connection = ConfigurationAzureBlobConnectionString)] string message)
{
var logger = LoggerFactory.CreateLogger(nameof(IssuesUpdateManualAsync));
var updateMessage = JsonConvert.DeserializeObject<IssueUpdateManualMessage>(message);
var updateMessage = JsonConvert.DeserializeObject<IssueUpdateManualMessage>(message)!;
if (updateMessage.ModelTrackingIssueId is { } id)
{
var util = new TrackingGitHubUtil(GitHubClientFactory, Context, SiteLinkUtil, logger);
Expand All @@ -295,7 +295,7 @@ public async Task<IActionResult> OnGitHubEvent(
if (eventName == "pull_request")
{
string requestBody = await new StreamReader(request.Body).ReadToEndAsync().ConfigureAwait(false);
dynamic prInfo = JsonConvert.DeserializeObject(requestBody);
dynamic prInfo = JsonConvert.DeserializeObject(requestBody)!;
if (prInfo.action == "closed" &&
prInfo.pull_request != null &&
prInfo.pull_request.merged == true)
Expand Down Expand Up @@ -333,7 +333,7 @@ public async Task OnPullRequestMergedAsync(
{
var logger = LoggerFactory.CreateLogger(nameof(OnPullRequestMergedAsync));
var functionUtil = new FunctionUtil(logger);
var prMessage = JsonConvert.DeserializeObject<PullRequestMergedMessage>(message);
var prMessage = JsonConvert.DeserializeObject<PullRequestMergedMessage>(message)!;
var prKey = new GitHubPullRequestKey(prMessage.Organization!, prMessage.Repository!, prMessage.PullRequestNumber);
await functionUtil.OnPullRequestMergedAsync(
Server,
Expand Down
14 changes: 5 additions & 9 deletions DevOps.Functions/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using Azure.Identity;
using DevOps.Util;
using DevOps.Util.DotNet;
using DevOps.Util.DotNet.Triage;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Azure.KeyVault;
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureKeyVault;
using Microsoft.Extensions.Configuration.UserSecrets;
using Microsoft.Extensions.DependencyInjection;
using Octokit;
Expand All @@ -20,14 +18,12 @@ internal class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
var config = new ConfigurationBuilder()
.AddAzureKeyVault(DotNetConstants.KeyVaultEndPoint, keyVaultClient, new DefaultKeyVaultSecretManager())
.AddAzureKeyVault(new Uri(DotNetConstants.KeyVaultEndPoint), new DefaultAzureCredential())
.Build();

var connectionString = config[DotNetConstants.ConfigurationSqlConnectionString];
var azdoToken = config[DotNetConstants.ConfigurationAzdoToken];
var azdoToken = config[DotNetConstants.ConfigurationAzdoToken]!;
var helixToken = config[DotNetConstants.ConfigurationAzdoToken];
builder.Services.AddDbContext<TriageContext>(
options => options.UseSqlServer(connectionString, o => o.CommandTimeout((int)TimeSpan.FromMinutes(10).TotalSeconds)));
Expand All @@ -42,8 +38,8 @@ public override void Configure(IFunctionsHostBuilder builder)

builder.Services.AddScoped<GitHubClientFactory>(_ =>
{
var appId = int.Parse(config[DotNetConstants.ConfigurationGitHubAppId]);
var appPrivateKey = config[DotNetConstants.ConfigurationGitHubAppPrivateKey];
var appId = int.Parse(config[DotNetConstants.ConfigurationGitHubAppId]!);
var appPrivateKey = config[DotNetConstants.ConfigurationGitHubAppPrivateKey]!;
return new GitHubClientFactory(appId, appPrivateKey);
});
}
Expand Down
12 changes: 4 additions & 8 deletions DevOps.Status/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,23 @@ namespace DevOps.Status.Controllers
public class AccountController : Controller
{
[HttpGet("signin")]
public IActionResult SignIn(string? returnUrl = null)
{
return Challenge(
public IActionResult UserSignIn(string? returnUrl = null) =>
Challenge(
new AuthenticationProperties
{
RedirectUri = "/" + returnUrl
},
GitHubAuthenticationDefaults.AuthenticationScheme
);
}

[HttpGet("signout")]
[HttpPost("signout")]
public IActionResult SignOut()
{
return SignOut(
public IActionResult UserSignOut() =>
SignOut(
new AuthenticationProperties
{
RedirectUri = "/"
},
CookieAuthenticationDefaults.AuthenticationScheme);
}
}
}
12 changes: 5 additions & 7 deletions DevOps.Status/DevOps.Status.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<UserSecretsId>67c4a872-5dd7-422a-acad-fdbe907ace33</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AspNet.Security.OAuth.GitHub" Version="3.1.2" />
<PackageReference Include="Azure.Identity" Version="1.4.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.17" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
<PackageReference Include="Westwind.AspNetCore.Markdown" Version="3.4.0" />
<PackageReference Include="AspNet.Security.OAuth.GitHub" Version="6.0.14" />
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" />
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.5.0" />
<ProjectReference Include="..\DevOps.Util\DevOps.Util.csproj" />
<ProjectReference Include="..\DevOps.Util.DotNet\DevOps.Util.DotNet.csproj" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions DevOps.Status/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@
{
<img src="@avatarUrl.Value"
class="mr-1"
alt="@Context.User.Identity.Name"
alt="@Context.User!.Identity!.Name"
style="border-radius: 50%"
width="20"
height="20" />
}
}
@Context.User.Identity.Name
@Context.User!.Identity!.Name
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="/signout">Sign out</a>
Expand Down
1 change: 0 additions & 1 deletion DevOps.Status/Pages/Tracking/Issue.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading;
using System.Threading.Tasks;
using DevOps.Status.Util;
Expand Down
17 changes: 2 additions & 15 deletions DevOps.Status/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Azure.Identity;
using DevOps.Util.DotNet;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Azure.KeyVault;
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureKeyVault;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

Expand All @@ -24,18 +22,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
if (context.HostingEnvironment.IsProduction())
{
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
config.AddAzureKeyVault(DotNetConstants.KeyVaultEndPoint, keyVaultClient, new DefaultKeyVaultSecretManager());
}
else
{
config.AddAzureKeyVault(
DotNetConstants.KeyVaultEndPoint,
new DefaultKeyVaultSecretManager());
}
config.AddAzureKeyVault(new Uri(DotNetConstants.KeyVaultEndPoint), new DefaultAzureCredential());
})
.ConfigureWebHostDefaults(webBuilder =>
{
Expand Down
14 changes: 8 additions & 6 deletions DevOps.Status/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ public void ConfigureServices(IServiceCollection services)
options.ClaimActions.MapJsonKey(Constants.GitHubAvatarUrl, Constants.GitHubAvatarUrl);
options.Events.OnCreatingTicket = async context =>
{
var userName = context.Identity.Name.ToLower();
var gitHubClient = GitHubClientFactory.CreateForToken(context.AccessToken, AuthenticationType.Oauth);
var organizations = await gitHubClient.Organization.GetAllForUser(userName);
var microsoftOrg = organizations.FirstOrDefault(x => x.Login.ToLower() == "microsoft");
if (microsoftOrg is object)
if (context is { Identity: { Name: string userName }, AccessToken: string accessToken })
{
context.Identity.AddClaim(new Claim(context.Identity.RoleClaimType, Constants.TriageRole));
var gitHubClient = GitHubClientFactory.CreateForToken(accessToken, AuthenticationType.Oauth);
var organizations = await gitHubClient.Organization.GetAllForUser(userName.ToLower());
var microsoftOrg = organizations.FirstOrDefault(x => x.Login.ToLower() == "microsoft");
if (microsoftOrg is object)
{
context.Identity.AddClaim(new Claim(context.Identity.RoleClaimType, Constants.TriageRole));
}
}
};
});
Expand Down
6 changes: 5 additions & 1 deletion DevOps.Status/Util/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using DevOps.Util.DotNet.Triage;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.EntityFrameworkCore;
using Octokit;
using System;
Expand All @@ -26,6 +25,11 @@ public static class Extensions
public static async Task<IGitHubClient> CreateForUserAsync(this IGitHubClientFactory gitHubClientFactory, HttpContext httpContext)
{
var accessToken = await httpContext.GetTokenAsync("access_token");
if (accessToken is null)
{
throw new Exception("Cannot get access_token for user");
}

return GitHubClientFactory.CreateForToken(accessToken, AuthenticationType.Oauth);
}

Expand Down
1 change: 0 additions & 1 deletion DevOps.Status/Util/TimelineIssuesDisplay.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using DevOps.Util;
using DevOps.Util.DotNet.Triage;
using Microsoft.EntityFrameworkCore;
using Microsoft.VisualStudio.Web.CodeGeneration.Contracts.Messaging;
using Octokit;
using Org.BouncyCastle.Math.EC.Rfc7748;
using System;
Expand Down
6 changes: 3 additions & 3 deletions DevOps.Util.DotNet/DevOps.Util.DotNet.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Queues" Version="12.4.2" />
<ProjectReference Include="..\DevOps.Util\DevOps.Util.csproj" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.16" />
<PackageReference Include="YamlDotNet" Version="8.1.1" />
<PackageReference Include="Octokit" Version="0.47.0" />
<PackageReference Include="GitHubJwt" Version="0.0.4" />
<PackageReference Include="GitHubJwt" Version="0.0.6" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion DevOps.Util.DotNet/Triage/SearchTimelinesRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand Down
1 change: 0 additions & 1 deletion DevOps.Util.DotNet/Triage/TriageContextUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down
Loading

0 comments on commit 4a79e6a

Please sign in to comment.