Skip to content

Commit

Permalink
feat: upgrade to .NET 8 (#19)
Browse files Browse the repository at this point in the history
* feat: upgrade to .NET 8
* chore: disable Azure WebApp deployment
* chore: remove CNAME
  • Loading branch information
Adrrei authored Nov 18, 2023
1 parent 25f21e7 commit 9023f0f
Show file tree
Hide file tree
Showing 41 changed files with 186 additions and 5,129 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: B) Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'

- name: C) Run Tests
run: dotnet test ${{ env.TESTS_PROJECT }} --configuration Release
Expand All @@ -34,16 +34,16 @@ jobs:
run: |
echo Pull Request Version: ${{ env.PULL_REQUEST_VERSION }}
- name: F) Azure Docker Login
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.REGISTRY_SERVER }}
username: ${{ secrets.REGISTRY_NAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
# - name: F) Azure Docker Login
# uses: azure/docker-login@v1
# with:
# login-server: ${{ secrets.REGISTRY_SERVER }}
# username: ${{ secrets.REGISTRY_NAME }}
# password: ${{ secrets.REGISTRY_PASSWORD }}

- name: G) Docker Image to Azure Container Registry
if: success()
run: |
echo ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.PULL_REQUEST_VERSION }}
docker build -t ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.PULL_REQUEST_VERSION }} --build-arg versionNumber=${{ env.PULL_REQUEST_VERSION }} .
docker push ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.PULL_REQUEST_VERSION }}
# - name: G) Docker Image to Azure Container Registry
# if: success()
# run: |
# echo ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.PULL_REQUEST_VERSION }}
# docker build -t ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.PULL_REQUEST_VERSION }} --build-arg versionNumber=${{ env.PULL_REQUEST_VERSION }} .
# docker push ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.PULL_REQUEST_VERSION }}
56 changes: 28 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: C) Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'

- name: D) Run Tests
run: dotnet test ${{ env.TESTS_PROJECT }} --configuration Release
Expand All @@ -49,34 +49,34 @@ jobs:
run: |
echo Release Version: ${{ env.RELEASE_VERSION }}
- name: H) Login via Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# - name: H) Login via Azure CLI
# uses: azure/login@v1
# with:
# creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: I) Azure Docker Login
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.REGISTRY_SERVER }}
username: ${{ secrets.REGISTRY_NAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
# - name: I) Azure Docker Login
# uses: azure/docker-login@v1
# with:
# login-server: ${{ secrets.REGISTRY_SERVER }}
# username: ${{ secrets.REGISTRY_NAME }}
# password: ${{ secrets.REGISTRY_PASSWORD }}

- name: J) Docker Images to Azure Container Registry
if: success()
run: |
echo ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}
docker build -t ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }} --build-arg versionNumber=${{ env.RELEASE_VERSION }} .
docker tag ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }} ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ github.run_number }}
docker push ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ github.run_number }}
docker push ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}
# - name: J) Docker Images to Azure Container Registry
# if: success()
# run: |
# echo ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}
# docker build -t ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }} --build-arg versionNumber=${{ env.RELEASE_VERSION }} .
# docker tag ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }} ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ github.run_number }}
# docker push ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ github.run_number }}
# docker push ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}

- name: K) Deploy to Azure WebApp for Containers
if: success()
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.APP_NAME }}
images: ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}
# - name: K) Deploy to Azure WebApp for Containers
# if: success()
# uses: azure/webapps-deploy@v2
# with:
# app-name: ${{ env.APP_NAME }}
# images: ${{ secrets.REGISTRY_SERVER }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}

- name: L) Azure Logout
if: always()
run: az logout
# - name: L) Azure Logout
# if: always()
# run: az logout
1 change: 0 additions & 1 deletion CNAME

This file was deleted.

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine3.17 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build

EXPOSE 80

Expand All @@ -8,7 +8,7 @@ WORKDIR "/src/URU/"

RUN dotnet publish "URU.csproj" -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine3.17
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine

RUN apk add --no-cache icu-libs
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

My personal website.

The current version is developed with **C# 11.0**, **[.NET 7](https://dotnet.microsoft.com)**, **JavaScript**, and **HTML5 & CSS3**.
The current version is developed with **C# 12.0**, **[.NET 8](https://dotnet.microsoft.com)**, **JavaScript**, and **HTML5 & CSS3**.
**[GitHub Actions](https://github.com/features/actions)** is used in combination with **[Azure Pipelines](https://azure.microsoft.com/en-us/services/devops/pipelines/)** for CI/CD using **[Docker](https://azure.microsoft.com/en-us/services/kubernetes-service/docker/)**.
**[Semantic-Relase](https://github.com/semantic-release/semantic-release)** is used for automatic versioning.

Expand Down
12 changes: 3 additions & 9 deletions src/URU.Client/Data/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
namespace URU.Client.Data
{
public class ClientConfiguration
public class ClientConfiguration(string clientId, string clientSecret)
{
public ClientConfiguration(string clientId, string clientSecret)
{
ClientId = clientId;
ClientSecret = clientSecret;
}

public string ClientId { get; set; }
public string ClientId { get; set; } = clientId;

public string ClientSecret { get; set; }
public string ClientSecret { get; set; } = clientSecret;
}

public class SpotifyConfiguration
Expand Down
20 changes: 7 additions & 13 deletions src/URU.Client/Resources/SpotifyResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@

namespace URU.Client.Resources
{
public class SpotifyResource
public class SpotifyResource(HttpClient client)
{
private readonly string Endpoint;
private readonly HttpClient Client;

public SpotifyResource(HttpClient client)
{
Endpoint = "https://api.spotify.com/v1";
Client = client;
}
private readonly string Endpoint = "https://api.spotify.com/v1";
private readonly HttpClient Client = client;

public string ConstructEndpoint(User user, Method method, (string query, string value)[]? parameters)
{
Expand Down Expand Up @@ -48,7 +42,7 @@ public string ConstructEndpoint(User user, Method method, (string query, string

private async Task<T> GetObject<T>(string spotifyUrl)
{
var response = await Client.GetAsync(spotifyUrl, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
var response = await Client.GetAsync(spotifyUrl, HttpCompletionOption.ResponseHeadersRead);

if (!response.IsSuccessStatusCode)
throw new HttpRequestException();
Expand All @@ -59,7 +53,7 @@ private async Task<T> GetObject<T>(string spotifyUrl)

private async Task<Item[]> QueryPlaylistItems(string playlistUrl)
{
var response = await Client.GetAsync(playlistUrl, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
var response = await Client.GetAsync(playlistUrl, HttpCompletionOption.ResponseHeadersRead);
string result = await response.Content.ReadAsStringAsync();
var playlist = JsonConvert.DeserializeObject<Playlist>(result);

Expand All @@ -71,12 +65,12 @@ private async Task<Item[]> QueryPlaylistItems(string playlistUrl)

private async Task<Track[]> QueryAllTracks(string trackUrl)
{
var response = await Client.GetAsync(trackUrl, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
var response = await Client.GetAsync(trackUrl, HttpCompletionOption.ResponseHeadersRead);
string result = await response.Content.ReadAsStringAsync();
var tracks = JsonConvert.DeserializeObject<Tracks>(result);

if (tracks?.AllTracks == null)
return Array.Empty<Track>();
return [];

return tracks.AllTracks;
}
Expand Down
4 changes: 2 additions & 2 deletions src/URU.Client/URU.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down
36 changes: 10 additions & 26 deletions src/URU.Models/Spotify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public enum Method

public partial class ListedGenres
{
public List<string> Genres = new()
{
public List<string> Genres =
[
"Bass House",
"Big Room",
"Breakbeat",
Expand All @@ -38,29 +38,19 @@ public partial class ListedGenres
"Techno",
"Trance",
"Trap",
};
];
}

public partial class Favorites
public partial class Favorites(string[] ids)
{
[JsonProperty("favorites")]
public string[] Ids { get; set; }

public Favorites(string[] ids)
{
Ids = ids;
}
public string[] Ids { get; set; } = ids;
}

public partial class Genres
public partial class Genres(Dictionary<string, (long, string)> counts)
{
[JsonProperty("genres")]
public Dictionary<string, (long, string)> Counts { get; set; }

public Genres(Dictionary<string, (long, string)> counts)
{
Counts = counts;
}
public Dictionary<string, (long, string)> Counts { get; set; } = counts;
}

public partial class TracksByYear
Expand Down Expand Up @@ -147,21 +137,15 @@ public partial class Tracks
public long Total { get; set; }
}

public partial class User
public partial class User(string userId, string playlistId)
{
public string PlaylistId { get; set; }
public string PlaylistId { get; set; } = playlistId;

public string UserId { get; set; }
public string UserId { get; set; } = userId;

public long Offset { get; set; } = 0;

public long Limit { get; set; } = 1;

public User(string userId, string playlistId)
{
UserId = userId;
PlaylistId = playlistId;
}
}

internal static class Converter
Expand Down
2 changes: 1 addition & 1 deletion src/URU.Models/URU.Models.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
5 changes: 1 addition & 4 deletions src/URU/Controllers/ErrorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ public ErrorController()

public IActionResult Index(int? statusCode)
{
if (statusCode == null)
{
statusCode = StatusCodes.Status404NotFound;
}
statusCode ??= StatusCodes.Status404NotFound;

return View(statusCode);
}
Expand Down
9 changes: 2 additions & 7 deletions src/URU/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@
namespace URU.Controllers
{
[SecurityHeaders]
public class HomeController : Controller
public class HomeController(IStringLocalizer<HomeController> stringLocalizer) : Controller
{
private readonly IStringLocalizer<HomeController> _stringLocalizer;

public HomeController(IStringLocalizer<HomeController> stringLocalizer)
{
_stringLocalizer = stringLocalizer;
}
private readonly IStringLocalizer<HomeController> _stringLocalizer = stringLocalizer;

public IActionResult Index()
{
Expand Down
9 changes: 2 additions & 7 deletions src/URU/Controllers/MastersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
namespace URU.Controllers
{
[SecurityHeaders]
public class MastersController : Controller
public class MastersController(IStringLocalizer<MastersController> stringLocalizer) : Controller
{
private readonly IStringLocalizer<MastersController> _stringLocalizer;

public MastersController(IStringLocalizer<MastersController> stringLocalizer)
{
_stringLocalizer = stringLocalizer;
}
private readonly IStringLocalizer<MastersController> _stringLocalizer = stringLocalizer;

public IActionResult Index()
{
Expand Down
7 changes: 2 additions & 5 deletions src/URU/Controllers/SpotifyApiController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using URU.Client.Data;
using URU.Models;
Expand Down Expand Up @@ -35,7 +32,7 @@ public async Task<IActionResult> Favorites()
Limit = 50,
};

(string query, string value)[] parameters = { ("limit", user.Limit.ToString()) };
(string query, string value)[] parameters = [("limit", user.Limit.ToString())];

try
{
Expand All @@ -59,7 +56,7 @@ public async Task<IActionResult> Genres()
Limit = 50,
};

(string query, string value)[] parameters = { ("limit", user.Limit.ToString()) };
(string query, string value)[] parameters = [("limit", user.Limit.ToString())];

try
{
Expand Down
9 changes: 2 additions & 7 deletions src/URU/Controllers/SpotifyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@
namespace URU.Controllers
{
[SecurityHeaders]
public class SpotifyController : Controller
public class SpotifyController(IStringLocalizer<SpotifyController> stringLocalizer) : Controller
{
private readonly IStringLocalizer<SpotifyController> _stringLocalizer;

public SpotifyController(IStringLocalizer<SpotifyController> stringLocalizer)
{
_stringLocalizer = stringLocalizer;
}
private readonly IStringLocalizer<SpotifyController> _stringLocalizer = stringLocalizer;

public IActionResult Index()
{
Expand Down
Loading

0 comments on commit 9023f0f

Please sign in to comment.