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 new file mode 100644 index 0000000..11fc04c --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,40 @@ +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 + with: + fetch-depth: 0 + + - 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: Pack + 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/README.md b/README.md index 933f713..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. @@ -27,12 +30,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 +193,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/Crap4DotNet.Cli.csproj b/src/Crap4DotNet.Cli/Crap4DotNet.Cli.csproj index 4d57476..5f0eced 100644 --- a/src/Crap4DotNet.Cli/Crap4DotNet.Cli.csproj +++ b/src/Crap4DotNet.Cli/Crap4DotNet.Cli.csproj @@ -5,11 +5,14 @@ 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 MIT + https://github.com/7Factor/crap4dotnet + git + https://github.com/7Factor/crap4dotnet true dotnet-crap README.md @@ -24,6 +27,7 @@ + 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.