From 3a1ec1b48fc39c536dda1c8e8fef5884bb4cf9ad Mon Sep 17 00:00:00 2001 From: Scott Pfister Date: Thu, 12 Mar 2026 18:28:58 -0500 Subject: [PATCH 1/4] ci: add NuGet publish workflow and repository metadata Add tag-triggered GitHub Actions workflow that builds, tests, and publishes to nuget.org on v* tags. Add RepositoryUrl, RepositoryType, and PackageProjectUrl to CLI .csproj for NuGet package metadata. Closes #1 Co-Authored-By: Claude Opus 4.6 --- .github/workflows/publish.yml | 42 ++++++++++++++++++++++ src/Crap4DotNet.Cli/Crap4DotNet.Cli.csproj | 3 ++ 2 files changed, 45 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..af6e752 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,42 @@ +name: Publish to NuGet + +on: + push: + tags: + - 'v*' + +permissions: + id-token: write + packages: write + contents: read + +jobs: + publish: + runs-on: ubuntu-latest + environment: nuget + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0' + + - name: Restore + run: dotnet restore + + - name: Build + run: dotnet build --no-restore + + - name: Test + run: dotnet test --no-build + + - name: Extract version from tag + id: version + run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" + + - name: Pack + run: dotnet pack src/Crap4DotNet.Cli -o ./nupkg /p:Version=${{ steps.version.outputs.VERSION }} + + - name: Push to NuGet + run: dotnet nuget push ./nupkg/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} diff --git a/src/Crap4DotNet.Cli/Crap4DotNet.Cli.csproj b/src/Crap4DotNet.Cli/Crap4DotNet.Cli.csproj index 4d57476..40fd378 100644 --- a/src/Crap4DotNet.Cli/Crap4DotNet.Cli.csproj +++ b/src/Crap4DotNet.Cli/Crap4DotNet.Cli.csproj @@ -10,6 +10,9 @@ CLI tool for computing CRAP (Change Risk Anti-Patterns) scores on .NET projects. Combines cyclomatic complexity with code coverage to identify risky, under-tested methods. crap;metrics;code-quality;complexity;coverage;dotnet-tool MIT + https://github.com/7Factor/crap4dotnet + git + https://github.com/7Factor/crap4dotnet true dotnet-crap README.md From e5580891eba6b02c48a4ab3aa08bffcbf3f26122 Mon Sep 17 00:00:00 2001 From: Scott Pfister Date: Thu, 12 Mar 2026 18:47:01 -0500 Subject: [PATCH 2/4] docs: fix README inaccuracies and broken links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix broken GitHub link in CLI README (7f → 7Factor) - Fix command name in CLI README (dotnet crap → dotnet-crap) - Fix CLI README usage examples to require --coverage or --run-tests - Update root README install section now that NuGet package exists - Replace placeholders with actual GitHub URL Co-Authored-By: Claude Opus 4.6 --- README.md | 8 ++------ src/Crap4DotNet.Cli/README.md | 14 +++++++------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 933f713..04890db 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,8 @@ Methods with a CRAP score above the threshold (default: 30) are **CRAPpy** — t ## Install -Not yet published to NuGet. Install from source: - ```bash -git clone && cd crap4dotnet -dotnet pack src/Crap4DotNet.Cli -o ./nupkg -dotnet tool install -g Crap4DotNet --add-source ./nupkg +dotnet tool install -g Crap4DotNet ``` Requires .NET 8.0 or later. @@ -194,7 +190,7 @@ Complexity analysis is purely syntactic (no semantic model needed), so the tool ## Building from Source ```bash -git clone +git clone https://github.com/7Factor/crap4dotnet.git cd crap4dotnet dotnet build dotnet test diff --git a/src/Crap4DotNet.Cli/README.md b/src/Crap4DotNet.Cli/README.md index 1ba7f9c..1c1134e 100644 --- a/src/Crap4DotNet.Cli/README.md +++ b/src/Crap4DotNet.Cli/README.md @@ -13,20 +13,20 @@ dotnet tool install -g Crap4DotNet ## Usage ```bash -# Analyze a project (auto-discovers coverage from TestResults) -dotnet crap analyze ./src/MyProject +# Run tests and analyze in one step +dotnet-crap analyze ./MyApp.sln --run-tests # Analyze with explicit coverage file -dotnet crap analyze ./src/MyProject --coverage ./TestResults/coverage.cobertura.xml +dotnet-crap analyze ./src/MyProject --coverage ./TestResults/coverage.cobertura.xml # Write report to file -dotnet crap analyze ./src/MyProject --output report.json +dotnet-crap analyze ./src/MyProject --coverage ./coverage.xml --output report.json # Custom threshold (default: 30) -dotnet crap analyze ./src/MyProject --threshold 15 +dotnet-crap analyze ./src/MyProject --coverage ./coverage.xml --threshold 15 # Compare two reports -dotnet crap diff before.json after.json +dotnet-crap diff before.json after.json ``` ## Exit Codes @@ -48,4 +48,4 @@ A method with complexity 20 and 10% coverage has a CRAP score of ~312 (terrible) ## JSON Output -The tool outputs a JSON report with method-level CRAP scores, statistics, severity bands, and a namespace hierarchy. See the [specification](https://github.com/7f/crap4dotnet) for the full schema. +The tool outputs a JSON report with method-level CRAP scores, statistics, severity bands, and a namespace hierarchy. See the [specification](https://github.com/7Factor/crap4dotnet) for the full schema. From c31b466f7cf5242471e15b4274dc4ea402197ce3 Mon Sep 17 00:00:00 2001 From: Scott Pfister Date: Thu, 12 Mar 2026 18:51:10 -0500 Subject: [PATCH 3/4] build: add MinVer for git-tag-based versioning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace hardcoded Version in .csproj with MinVer, which derives the package version from git tags (e.g. v0.1.0 → 0.1.0). Remove manual version extraction from publish workflow since MinVer handles it. Add fetch-depth: 0 to both CI and publish workflows so MinVer can read the full tag history. Co-Authored-By: Claude Opus 4.6 --- .github/workflows/ci.yml | 2 ++ .github/workflows/publish.yml | 8 +++----- Directory.Packages.props | 3 +++ src/Crap4DotNet.Cli/Crap4DotNet.Cli.csproj | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2ec758..f101af1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: actions/setup-dotnet@v4 with: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index af6e752..11fc04c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,6 +17,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: actions/setup-dotnet@v4 with: @@ -31,12 +33,8 @@ jobs: - name: Test run: dotnet test --no-build - - name: Extract version from tag - id: version - run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" - - name: Pack - run: dotnet pack src/Crap4DotNet.Cli -o ./nupkg /p:Version=${{ steps.version.outputs.VERSION }} + run: dotnet pack src/Crap4DotNet.Cli -o ./nupkg - name: Push to NuGet run: dotnet nuget push ./nupkg/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} diff --git a/Directory.Packages.props b/Directory.Packages.props index 71e9f54..9c0adb5 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,6 +10,9 @@ + + + diff --git a/src/Crap4DotNet.Cli/Crap4DotNet.Cli.csproj b/src/Crap4DotNet.Cli/Crap4DotNet.Cli.csproj index 40fd378..5f0eced 100644 --- a/src/Crap4DotNet.Cli/Crap4DotNet.Cli.csproj +++ b/src/Crap4DotNet.Cli/Crap4DotNet.Cli.csproj @@ -5,7 +5,7 @@ Crap4DotNet.Cli dotnet-crap Crap4DotNet - 0.1.0 + v 7f CLI tool for computing CRAP (Change Risk Anti-Patterns) scores on .NET projects. Combines cyclomatic complexity with code coverage to identify risky, under-tested methods. crap;metrics;code-quality;complexity;coverage;dotnet-tool @@ -27,6 +27,7 @@ + From dd928a6907806d0254088d03f2f3a5588b86963f Mon Sep 17 00:00:00 2001 From: Scott Pfister Date: Thu, 12 Mar 2026 18:58:14 -0500 Subject: [PATCH 4/4] docs: add NuGet and CI status badges to README Co-Authored-By: Claude Opus 4.6 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 04890db..e0e358f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # crap4dotnet +[![NuGet](https://img.shields.io/nuget/v/Crap4DotNet)](https://www.nuget.org/packages/Crap4DotNet) +[![CI](https://github.com/7Factor/crap4dotnet/actions/workflows/ci.yml/badge.svg)](https://github.com/7Factor/crap4dotnet/actions/workflows/ci.yml) + A .NET global tool that computes **CRAP (Change Risk Anti-Patterns)** scores for your C# code. CRAP combines cyclomatic complexity with code coverage to identify methods that are both complex and poorly tested — the riskiest code in your project. Designed for **AI agent consumption**: JSON to stdout, structured errors to stderr, meaningful exit codes.