Skip to content

Feature/rename project #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -e -B sonar:sonar -Dsonar.projectKey=green-code-initiative_ecoCode-csharp-sonarqube -Pcode-analysis
run: mvn -e -B sonar:sonar -Dsonar.projectKey=green-code-initiative_creedengo-csharp-sonarqube -Pcode-analysis
4 changes: 2 additions & 2 deletions .github/workflows/build_container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ on:

env:
# github.repository as <account>/<repo>
IMAGE_NAME: sonarqube-ecocode-csharp
IMAGE_NAME: sonarqube-creedengo-csharp
IMAGES: |
ghcr.io/${{ github.repository_owner }}/sonarqube-ecocode-csharp
ghcr.io/${{ github.repository_owner }}/sonarqube-creedengo-csharp

jobs:
Build:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tag_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
id: export_jar_files
uses: actions/upload-artifact@v4
with:
name: ecocode-plugins
name: creedengo-plugins
path: target
overwrite: true
- name: Export UPLOAD_URL
Expand All @@ -61,7 +61,7 @@ jobs:
id: import_jar_files
uses: actions/download-artifact@v4
with:
name: ecocode-plugins
name: creedengo-plugins
path: target
- name: Upload Release Asset - C# Plugin
id: upload-release-asset
Expand All @@ -70,6 +70,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{needs.build.outputs.upload_url}}
asset_path: target/ecocode-csharp-plugin-${{ github.ref_name }}.jar
asset_name: ecocode-csharp-plugin-${{ github.ref_name }}.jar
asset_path: target/creedengo-csharp-plugin-${{ github.ref_name }}.jar
asset_name: creedengo-csharp-plugin-${{ github.ref_name }}.jar
asset_content_type: application/zip
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Deleted

## [2.1.0] - 2025-02-17

### Changed

- First official release of creedengo-csharp-sonarqube plugin (renaming ECxx rule ids to GCIxx rule ids)
- Update creedengo-rules-specifications to 2.2.1
- Update nuget package Creedengo to 2.1.0

## [1.5.1] - 2024-11-01

### Changed
Expand All @@ -28,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Depend on ecocode-rules-specifications v1.5.4
- Depend on nuget package EcoCode v1.1.0

[unreleased](https://github.com/green-code-initiative/ecoCode-csharp-sonarqube/compare/1.5.1...HEAD)
[1.5.1](https://github.com/green-code-initiative/ecoCode-csharp-sonarqube/compare/1.1.0...1.5.1)
[1.1.0](https://github.com/green-code-initiative/ecoCode-csharp-sonarqube/releases/tag/1.1.0)
[unreleased](https://github.com/green-code-initiative/creedengo-csharp-sonarqube/compare/2.1.0...HEAD)
[2.1.0](https://github.com/green-code-initiative/creedengo-csharp-sonarqube/compare/1.5.1...2.1.0)
[1.5.1](https://github.com/green-code-initiative/creedengo-csharp-sonarqube/compare/1.1.0...1.5.1)
[1.1.0](https://github.com/green-code-initiative/creedengo-csharp-sonarqube/releases/tag/1.1.0)
2 changes: 1 addition & 1 deletion CODE_STYLE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Code Style

Please read common [CODE_STYLE.md](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/CODE_STYLE.md) in `ecoCode-common` repository.
Please read common [CODE_STYLE.md](https://github.com/green-code-initiative/creedengo-common/blob/main/doc/CODE_STYLE.md) in `creedengo-common` repository.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Contributing

Please read common [CONTRIBUTING.md](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/CONTRIBUTING.md) in `ecoCode-common` repository.
Please read common [CONTRIBUTING.md](https://github.com/green-code-initiative/creedengo-common/blob/main/doc/CONTRIBUTING.md) in `creedengo-common` repository.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ ARG SONARQUBE_VERSION=9.9-community

FROM maven:${MAVEN_BUILDER} AS builder

WORKDIR /usr/src/ecocode
WORKDIR /usr/src/creedengo
COPY src src/
COPY pom.xml tool_build.sh ./

RUN ./tool_build.sh

FROM sonarqube:${SONARQUBE_VERSION}
COPY --from=builder /usr/src/ecocode/target/ecocode-*.jar /opt/sonarqube/extensions/plugins/
COPY --from=builder /usr/src/creedengo/target/creedengo-*.jar /opt/sonarqube/extensions/plugins/
USER sonarqube
53 changes: 27 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
EcoCode C#
Creedengo C#
===========

_ecoCode_ is a collective project aiming to reduce environmental footprint of software at the code level. The goal of
_creedengo_ is a collective project aiming to reduce environmental footprint of software at the code level. The goal of
the project is to provide a list of static code analyzers to highlight code structures that may have a negative
ecological impact: energy and resources over-consumption, "fatware", shortening terminals' lifespan, etc.

_ecoCode_ is based on evolving catalogs
of [good practices](https://github.com/green-code-initiative/ecoCode/blob/main/docs/rules), for various technologies.
_creedengo_ is based on evolving catalogs
of [good practices](https://github.com/green-code-initiative/creedengo-rules-specifications/tree/main/docs/rules), for various technologies.
This SonarQube plugin then implements these catalogs as rules for scanning your C# projects.

This SonarQube plugin is based on a generated plugin from [SonarSource Sonarqube Roslyn SDK](https://github.com/SonarSource/sonarqube-roslyn-sdk) with a slightly different rules import process.

The _EcoCode C# Sonarqube plugin_ relies on the [EcoCode nuget package](https://www.nuget.org/packages/EcoCode) that is responsible of the codebase analysing part. You can then track detected issues within a compatible Sonarqube instance.
The _Creedengo C# Sonarqube plugin_ relies on the [Creedengo nuget package](https://www.nuget.org/packages/Creedengo) that is responsible of the codebase analysing part. You can then track detected issues within a compatible Sonarqube instance.

> ⚠️ This is still a very early stage project. Any feedback or contribution will be highly appreciated. Please
> refer to the contribution section.

[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/CODE_OF_CONDUCT.md)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://github.com/green-code-initiative/creedengo-common/blob/main/doc/CODE_OF_CONDUCT.md)

🌿 SonarQube Plugins
-------------------

This plugin is part of the ecoCode project.\
This plugin is part of the creedengo project.\
You can find a list of all our other plugins in
the [ecoCode repository](https://github.com/green-code-initiative/ecoCode#-sonarqube-plugins)
the [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-sonarqube-plugins)

🚀 Getting Started
------------------
Expand All @@ -34,67 +34,68 @@ You can give a try with a one command docker :
```sh
docker run -ti --rm \
-p 9000:9000 \
--name sonarqube-ecocode-csharp ghcr.io/green-code-initiative/sonarqube-ecocode-csharp:latest
--name sonarqube-creedengo-csharp ghcr.io/green-code-initiative/sonarqube-creedengo-csharp:latest
```

or (with logs and data locally stored) :

```sh
docker run -ti --rm \
-v sq_ecocode_logs:/opt/sonarqube/logs \
-v sq_ecocode_data:/opt/sonarqube/data \
-v sq_creedengo_logs:/opt/sonarqube/logs \
-v sq_creedengo_data:/opt/sonarqube/data \
-p 9000:9000 \
--name sonarqube-ecocode-csharp ghcr.io/green-code-initiative/sonarqube-ecocode-csharp:latest
--name sonarqube-creedengo-csharp ghcr.io/green-code-initiative/sonarqube-creedengo-csharp:latest
```

... and configure local SonarQube (security config and quality profile : see [configuration](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md#configuration-sonarqube) for more details).
... and configure local SonarQube (security config and quality profile : see [configuration](https://github.com/green-code-initiative/creedengo-common/blob/main/doc/HOWTO.md#installing-local-environment-local-sonarqube) for more details).

To install other `ecocode` plugins, you can also :
To install other `creedengo` plugins, you can also :

- download each plugin separatly and copy the plugin (jar file) to `$SONAR_INSTALL_DIR/extensions/plugins` and restart SonarQube.
- install different ecocode plugins with Marketplace (inside admin panel of SonarQube)
- install different creedengo plugins with Marketplace (inside admin panel of SonarQube)

Then you can use C# test project repository to test the environment : see README.md of [C# test project](https://github.com/green-code-initiative/ecoCode-csharp-test-project)
Then you can use C# test project repository to test the environment : see README.md of [C# test project](https://github.com/green-code-initiative/creedengo-csharp-test-project)

To analyze a .net codebase without having to install required components (i.e. .net SDK, JDK/JRE, etc.), you can use our [docker dotnetscan wrapper](./docker-dotnetscan/README.md).

Finally, you can directly use a [all-in-one docker-compose](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md#start-sonarqube-if-first-time)
Finally, you can directly use a [all-in-one docker-compose](https://github.com/green-code-initiative/creedengo-common/blob/main/doc/HOWTO.md#installing-local-environment-local-sonarqube)

By default, `Dockerfile` use the official [Sonarqube LTS Community](https://hub.docker.com/_/sonarqube) image version.
You can override this behaviour and use a custom version of your choice by specifying a `build-arg` to the build command, for example :

```sh
docker build --build-arg SONARQUBE_VERSION=10.5.1-community .
docker build --build-arg SONARQUBE_VERSION=25.2.0.102705-community .
```

If you want to use the `docker-compose` file, you can use the below commands to use an overriding `dockerfile` build :
If you want to use the `docker-compose` file, you can use the below commands to use an overrided `dockerfile` build :

```sh
docker compose build --build-arg SONARQUBE_VERSION=10.5.1-community
docker compose build --build-arg SONARQUBE_VERSION=25.2.0.102705-community
docker compose up -d --no-build
```

🛒 Distribution
------------------

Ready to use binaries are available [from GitHub](https://github.com/green-code-initiative/ecoCode-csharp-sonarqube/releases).
Ready to use binaries are available [from GitHub](https://github.com/green-code-initiative/creedengo-csharp-sonarqube/releases).

🧩 Compatibility
-----------------

| Plugin version | SonarQube version | EcoCode nuget package version |
| -------------- | ------------------- | ----------------------------- |
| 1.1.0+ | 9.9.+ LTS to 10.5.1 | 1.1.0 |
| Plugin version | SonarQube version | creedengo nuget package version |
| -------------- | ------------------- | ------------------------------- |
| 1.1.0+ | 9.9.+ LTS to 10.5.1 | 1.1.0 |
| 2.1.0+ | 9.9.+ LTS and above | 2.1.0 |

🤝 Contribution
---------------

check [ecoCode repository](https://github.com/green-code-initiative/ecoCode#-contribution)
check [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-contribution)

🤓 Main contributors
--------------------

check [ecoCode repository](https://github.com/green-code-initiative/ecoCode#-main-contributors)
check [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-main-contributors)

Links
-----
Expand Down
2 changes: 1 addition & 1 deletion RULES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Rules
===========

Please read [RULES.md](https://github.com/green-code-initiative/ecoCode/blob/main/RULES.md) in `ecoCode` repository.
Please read [RULES.md](https://github.com/green-code-initiative/creedengo-rules-specifications/blob/main/RULES.md) in `creedengo-rules-specification` repository.
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
name: sonarqube_ecocode_csharp
name: sonarqube_creedengo_csharp

services:
sonar:
build: .
container_name: sonar_ecocode_csharp
container_name: sonar_creedengo_csharp
ports:
- "9000:9000"
networks:
Expand All @@ -29,7 +29,7 @@ services:

db:
image: postgres:12
container_name: postgresql_ecocode_csharp
container_name: postgresql_creedengo_csharp
networks:
- sonarnet
volumes:
Expand Down
4 changes: 3 additions & 1 deletion docker-dotnetscan/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# syntax=docker/dockerfile:1.0

FROM mcr.microsoft.com/dotnet/sdk:8.0
ARG DOTNET_SDK=9.0

FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_SDK}

RUN dotnet tool install --global dotnet-sonarscanner
RUN set -ex; \
Expand Down
33 changes: 22 additions & 11 deletions docker-dotnetscan/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.net analysis docker utility container
===========
# .net analysis docker utility container

Docker utility container for dotnet codebase analysis that can be use to scan .net code and upload result to a Sonarqube instance.
This container is intended to be used as a standalone tool with the docker-compose configuration provided in this repo that starts a Sonarqube instance or an existing Sonarqube instance.
Expand All @@ -15,35 +14,47 @@ Build the docker image and tag it with a convenient name (for instance we named
docker build -t scanner .
```

### Use a specific .Net SDK version

By default building docker image will use `.Net SDK 9.0`. You can use a version that will suit you usecase by specifying the version you want to use with a `build-arg` :

```sh
docker build -t scanner --build-arg DOTNET_SDK=8.0 .
```

Obviously, you can tag your image using `-t scanner:8.0` for example and adapt below analysing commands accordingly.

### Analyze your code

#### Prerequisites

You need to have an up and running Sonarqube instance with :
- the EcoCode CSharp plugin installed
- Quality profile with EcoCode rules activated

- the creedengo CSharp plugin installed
- Quality profile with creedengo rules activated
- An user token, global or project analysis token, cf. Sonarqube documentation : [Generating and using tokens](https://docs.sonarsource.com/sonarqube/latest/user-guide/user-account/generating-and-using-tokens/)

The following samples commands are based on these assumptions :

| Property | Parameter | Value | Comments |
| ------------- | --------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| Project key | -p | `myDotNetProject` | Project will be create automatically if you use a user token (i.e. `-l`) that is allowed to create one (i.e. admin rights) |
| Auth token | -l | `squ_123456789` | User token are `squ_XXXX`, projet analysis token are `sqp_XXXX` |
| Sonarqube url | -u | `http://localhost:9000` | Note : this is the default url if you omit to specify one with `-u` parameter |
| Property | Parameter | Value | Comments |
| ------------------------- | --------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| Project key | -p | `myDotNetProject` | Project will be create automatically if you use a user token (i.e. `-l`) that is allowed to create one (i.e. admin rights) |
| User auth token | -l | `squ_123456789` | User token are `squ_XXXX`. [_Deprecated by Sonarqube and will be remove in the future, use -t instead_] |
| Global/Project auth token | -t | `sqp_123456789` | Global or projet analysis token are `sqp_XXXX` |
| Sonarqube url | -u | `http://localhost:9000` | Note : this is the default url if you omit to specify one with `-u` parameter |

Running a SonarQube analysis is straighforward. You just need to execute the following commands at **the root of your solution**.

#### With a Sonarqube instance from our docker-compose

```sh
docker run --rm -it --mount type=bind,src="$(pwd)",target=/src --network sonarnet scanner -p myDotNetProject -u http://sonar:9000 -l squ_123456789
docker run --rm -it --mount type=bind,src="$(pwd)",target=/src --network sonarnet scanner -p myDotNetProject -u http://sonar:9000 -t sqp_123456789
```

#### With an existing Sonarqube instance

```sh
docker run --rm -it --mount type=bind,src="$(pwd)",target=/src --network host scanner -p myDotNetProject -u http://localhost:9000 -l squ_123456789
docker run --rm -it --mount type=bind,src="$(pwd)",target=/src --network host scanner -p myDotNetProject -u http://localhost:9000 -t sqp_123456789
```

For further available parameters, refer to Help
Expand Down
4 changes: 2 additions & 2 deletions docker-dotnetscan/docker_dotnetscan_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ get_help_scanning_options() {
echo -e "\t-t|--token\tSonarqube global or project analysis auth token."
echo -e "or\t-l|--login\tSonarqube user auth token.\n"
echo "Optional:"
echo -e "\t-p|--project\tProject key (default: ecoCode-csharp-test-project)"
echo -e "\t-p|--project\tProject key (default: creedengo-csharp-test-project)"
echo -e "\t-u|--url\tUrl to Sonarqube instance (default: http://localhost:9000)"
echo -e "\t-h|--help\tPrint this help\n"
echo "Arguments:"
Expand Down Expand Up @@ -85,7 +85,7 @@ if [[ "$1" == '--' ]]; then shift; fi
CMD_ARGS=$@

# Get passed args value or set to default value
PROJECT_KEY=${project:=ecoCode-csharp-test-project}
PROJECT_KEY=${project:=creedengo-csharp-test-project}
SONAR_HOST=${url:=http://localhost:9000}
if [[ -z $CMD_ARGS ]]; then
DOTNET_ARGS="build"
Expand Down
Loading