Skip to content

Commit

Permalink
Merge pull request Kentico#380 from JosefDvorak/DotnetUpdate
Browse files Browse the repository at this point in the history
Add GitHub Actions & Upgrade to .NET 8
  • Loading branch information
kentico-ericd authored Jan 16, 2024
2 parents e6d687d + 597bd22 commit ffcef81
Show file tree
Hide file tree
Showing 20 changed files with 163 additions and 74 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:


jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
node-version: 20.7.x
- name: Restore dependencies
run: dotnet restore
- name: Build front-end app
run: |
cd ./KenticoInspector.WebApplication/ClientApp
npm i
npm run build
- name: Build dotnet app
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
5 changes: 3 additions & 2 deletions KenticoInspector.Actions/KenticoInspector.Actions.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="4.9.2" />
<PackageReference Include="Autofac" Version="7.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>

<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>

<LangVersion>7.1</LangVersion>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
28 changes: 28 additions & 0 deletions KenticoInspector.Core/Converters/VersionListConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System;

namespace KenticoInspector.Core.Converters
{
public class VersionListConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return (objectType == typeof(List<Version>));
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
serializer.Converters.Add(new VersionObjectConverter());

serializer.Serialize(writer, value);
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
serializer.Converters.Add(new VersionObjectConverter());

return serializer.Deserialize(reader, typeof(Version));
}
}
}
26 changes: 26 additions & 0 deletions KenticoInspector.Core/Converters/VersionObjectConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;

namespace KenticoInspector.Core.Converters
{
public class VersionObjectConverter : JsonConverter<Version>
{
public override void WriteJson(JsonWriter writer, Version value, JsonSerializer serializer)
{
JObject jsonVersion = new JObject
{
{ "major", value.Major },
{ "minor", value.Minor },
{ "build", value.Build },
};
jsonVersion.WriteTo(writer);
}

public override Version ReadJson(JsonReader reader, Type objectType, Version existingValue, bool hasExistingValue, JsonSerializer serializer)
{
JObject jsonVersion = JObject.Load(reader);
return new Version((int)jsonVersion["major"], (int)jsonVersion["minor"], (int)jsonVersion["build"]);
}
}
}
8 changes: 2 additions & 6 deletions KenticoInspector.Core/Helpers/DirectoryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ namespace KenticoInspector.Core.Helpers
{
public static class DirectoryHelper
{
private const string filePrefix = "file:\\";

/// <summary>
/// Gets the executing directory of the application.
/// </summary>
/// <returns>A string that contains the path of the executing directory, and does not end with a backslash (\).</returns>
public static string GetExecutingDirectory()
{
var assemblyPath = Assembly.GetExecutingAssembly().CodeBase;
var assemblyDirectory = Path.GetDirectoryName(assemblyPath);

return assemblyDirectory.Substring(filePrefix.Length);
var assemblyPath = Assembly.GetExecutingAssembly().Location;
return Path.GetDirectoryName(assemblyPath);
}
}
}
12 changes: 6 additions & 6 deletions KenticoInspector.Core/KenticoInspector.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>7.1</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<Version />
<PackageVersion />
<AssemblyVersion />
Expand All @@ -11,9 +11,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="4.9.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
<PackageReference Include="Autofac" Version="7.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion KenticoInspector.Core/Models/InstanceDetails.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using KenticoInspector.Core.Converters;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace KenticoInspector.Core.Models
Expand All @@ -7,8 +9,10 @@ public class InstanceDetails
{
public Guid Guid { get; set; }

[JsonConverter(typeof(VersionObjectConverter))]
public Version AdministrationVersion { get; set; }

[JsonConverter(typeof(VersionObjectConverter))]
public Version DatabaseVersion { get; set; }

public IEnumerable<Site> Sites { get; set; }
Expand Down
7 changes: 5 additions & 2 deletions KenticoInspector.Core/Modules/IModule.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

using KenticoInspector.Core.Models;
using KenticoInspector.Core.Converters;

namespace KenticoInspector.Core.Modules
{
public interface IModule
{
string Codename { get; }

[JsonConverter(typeof(VersionListConverter))]
IList<Version> CompatibleVersions { get; }

[JsonConverter(typeof(VersionListConverter))]
IList<Version> IncompatibleVersions { get; }

IList<string> Tags { get; }
Expand Down
4 changes: 2 additions & 2 deletions KenticoInspector.Core/Tokens/TokenExpressionResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;

namespace KenticoInspector.Core.Tokens
Expand Down Expand Up @@ -86,7 +86,7 @@ private static string ResolveTokenExpression(string tokenExpression, IDictionary
{
if (Regex.IsMatch(innerTokenExpression, pattern))
{
var expressionObject = FormatterServices.GetUninitializedObject(tokenExpressionType) as ITokenExpression;
var expressionObject = RuntimeHelpers.GetUninitializedObject(tokenExpressionType) as ITokenExpression;

resolvedExpression = expressionObject.Resolve(innerTokenExpression, tokenDictionary);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>

<TargetFramework>net8.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>7.1</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<Version />
<PackageVersion />
<AssemblyVersion />
Expand All @@ -11,11 +11,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="4.9.2" />
<PackageReference Include="Autofac" Version="7.1.0" />
<PackageReference Include="Dapper" Version="1.60.1" />
<PackageReference Include="Dapper.FluentMap" Version="1.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
<PackageReference Include="YamlDotNet" Version="6.1.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>

<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>

<LangVersion>7.1</LangVersion>
<LangVersion>9.0</LangVersion>
<Version />
<PackageVersion />
<AssemblyVersion />
Expand Down
8 changes: 4 additions & 4 deletions KenticoInspector.Reports/KenticoInspector.Reports.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>7.1</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<Version />
<PackageVersion />
<AssemblyVersion />
Expand All @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="4.9.2" />
<PackageReference Include="Autofac" Version="7.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 7 additions & 9 deletions KenticoInspector.WebApplication/Controllers/ActionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;

using KenticoInspector.Core.Models;
using KenticoInspector.Core.Modules;
Expand All @@ -23,20 +24,17 @@ public ActionsController(IModuleService moduleService)
}

[HttpGet("{instanceGuid}")]
public ActionResult<IEnumerable<IAction>> Get(Guid instanceGuid)
public Task<IEnumerable<IAction>> Get(Guid instanceGuid)
{
return Ok(moduleService.GetActions(instanceGuid));
return Task.FromResult(moduleService.GetActions(instanceGuid));
}

// POST api/values
[HttpPost("{codename}/execute/{instanceGuid}")]
public ActionResult<ActionResults> Excecute(string codename, Guid instanceGuid)
public async Task<ActionResults> Excecute(string codename, Guid instanceGuid)
{
using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
{
var optionsJson = reader.ReadToEnd();
return moduleService.ExecuteAction(codename, instanceGuid, optionsJson);
}
using StreamReader reader = new(Request.Body, Encoding.UTF8);
var optionsJson = await reader.ReadToEndAsync();
return moduleService.ExecuteAction(codename, instanceGuid, optionsJson);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using KenticoInspector.Core.Models;
using KenticoInspector.Core.Services.Interfaces;
Expand All @@ -21,9 +22,9 @@ public InstancesController(IInstanceService instanceService)
}

[HttpGet("details/{instanceGuid}")]
public ActionResult<InstanceDetails> Details(Guid instanceGuid)
public Task<InstanceDetails> Details(Guid instanceGuid)
{
return _instanceService.GetInstanceDetails(instanceGuid);
return Task.FromResult(_instanceService.GetInstanceDetails(instanceGuid));
}

[HttpDelete("{instanceGuid}")]
Expand All @@ -33,22 +34,22 @@ public void Delete(Guid instanceGuid)
}

[HttpGet]
public ActionResult<IEnumerable<Instance>> Get()
public Task<List<Instance>> Get()
{
var instances = _instanceService.GetInstances();
return instances.ToList();
return Task.FromResult(instances.ToList());
}

[HttpGet("{instanceGuid}")]
public ActionResult<Instance> Get(Guid instanceGuid)
public Task<Instance> Get(Guid instanceGuid)
{
return _instanceService.GetInstance(instanceGuid);
return Task.FromResult(_instanceService.GetInstance(instanceGuid));
}

[HttpPost]
public Instance Post([FromBody] Instance instance)
public Task<Instance> Post([FromBody] Instance instance)
{
return _instanceService.UpsertInstance(instance);
return Task.FromResult(_instanceService.UpsertInstance(instance));
}
}
}
Loading

0 comments on commit ffcef81

Please sign in to comment.