diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..58d0ba6 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,11 @@ +changelog: + categories: + - title: Changes + labels: + - "*" + exclude: + labels: + - dependencies + - title: Dependencies + labels: + - dependencies diff --git a/.github/workflows/build-pipeline.yml b/.github/workflows/build-pipeline.yml index 32581e3..71cd8f8 100644 --- a/.github/workflows/build-pipeline.yml +++ b/.github/workflows/build-pipeline.yml @@ -26,6 +26,7 @@ jobs: outputs: name: ${{ steps.initialize.outputs.name }} docker_tag: ${{ steps.initialize.outputs.docker_tag }} + version: ${{ steps.initialize.outputs.version }} steps: - name: Checkout @@ -60,6 +61,7 @@ jobs: echo "version_prefix=$(eval printf "%s" "$VERSION_PREFIX")" >> $GITHUB_OUTPUT echo "version_suffix=$(eval printf "%s" "$VERSION_SUFFIX")" >> $GITHUB_OUTPUT echo "docker_tag=$(eval printf "%s" "$DOCKER_TAG")" >> $GITHUB_OUTPUT + echo "version=$(eval printf "%s" "$DOCKER_TAG")" >> $GITHUB_OUTPUT echo "branch=$(eval printf "%s" "$BRANCH_CURRENT")" >> $GITHUB_OUTPUT shell: bash @@ -111,6 +113,22 @@ jobs: SUFFIX: ${{ steps.initialize.outputs.version_suffix }} shell: bash + - name: Verify Template + id: verify-template + run: | + SIZE=$(stat --format=%s packages/*.nupkg) + echo "Template package is $SIZE bytes" + if [ "$SIZE" -gt "$MAX_SIZE" ]; then + echo "::error::Template package is larger than $MAX_SIZE bytes" + exit 1 + fi + dotnet new install packages/*.nupkg + dotnet new $(jq -r .shortName .template.config/template.json) --name Template.Verification --output verification + dotnet build verification --configuration Release + env: + MAX_SIZE: 1048576 + shell: bash + - name: Upload Coverage id: upload-coverage uses: actions/upload-artifact@v7 @@ -282,16 +300,10 @@ jobs: needs: [build, coverage, scan, analysis] if: ${{ github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }} permissions: - contents: read + contents: write id-token: write steps: - - name: Download Image - id: download-image - uses: actions/download-artifact@v8 - with: - name: image - - name: Download Template id: download-template uses: actions/download-artifact@v8 @@ -299,23 +311,6 @@ jobs: name: template path: packages - - name: Load Image - id: load - run: docker load --input image.tar - - - name: Docker Login - id: docker-login - uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0 - with: - username: ${{ secrets.DOCKER_LOGIN }} - password: ${{ secrets.DOCKER_TOKEN }} - - - name: Docker Push - id: docker-push - run: docker push $NAME --all-tags - env: - NAME: ${{ needs.build.outputs.name }} - - name: Login to NuGet id: nuget-login uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2.0 @@ -324,4 +319,11 @@ jobs: - name: NuGet Push id: nuget-push - run: dotnet nuget push packages/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }} + run: dotnet nuget push packages/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }} --skip-duplicate + + - name: GitHub Release + id: github-release + run: gh release create "$VERSION" packages/*.nupkg --repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA" --title "$VERSION" --generate-notes + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ needs.build.outputs.version }} diff --git a/.template_config/template.json b/.template.config/template.json similarity index 97% rename from .template_config/template.json rename to .template.config/template.json index 6435af2..5c8f178 100644 --- a/.template_config/template.json +++ b/.template.config/template.json @@ -20,7 +20,7 @@ "sourceName": "CleanModelContextProtocol", "preferNameDirectory": true, "symbols": { - "author": { + "authorName": { "type": "parameter", "displayName": "The name of the author of the solution.", "defaultValue": "Stephen Walsh", diff --git a/NUGET.md b/NUGET.md index 8d4feb1..8b0f1fd 100644 --- a/NUGET.md +++ b/NUGET.md @@ -13,7 +13,7 @@ dotnet new install CleanModelContextProtocol.Template ## Usage ``` bash -dotnet new cleanmodelcontextprotocol --name {YOUR_SOLUTION_NAMESPACE} --author "{YOUR_NAME}" +dotnet new cleanmodelcontextprotocol --name {YOUR_SOLUTION_NAMESPACE} --authorName "{YOUR_NAME}" ``` ## Documentation diff --git a/README.md b/README.md index b522130..dbbbd59 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ dotnet new install CleanModelContextProtocol.Template ### Create a solution ``` bash -dotnet new cleanmodelcontextprotocol --name {YOUR_SOLUTION_NAMESPACE} --author "{YOUR_NAME}" +dotnet new cleanmodelcontextprotocol --name {YOUR_SOLUTION_NAMESPACE} --authorName "{YOUR_NAME}" ``` ## Running the project @@ -57,12 +57,6 @@ The `Dockerfile` has stages for testing, publishing and running, so you can buil docker build . --target run --tag cleanmodelcontextprotocol:latest --build-arg VERSION_PREFIX={VERSION_NUMBER} --build-arg VERSION_SUFFIX={PRERELEASE_NAME} ``` -Every push to `main` publishes an image to Docker Hub. - -``` bash -docker pull stphnwlsh/cleanmodelcontextprotocol -``` - ## Architecture This solution is loosely based on Clean Architecture. It's by no means perfect, so I prefer to call it "Lean Mean Clean Architecture". Inspiration comes from [Jason Taylor's Clean Architecture Template](https://github.com/jasontaylordev/CleanArchitecture), with some ideas taken further and others scaled back. @@ -88,7 +82,7 @@ The one deliberate break from Clean Architecture is that the Presentation projec - Object mapping using [Mapperly](https://mapperly.riok.app) - In-memory data using [Entity Framework Core](https://learn.microsoft.com/ef/core/providers/in-memory/) seeded with [Bogus](https://github.com/bchavez/Bogus) - Testing using [xUnit](https://xunit.net), [Shouldly](https://github.com/shouldly/shouldly) and [NSubstitute](https://github.com/nsubstitute/NSubstitute), with coverage from [Coverlet](https://github.com/coverlet-coverage/coverlet) -- CI with GitHub Actions: build and test, 95% coverage gate, [Trivy](https://trivy.dev) container scan, [CodeQL](https://codeql.github.com) static analysis, then Docker Hub and NuGet publishing from `main` using [trusted publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing) +- CI with GitHub Actions: build and test, 95% coverage gate, [Trivy](https://trivy.dev) container scan, [CodeQL](https://codeql.github.com) static analysis, then NuGet publishing and a GitHub release from `main` using [trusted publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing) - Monthly grouped dependency updates using [Dependabot](https://docs.github.com/code-security/dependabot) ## Related templates diff --git a/template/template.csproj b/template/template.csproj index d2c0983..32da234 100644 --- a/template/template.csproj +++ b/template/template.csproj @@ -14,17 +14,24 @@ docs/LICENSE.md docs/NUGET.md images/icon.png - true + https://github.com/stphnwlsh/CleanModelContextProtocol/releases false - content $(NoWarn);NU5128;NU5118 true false false + + ../**/bin/**;../**/obj/**;../**/TestResults/**;../**/*.user;../**/.DS_Store + + - + + + + + diff --git a/tests/Presentation.Tests.Integration/CleanModelContextProtocolApplication.cs b/tests/Presentation.Tests.Integration/ModelContextProtocolApplication.cs similarity index 72% rename from tests/Presentation.Tests.Integration/CleanModelContextProtocolApplication.cs rename to tests/Presentation.Tests.Integration/ModelContextProtocolApplication.cs index f11cadd..b312831 100644 --- a/tests/Presentation.Tests.Integration/CleanModelContextProtocolApplication.cs +++ b/tests/Presentation.Tests.Integration/ModelContextProtocolApplication.cs @@ -3,7 +3,7 @@ namespace CleanModelContextProtocol.Presentation.Tests.Integration; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.Hosting; -internal sealed class CleanModelContextProtocolApplication(string environment = "local") : WebApplicationFactory +internal sealed class ModelContextProtocolApplication(string environment = "local") : WebApplicationFactory { protected override IHost CreateHost(IHostBuilder builder) { diff --git a/tests/Presentation.Tests.Integration/Tools/BaseToolTests.cs b/tests/Presentation.Tests.Integration/Tools/BaseToolTests.cs index bcebd96..e1d54cf 100644 --- a/tests/Presentation.Tests.Integration/Tools/BaseToolTests.cs +++ b/tests/Presentation.Tests.Integration/Tools/BaseToolTests.cs @@ -7,7 +7,7 @@ namespace CleanModelContextProtocol.Presentation.Tests.Integration; public abstract class BaseToolTests : IAsyncLifetime, IAsyncDisposable { #pragma warning disable CS8618 - private CleanModelContextProtocolApplication application; + private ModelContextProtocolApplication application; private bool disposed; protected McpClient Client { get; private set; } @@ -15,7 +15,7 @@ public abstract class BaseToolTests : IAsyncLifetime, IAsyncDisposable public async Task InitializeAsync() { - this.application = new CleanModelContextProtocolApplication(); + this.application = new ModelContextProtocolApplication(); this.Client = await McpClient.CreateAsync( new HttpClientTransport( new HttpClientTransportOptions { Endpoint = new Uri("http://localhost/mcp") },