Skip to content

Commit 76b95bd

Browse files
authored
dotnet 8 (#119)
* dotnet 8
1 parent 91bf831 commit 76b95bd

File tree

135 files changed

+962
-854
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+962
-854
lines changed

.github/workflows/client.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Setup dotnet
1818
uses: actions/setup-dotnet@v1
1919
with:
20-
dotnet-version: "6.0.x"
20+
dotnet-version: "8.0.x"
2121

2222
- name: Setup Package Name
2323
id: package_name

.github/workflows/main.yml

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish Docker Images
1+
name: Build and Publish Image
22

33
on:
44
pull_request:
@@ -8,66 +8,13 @@ on:
88
branches: [ development, staging ]
99
release:
1010
types: [ "published" ]
11-
workflow_dispatch:
12-
inputs:
13-
tagName:
14-
description: 'Tag of the image you want to build and push'
15-
required: true
1611

1712
jobs:
18-
build:
19-
runs-on: ubuntu-latest
20-
steps:
21-
22-
- name: Checkout
23-
uses: actions/checkout@v2
24-
25-
- name: Prepare
26-
id: prep
27-
run: |
28-
DOCKER_IMAGE=cmusei/blueprint-api
29-
VERSION=development
30-
if [[ ! -z "${{ github.event.inputs.tagName }}" ]]; then
31-
VERSION=${{ github.event.inputs.tagName }}
32-
TAGS="${DOCKER_IMAGE}:${VERSION}"
33-
elif [[ $GITHUB_REF == refs/tags/* ]]; then
34-
VERSION=${GITHUB_REF#refs/tags/}
35-
MAJORMINORVERSION=$(echo $VERSION | grep -oP '(\d+)\.(\d+)')
36-
TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${MAJORMINORVERSION}"
37-
elif [[ $GITHUB_REF == refs/heads/* ]]; then
38-
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
39-
TAGS="${DOCKER_IMAGE}:${VERSION}"
40-
fi
41-
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
42-
echo ::set-output name=push::false
43-
echo "event is pull_request, not pushing image"
44-
else
45-
echo ::set-output name=push::true
46-
echo "event is not pull_request, pushing image"
47-
fi
48-
echo ::set-output name=version::${VERSION}
49-
echo ::set-output name=tags::${TAGS}
50-
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
51-
52-
- name: Set up Docker Buildx
53-
uses: docker/setup-buildx-action@v1
54-
55-
- name: Login to DockerHub
56-
if: github.event_name != 'pull_request'
57-
uses: docker/login-action@v1
58-
with:
59-
username: ${{ secrets.DOCKERHUB_USERNAME }}
60-
password: ${{ secrets.DOCKERHUB_PASSWORD }}
61-
62-
- name: Build and push
63-
uses: docker/build-push-action@v2
64-
with:
65-
context: .
66-
file: ./Dockerfile
67-
push: ${{ steps.prep.outputs.push }}
68-
pull: true
69-
tags: ${{ steps.prep.outputs.tags }}
70-
labels: |
71-
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
72-
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
73-
org.opencontainers.image.revision=${{ github.sha }}
13+
build-and-publish:
14+
name: Build and Publish
15+
uses: cmu-sei/Crucible-Github-Actions/.github/workflows/[email protected]
16+
with:
17+
imageName: cmusei/blueprint-api
18+
secrets:
19+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
20+
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}

Blueprint.Api.Client/Blueprint.Api.Client.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="System.Text.Json" Version="6.0.1" />
14+
<PackageReference Include="System.Text.Json" Version="8.0.4" />
1515
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
1616
</ItemGroup>
1717

Blueprint.Api.Client/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# How to create the nuget package for Blueprint.Api.Client
22
1. cd ../Blueprint.Api
3-
2. swagger tofile --output ../Blueprint.Api.Client/swagger.json bin/Debug/net6.0/Blueprint.Api.dll v1
3+
2. swagger tofile --output ../Blueprint.Api.Client/swagger.json bin/Debug/net8.0/Blueprint.Api.dll v1
44
3. cd ../Blueprint.Api.Client
55
4. npm install
66
5. ./node_modules/.bin/nswag run /runtime:Net60
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
66
<ProjectGuid>{FA9D19BE-32D2-405D-A3A3-0A9061BC0DE5}</ProjectGuid>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.2" />
10+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" />
1111
</ItemGroup>
1212

13-
</Project>
13+
</Project>

Blueprint.Api.Data/BlueprintContext.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ namespace Blueprint.Api.Data
1717
public class BlueprintContext : DbContext
1818
{
1919
public List<Entry> Entries { get; set; } = new List<Entry>();
20-
private DbContextOptions<BlueprintContext> _options;
20+
// Needed for EventInterceptor
21+
public IServiceProvider ServiceProvider;
2122

22-
public BlueprintContext(DbContextOptions<BlueprintContext> options) : base(options) {
23-
_options = options;
24-
}
23+
public BlueprintContext(DbContextOptions<BlueprintContext> options) : base(options) { }
2524

2625
public DbSet<UserEntity> Users { get; set; }
2726
public DbSet<PermissionEntity> Permissions { get; set; }
@@ -120,4 +119,3 @@ private void SaveEntries()
120119
}
121120
}
122121
}
123-
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2024 Carnegie Mellon University. All Rights Reserved.
2+
// Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information.
3+
using System;
4+
using Microsoft.EntityFrameworkCore;
5+
namespace Blueprint.Api.Data;
6+
public class BlueprintContextFactory : IDbContextFactory<BlueprintContext>
7+
{
8+
private readonly IDbContextFactory<BlueprintContext> _pooledFactory;
9+
private readonly IServiceProvider _serviceProvider;
10+
public BlueprintContextFactory(
11+
IDbContextFactory<BlueprintContext> pooledFactory,
12+
IServiceProvider serviceProvider)
13+
{
14+
_pooledFactory = pooledFactory;
15+
_serviceProvider = serviceProvider;
16+
}
17+
public BlueprintContext CreateDbContext()
18+
{
19+
var context = _pooledFactory.CreateDbContext();
20+
// Inject the current scope's ServiceProvider
21+
context.ServiceProvider = _serviceProvider;
22+
return context;
23+
}
24+
}

Blueprint.Api.Data/Entry.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2024 Carnegie Mellon University. All Rights Reserved.
2+
// Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information.
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using Microsoft.EntityFrameworkCore;
7+
using Microsoft.EntityFrameworkCore.ChangeTracking;
8+
namespace Blueprint.Api.Data;
9+
public class Entry
10+
{
11+
public object Entity { get; set; }
12+
public EntityState State { get; set; }
13+
public IEnumerable<PropertyEntry> Properties { get; set; }
14+
private Dictionary<string, bool> IsPropertyModified { get; set; } = new();
15+
public Entry(EntityEntry entry, Entry oldEntry = null)
16+
{
17+
Entity = entry.Entity;
18+
State = entry.State;
19+
Properties = entry.Properties;
20+
ProcessOldEntry(oldEntry);
21+
foreach (var prop in Properties)
22+
{
23+
IsPropertyModified[prop.Metadata.Name] = prop.IsModified;
24+
}
25+
}
26+
private void ProcessOldEntry(Entry oldEntry)
27+
{
28+
if (oldEntry == null) return;
29+
if (oldEntry.State != EntityState.Unchanged && oldEntry.State != EntityState.Detached)
30+
{
31+
State = oldEntry.State;
32+
}
33+
var modifiedProperties = oldEntry.GetModifiedProperties();
34+
foreach (var property in Properties)
35+
{
36+
if (modifiedProperties.Contains(property.Metadata.Name))
37+
{
38+
property.IsModified = true;
39+
}
40+
}
41+
}
42+
public string[] GetModifiedProperties()
43+
{
44+
return IsPropertyModified
45+
.Where(x => x.Value)
46+
.Select(x => x.Key)
47+
.ToArray();
48+
}
49+
}

Blueprint.Api.Data/Extensions/ModelBuilderExtensions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public static void AddPostgresUUIDGeneration(this ModelBuilder builder)
4545
.GetEntityTypes()
4646
.SelectMany(t => t.GetProperties())
4747
.Where(p => p.ClrType == typeof(Guid))
48-
.Select(p => builder.Entity(p.DeclaringEntityType.ClrType).Property(p.Name))
49-
.Where(p => p.Metadata.ValueGenerated == Microsoft.EntityFrameworkCore.Metadata.ValueGenerated.OnAdd &&
48+
.Select(p => builder.Entity(p.DeclaringType.ClrType).Property(p.Name))
49+
.Where(p => p.Metadata.ValueGenerated == ValueGenerated.OnAdd &&
5050
p.Metadata.IsPrimaryKey())
5151
)
5252
{
@@ -80,4 +80,3 @@ public static void UsePostgresCasing(this ModelBuilder builder)
8080
}
8181
}
8282
}
83-

Blueprint.Api.Migrations.PostgreSQL/Blueprint.Api.Migrations.PostgreSQL.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
66
<ProjectGuid>{94A7F5B1-E6D5-465C-B07F-2573ACCD0236}</ProjectGuid>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.2" />
10+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

0 commit comments

Comments
 (0)