Skip to content

Commit

Permalink
👷 Update CICD workflow to request required permissions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontaylordev committed Aug 29, 2023
1 parent 40276ff commit bc4677a
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 121 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
- LICENSE
- README.md

permissions:
id-token: write
contents: read

jobs:

build:
Expand Down
4 changes: 2 additions & 2 deletions CleanArchitecture.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<metadata>

<id>Clean.Architecture.Solution.Template</id>
<version>8.0.0-preview.7.1</version>
<version>8.0.0-preview.7.2</version>
<title>Clean Architecture Solution Template</title>
<authors>JasonTaylorDev</authors>
<description>Clean Architecture Solution Template for .NET 8.</description>
<summary>
A Clean Architecture Solution Template for creating apps using Angular, React, or Web API only with ASP.NET Core.
</summary>
<releaseNotes>
Upgrade .NET 8.0.0-preview.7
Update CICD workflow to request required permissions.
</releaseNotes>

<projectUrl>https://github.com/JasonTaylorDev/CleanArchitecture</projectUrl>
Expand Down
102 changes: 51 additions & 51 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
<!-- For more info on central package management go to https://devblogs.microsoft.com/nuget/introducing-central-package-management/ -->
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Ardalis.GuardClauses" Version="4.0.1" />
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" />
<PackageVersion Include="Azure.Identity" Version="1.9.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="FluentAssertions" Version="6.11.0" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="11.6.0" />
<PackageVersion Include="MediatR" Version="12.1.1" />
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0-preview.7.23375.9" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0-preview.7.23375.9" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0-preview.6.23329.11" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0-preview.7.23375.9" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.0-preview.7.23375.9" />
<!--#if (!UseApiOnly)-->
<PackageVersion Include="Microsoft.AspNetCore.SpaProxy" Version="8.0.0-preview.7.23375.9" />
<!--#endif-->
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.0-preview.7.23375.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0-preview.7.23375.4" />
<!--#if (UseSQLite)-->
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0-preview.7.23375.4" />
<!--#endif-->
<!--#if (UseLocalDB)-->
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0-preview.7.23375.4" />
<!--#endif-->
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0-preview.7.23375.4" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0-preview.7.23375.6" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0-preview.7.23375.6" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.0-preview.7.23375.9" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageVersion Include="Moq" Version="4.18.4" />
<PackageVersion Include="NSwag.AspNetCore" Version="13.19.0" />
<PackageVersion Include="NSwag.MSBuild" Version="13.19.0" />
<PackageVersion Include="nunit" Version="3.13.3" />
<PackageVersion Include="NUnit.Analyzers" Version="3.6.1" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="Respawn" Version="6.1.0" />
<PackageVersion Include="Testcontainers.MsSql" Version="3.3.0" />
<PackageVersion Include="ZymLabs.NSwag.FluentValidation.AspNetCore" Version="0.6.2" />
<!--#if(!UseApiOnly)-->
<PackageVersion Include="Microsoft.Playwright" Version="1.35.0" />
<PackageVersion Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" />
<PackageVersion Include="SpecFlow.NUnit" Version="3.9.74" />
<!--#endif-->
</ItemGroup>
<!-- For more info on central package management go to https://devblogs.microsoft.com/nuget/introducing-central-package-management/ -->
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Ardalis.GuardClauses" Version="4.0.1" />
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" />
<PackageVersion Include="Azure.Identity" Version="1.9.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="FluentAssertions" Version="6.11.0" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="11.6.0" />
<PackageVersion Include="MediatR" Version="12.1.1" />
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0-preview.7.23375.9" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0-preview.7.23375.9" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0-preview.6.23329.11" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0-preview.7.23375.9" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.0-preview.7.23375.9" />
<!--#if (!UseApiOnly)-->
<PackageVersion Include="Microsoft.AspNetCore.SpaProxy" Version="8.0.0-preview.7.23375.9" />
<!--#endif-->
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.0-preview.7.23375.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0-preview.7.23375.4" />
<!--#if (UseSQLite)-->
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0-preview.7.23375.4" />
<!--#endif-->
<!--#if (UseLocalDB)-->
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0-preview.7.23375.4" />
<!--#endif-->
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0-preview.7.23375.4" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0-preview.7.23375.6" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0-preview.7.23375.6" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.0-preview.7.23375.9" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageVersion Include="Moq" Version="4.18.4" />
<PackageVersion Include="NSwag.AspNetCore" Version="13.19.0" />
<PackageVersion Include="NSwag.MSBuild" Version="13.19.0" />
<PackageVersion Include="nunit" Version="3.13.3" />
<PackageVersion Include="NUnit.Analyzers" Version="3.6.1" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="Respawn" Version="6.1.0" />
<PackageVersion Include="Testcontainers.MsSql" Version="3.3.0" />
<PackageVersion Include="ZymLabs.NSwag.FluentValidation.AspNetCore" Version="0.6.2" />
<!--#if(!UseApiOnly)-->
<PackageVersion Include="Microsoft.Playwright" Version="1.35.0" />
<PackageVersion Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" />
<PackageVersion Include="SpecFlow.NUnit" Version="3.9.74" />
<!--#endif-->
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions README-template.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CleanArchitecture

The project was generated using the [Clean.Architecture.Solution.Template](https://github.com/jasontaylordev/CleanArchitecture) version 8.0.0-preview.7.1.
The project was generated using the [Clean.Architecture.Solution.Template](https://github.com/jasontaylordev/CleanArchitecture) version 8.0.0-preview.7.2.

## Build

Expand Down Expand Up @@ -42,7 +42,7 @@ dotnet new ca-usecase -n GetTodos -fn TodoLists -ut query -rt TodosVm
If you encounter the error *"No templates or subcommands found matching: 'ca-usecase'."*, install the template and try again:

```bash
dotnet new install Clean.Architecture.Solution.Template::8.0.0-preview.7.1
dotnet new install Clean.Architecture.Solution.Template::8.0.0-preview.7.2
```

## Test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If you find this project useful, please give it a star. Thanks! ⭐

The easiest way to get started is to install the [.NET template](https://www.nuget.org/packages/Clean.Architecture.Solution.Template):
```
dotnet new install Clean.Architecture.Solution.Template::8.0.0-preview.7.1
dotnet new install Clean.Architecture.Solution.Template::8.0.0-preview.7.2
```

Once installed, create a new solution using the template. You can choose to use Angular, React, or create a Web API-only solution. Specify the client framework using the `-cf` or `--client-framework` option, and provide the output directory where your project will be created. Here are some examples:
Expand Down
130 changes: 65 additions & 65 deletions src/Infrastructure/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
using CleanArchitecture.Application.Common.Interfaces;
using CleanArchitecture.Domain.Constants;
using CleanArchitecture.Infrastructure.Data;
using CleanArchitecture.Infrastructure.Data.Interceptors;
using CleanArchitecture.Infrastructure.Identity;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration;

namespace Microsoft.Extensions.DependencyInjection;

public static class DependencyInjection
{
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString("DefaultConnection");

Guard.Against.Null(connectionString, message: "Connection string 'DefaultConnection' not found.");

services.AddScoped<ISaveChangesInterceptor, AuditableEntityInterceptor>();
services.AddScoped<ISaveChangesInterceptor, DispatchDomainEventsInterceptor>();

services.AddDbContext<ApplicationDbContext>((sp, options) =>
{
options.AddInterceptors(sp.GetServices<ISaveChangesInterceptor>());
#if (UseSQLite)
options.UseSqlite(connectionString);
#else
options.UseSqlServer(connectionString);
#endif
});

services.AddScoped<IApplicationDbContext>(provider => provider.GetRequiredService<ApplicationDbContext>());

services.AddScoped<ApplicationDbContextInitialiser>();

#if (UseApiOnly)
services.AddAuthentication()
.AddBearerToken(IdentityConstants.BearerScheme);

services.AddAuthorizationBuilder();

services
.AddIdentityCore<ApplicationUser>()
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddApiEndpoints();
#else
services
.AddDefaultIdentity<ApplicationUser>()
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();
#endif

services.AddSingleton(TimeProvider.System);
services.AddTransient<IIdentityService, IdentityService>();

services.AddAuthorization(options =>
options.AddPolicy(Policies.CanPurge, policy => policy.RequireRole(Roles.Administrator)));

return services;
}
}
using CleanArchitecture.Application.Common.Interfaces;
using CleanArchitecture.Domain.Constants;
using CleanArchitecture.Infrastructure.Data;
using CleanArchitecture.Infrastructure.Data.Interceptors;
using CleanArchitecture.Infrastructure.Identity;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration;

namespace Microsoft.Extensions.DependencyInjection;

public static class DependencyInjection
{
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString("DefaultConnection");

Guard.Against.Null(connectionString, message: "Connection string 'DefaultConnection' not found.");

services.AddScoped<ISaveChangesInterceptor, AuditableEntityInterceptor>();
services.AddScoped<ISaveChangesInterceptor, DispatchDomainEventsInterceptor>();

services.AddDbContext<ApplicationDbContext>((sp, options) =>
{
options.AddInterceptors(sp.GetServices<ISaveChangesInterceptor>());
#if (UseSQLite)
options.UseSqlite(connectionString);
#else
options.UseSqlServer(connectionString);
#endif
});

services.AddScoped<IApplicationDbContext>(provider => provider.GetRequiredService<ApplicationDbContext>());

services.AddScoped<ApplicationDbContextInitialiser>();

#if (UseApiOnly)
services.AddAuthentication()
.AddBearerToken(IdentityConstants.BearerScheme);

services.AddAuthorizationBuilder();

services
.AddIdentityCore<ApplicationUser>()
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddApiEndpoints();
#else
services
.AddDefaultIdentity<ApplicationUser>()
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();
#endif

services.AddSingleton(TimeProvider.System);
services.AddTransient<IIdentityService, IdentityService>();

services.AddAuthorization(options =>
options.AddPolicy(Policies.CanPurge, policy => policy.RequireRole(Roles.Administrator)));

return services;
}
}

0 comments on commit bc4677a

Please sign in to comment.