Skip to content

Commit

Permalink
init repo
Browse files Browse the repository at this point in the history
  • Loading branch information
dicko2 committed Nov 14, 2024
1 parent fd532d3 commit 00f51ee
Show file tree
Hide file tree
Showing 12 changed files with 606 additions and 2 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: .NET Core Build and Publish
on:
push:
env:
NETCORE_VERSION: '8.0'
GIT_REPO_ROOT: src
MAJOR_MINOR_VERSION: 1.0.
SOLUTION_FILE: CodeCompass.sln
DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX: 2
jobs:
build:
name: Build Package
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core SDK ${{ env.NETCORE_VERSION }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.NETCORE_VERSION }}
- name: Restore
working-directory: ${{ env.GIT_REPO_ROOT }}
run: dotnet restore ${{ env.SOLUTION_FILE }}
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1
- name: Build
working-directory: ${{ env.GIT_REPO_ROOT }}
run: dotnet build ${{ env.SOLUTION_FILE }} --configuration Release --no-restore

- name: Pack Release
if: github.ref == 'refs/heads/master'
working-directory: ${{ env.GIT_REPO_ROOT }}
run: |
dotnet pack Agoda.CodeCompass/Agoda.CodeCompass.csproj --configuration Release -o finalpackage --no-build -p:PackageVersion=${{ env.MAJOR_MINOR_VERSION }}${{ github.run_number }}
dotnet pack Agoda.CodeCompass.MSBuild/Agoda.CodeCompass.MSBuild.csproj --configuration Release -o finalpackage --no-build -p:PackageVersion=${{ env.MAJOR_MINOR_VERSION }}${{ github.run_number }}
- name: Pack Preview
if: github.ref != 'refs/heads/master'
working-directory: ${{ env.GIT_REPO_ROOT }}
run: |
dotnet pack Agoda.CodeCompass/Agoda.CodeCompass.csproj --configuration Release -o finalpackage --no-build -p:PackageVersion=${{ env.MAJOR_MINOR_VERSION }}${{ github.run_number }}-preview
dotnet pack Agoda.CodeCompass.MSBuild/Agoda.CodeCompass.MSBuild.csproj --configuration Release -o finalpackage --no-build -p:PackageVersion=${{ env.MAJOR_MINOR_VERSION }}${{ github.run_number }}-preview
- name: Publish artifact
uses: actions/upload-artifact@master
with:
name: nupkg
path: ${{ env.GIT_REPO_ROOT }}/finalpackage

deploy:
needs: build
name: Deploy Packages
runs-on: ubuntu-latest
steps:
- name: Download Package artifact
uses: actions/download-artifact@master
with:
name: nupkg
path: ./nupkg
- name: Setup NuGet
uses: NuGet/[email protected]
with:
nuget-api-key: ${{ secrets.NUGET_API_KEY }}
nuget-version: latest
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.NETCORE_VERSION }}

- name: Push to NuGet
run: dotnet nuget push nupkg/**/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://nuget.org --skip-duplicate

release:
needs: deploy
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- name: Create Draft Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.MAJOR_MINOR_VERSION }}${{ github.run_number }}
release_name: ${{ env.MAJOR_MINOR_VERSION }}${{ github.run_number }}
draft: true
prerelease: false
- uses: eregon/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ steps.create_release.outputs.id }}
26 changes: 26 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: .NET Core Build
on:
pull_request:
env:
NETCORE_VERSION: '8.0'
GIT_REPO_ROOT: src
SOLUTION_FILE: CodeCompass.sln
DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX: 2
jobs:
build:
name: Build Package
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core SDK ${{ env.NETCORE_VERSION }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.NETCORE_VERSION }}
- name: Restore
working-directory: ${{ env.GIT_REPO_ROOT }}
run: dotnet restore ${{ env.SOLUTION_FILE }}
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1
- name: Build
working-directory: ${{ env.GIT_REPO_ROOT }}
run: dotnet build ${{ env.SOLUTION_FILE }} --configuration Release --no-restore
159 changes: 157 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,157 @@
# code-compass-dotnet
CodeCompass .NET Library
# Agoda.CodeCompass 🧭

Because technical debt is like your laundry - it piles up when you're not looking.

## What is CodeCompass?

CodeCompass is a .NET analyzer that helps you navigate the treacherous waters of technical debt. It analyzes your code and produces standardized SARIF reports that quantify technical debt in terms of estimated remediation time, categorization, and priority.

Think of it as your code's financial advisor, but instead of telling you to stop buying avocado toast, it tells you to stop ignoring those nullable reference warnings.

## Installation

```bash
dotnet add package Agoda.CodeCompass
```

That's it! No complicated setup, no configuration files, no sacrificial offerings required.

## Features

- πŸ“Š Generates standardized SARIF reports
- ⏱️ Estimates remediation time for issues
- 🎯 Categorizes and prioritizes technical debt
- 🀝 Integrates seamlessly with existing .NET projects
- 🎨 Pretty colors in the SARIF viewer (okay, mostly different shades of blue)

## Example

Here's what CodeCompass will catch for you:

```csharp
public class UserService
{
// This will trigger AGD001: Unused parameter
public void UpdateUser(int userId, string name, string unusedParam)
{
Console.WriteLine($"Updating user {userId} to name {name}");
// unusedParam is sitting here like that gym membership you never use
}
}
```

The analyzer will generate a SARIF report that looks something like this:

```json
{
"runs": [{
"results": [{
"ruleId": "AGD001",
"message": {
"text": "Parameter 'unusedParam' is unused"
},
"properties": {
"techDebt": {
"minutes": 15,
"category": "CodeCleanup",
"priority": "Medium",
"rationale": "Unused parameters increase code complexity and maintenance burden",
"recommendation": "Remove the unused parameter or add a comment explaining why it's needed"
}
}
}]
}]
}
```

## Adding it to custom Rules

When calling `Diagnostic.Create` Method pass the additional paramter proeprties and populate the dictionary with the additional meta data.

```csharp
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class UnusedParameterAnalyzer : DiagnosticAnalyzer
{
public const string DiagnosticId = "AGD001";
private const string Category = "Usage";

private static readonly DiagnosticDescriptor Rule = new(
DiagnosticId,
title: "Unused parameter",
messageFormat: "Parameter '{0}' is unused",
category: Category,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: "Parameters that are not used in method bodies should be removed.",
helpLinkUri: "https://agoda.github.io/code-compass/rules/AGD001"
);

private void AnalyzeParameter(SyntaxNodeAnalysisContext context)
{
//...
if (!references.Any())
{
var diagnostic = Diagnostic.Create(
Rule,
parameter.GetLocation(),
properties: new Dictionary<string, string?>
{
["techDebtMinutes"] = "15",
["techDebtCategory"] = "CodeCleanup",
["techDebtPriority"] = "Medium",
["techDebtRationale"] = "Unused parameters increase code complexity and maintenance burden",
["techDebtRecommendation"] = "Remove the unused parameter or add a comment explaining why it's needed"
}.ToImmutableDictionary(),
parameter.Identifier.Text);

context.ReportDiagnostic(diagnostic);
}
}
}
```

## How It Works

1. Add the package to your project
2. Build your project
3. Look at the SARIF report
4. Feel slightly guilty about that code you wrote last Friday at 4:59 PM
5. Fix the issues
6. Repeat (because let's be honest, we all write Friday code sometimes)

## Analyzing the Results

The SARIF report can be viewed using:
- Visual Studio's built-in SARIF viewer
- VS Code with the SARIF Viewer extension
- Any text editor (if you really enjoy reading JSON)

## Contributing

We welcome contributions! Whether it's:
- πŸ› Bug fixes
- ✨ New analyzers
- πŸ“ Documentation improvements
- πŸ’‘ Feature suggestions
- πŸ€” Philosophical debates about whether that TODO comment from 2019 should be classified as technical debt

## License

MIT License - Feel free to use it, modify it, or talk about it at developer conferences.

## Acknowledgments

Special thanks to:
- The developers who write the code we analyze
- The maintainers who deal with the technical debt we find
- Coffee β˜•, without which this project wouldn't exist

## Questions?

Feel free to open an issue. We promise to read it, think about it, and maybe even fix it (no pinky promises though).

---

Made with πŸ’™ (and a bit of technical debt) by Agoda

Remember: Technical debt is like regular debt, except your bank account doesn't hate you for it - just your future self and your teammates.
25 changes: 25 additions & 0 deletions src/Agoda.CodeCompass.MSBuild/Agoda.CodeCompass.MSBuild.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<BuildOutputTargetFolder>tools</BuildOutputTargetFolder>
<DevelopmentDependency>true</DevelopmentDependency>
<NoPackageAnalysis>true</NoPackageAnalysis>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" Version="17.8.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.8.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Agoda.CodeCompass\Agoda.CodeCompass.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="build\*.props" Pack="true" PackagePath="build" />
<None Include="build\*.targets" Pack="true" PackagePath="build" />
</ItemGroup>
</Project>
Loading

0 comments on commit 00f51ee

Please sign in to comment.