From 610910fbbe7ede0a0447ddfe1bbfdefde0c912a9 Mon Sep 17 00:00:00 2001 From: Christophe Havard Date: Thu, 3 Dec 2020 16:43:40 +0000 Subject: [PATCH 01/18] Helper.cs edited online with Bitbucket --- Helper.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Helper.cs b/Helper.cs index 74a50b5..ce9b97d 100644 --- a/Helper.cs +++ b/Helper.cs @@ -20,9 +20,9 @@ private static string GetKeyVaultConnectionString(string secretName) } public static string GetConnectionString() { - // if (Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT") != "Local") - // return GetKeyVaultConnectionString("db-plastico-dev-connectionstring"); - // else + if (Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT") != "Local") + return GetKeyVaultConnectionString("db-plastico-dev-connectionstring"); + else return Environment.GetEnvironmentVariable("postgre_connection"); } // I add another useless code line From c40e6a57ac222ae5f072e0f0e101b07697a10820 Mon Sep 17 00:00:00 2001 From: Christophe Havard Date: Thu, 3 Dec 2020 16:50:01 +0000 Subject: [PATCH 02/18] added variable --- bitbucket-pipelines.yml | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index ce3783b..c80b021 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -5,20 +5,25 @@ image: mcr.microsoft.com/dotnet/core/sdk:3.1 +definitions: + - step: &build-test-sonarcloud + name: Build and Test + caches: + - dotnetcore + script: + - apt-get update + - apt-get install --yes openjdk-11-jre + - dotnet tool install --global dotnet-sonarscanner + - export PATH="$PATH:/root/.dotnet/tools" + - dotnet sonarscanner begin /k:"christophe-havard-sonarsource_my_dotnetcore_project" /d:"sonar.login=${SONAR_TOKEN}" /o:"christophe-havard-sonarsource-1" /v:"${BITBUCKET_COMMIT}" /d:"sonar.host.url=https://sonarcloud.io" + - REPORTS_PATH=./test-reports/build_${BITBUCKET_BUILD_NUMBER} + - dotnet restore + - dotnet build --no-restore --configuration Release + - dotnet test --no-build --configuration Release --test-adapter-path:. --logger:"junit;LogFilePath=$REPORTS_PATH/junit.xml" + - dotnet sonarscanner end /d:"sonar.login=${SONAR_TOKEN}" pipelines: default: - - step: - name: Build and Test - caches: - - dotnetcore - script: - - apt-get update - - apt-get install --yes openjdk-11-jre - - dotnet tool install --global dotnet-sonarscanner - - export PATH="$PATH:/root/.dotnet/tools" - - dotnet sonarscanner begin /k:"christophe-havard-sonarsource_my_dotnetcore_project" /d:"sonar.login=${SONAR_TOKEN}" /o:"christophe-havard-sonarsource-1" /v:"${BITBUCKET_COMMIT}" /d:"sonar.host.url=https://sonarcloud.io" - - REPORTS_PATH=./test-reports/build_${BITBUCKET_BUILD_NUMBER} - - dotnet restore - - dotnet build --no-restore --configuration Release - - dotnet test --no-build --configuration Release --test-adapter-path:. --logger:"junit;LogFilePath=$REPORTS_PATH/junit.xml" - - dotnet sonarscanner end /d:"sonar.login=${SONAR_TOKEN}" \ No newline at end of file + - step: *build-test-sonarcloud + pull-requests: + '**': + - step: *build-test-sonarcloud \ No newline at end of file From a57487873a3d766b32e55eddb7630fab7797631e Mon Sep 17 00:00:00 2001 From: Christophe Havard Date: Fri, 4 Dec 2020 08:26:06 +0000 Subject: [PATCH 03/18] bitbucket-pipelines.yml edited online with Bitbucket --- bitbucket-pipelines.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index c80b021..8b2a88f 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -6,7 +6,8 @@ image: mcr.microsoft.com/dotnet/core/sdk:3.1 definitions: - - step: &build-test-sonarcloud + steps: + - step: &build-test-sonarcloud name: Build and Test caches: - dotnetcore From e51e27166212a05d3b2e071a417038d9a5c5dc6c Mon Sep 17 00:00:00 2001 From: Christophe Havard Date: Fri, 4 Dec 2020 08:29:15 +0000 Subject: [PATCH 04/18] bitbucket-pipelines.yml edited online with Bitbucket --- bitbucket-pipelines.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 8b2a88f..81398bf 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -6,11 +6,14 @@ image: mcr.microsoft.com/dotnet/core/sdk:3.1 definitions: + caches: + sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build steps: - step: &build-test-sonarcloud name: Build and Test caches: - - dotnetcore + - dotnetcore + - sonar script: - apt-get update - apt-get install --yes openjdk-11-jre From 293e68b25497d9653018074ec68a17b23579b25f Mon Sep 17 00:00:00 2001 From: Christophe Havard Date: Fri, 4 Dec 2020 09:34:41 +0100 Subject: [PATCH 05/18] indentation --- bitbucket-pipelines.yml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 81398bf..4986604 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -10,21 +10,21 @@ definitions: sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build steps: - step: &build-test-sonarcloud - name: Build and Test - caches: - - dotnetcore - - sonar - script: - - apt-get update - - apt-get install --yes openjdk-11-jre - - dotnet tool install --global dotnet-sonarscanner - - export PATH="$PATH:/root/.dotnet/tools" - - dotnet sonarscanner begin /k:"christophe-havard-sonarsource_my_dotnetcore_project" /d:"sonar.login=${SONAR_TOKEN}" /o:"christophe-havard-sonarsource-1" /v:"${BITBUCKET_COMMIT}" /d:"sonar.host.url=https://sonarcloud.io" - - REPORTS_PATH=./test-reports/build_${BITBUCKET_BUILD_NUMBER} - - dotnet restore - - dotnet build --no-restore --configuration Release - - dotnet test --no-build --configuration Release --test-adapter-path:. --logger:"junit;LogFilePath=$REPORTS_PATH/junit.xml" - - dotnet sonarscanner end /d:"sonar.login=${SONAR_TOKEN}" + name: Build and Test + caches: + - dotnetcore + - sonar + script: + - apt-get update + - apt-get install --yes openjdk-11-jre + - dotnet tool install --global dotnet-sonarscanner + - export PATH="$PATH:/root/.dotnet/tools" + - dotnet sonarscanner begin /k:"christophe-havard-sonarsource_my_dotnetcore_project" /d:"sonar.login=${SONAR_TOKEN}" /o:"christophe-havard-sonarsource-1" /v:"${BITBUCKET_COMMIT}" /d:"sonar.host.url=https://sonarcloud.io" + - REPORTS_PATH=./test-reports/build_${BITBUCKET_BUILD_NUMBER} + - dotnet restore + - dotnet build --no-restore --configuration Release + - dotnet test --no-build --configuration Release --test-adapter-path:. --logger:"junit;LogFilePath=$REPORTS_PATH/junit.xml" + - dotnet sonarscanner end /d:"sonar.login=${SONAR_TOKEN}" pipelines: default: - step: *build-test-sonarcloud From fc4972857b9b290d5297f0c0c6535fec6c20e48b Mon Sep 17 00:00:00 2001 From: Christophe Havard Date: Fri, 4 Dec 2020 10:08:47 +0100 Subject: [PATCH 06/18] added getSecret --- Helper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Helper.cs b/Helper.cs index ce9b97d..f4f3e7e 100644 --- a/Helper.cs +++ b/Helper.cs @@ -27,7 +27,7 @@ public static string GetConnectionString() } // I add another useless code line public static void DoNothing(){ - Environment.GetEnvironmentVariable("postgre_connection"); + Environment.GetSecret(); } } } \ No newline at end of file From dcca6edadaf6d1c61e3d0f0971499b5a70634e45 Mon Sep 17 00:00:00 2001 From: Christophe Havard Date: Fri, 4 Dec 2020 10:15:53 +0100 Subject: [PATCH 07/18] ouch --- Helper.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Helper.cs b/Helper.cs index f4f3e7e..7e1a86b 100644 --- a/Helper.cs +++ b/Helper.cs @@ -27,7 +27,11 @@ public static string GetConnectionString() } // I add another useless code line public static void DoNothing(){ - Environment.GetSecret(); + Environment.GetEnvironmentVariable("postgre_connection"); + int i = 0; + while(i< 100){ + // toto + } } } } \ No newline at end of file From 4f0d35d29fe4e0ee5543856db37964c6e4afcc3d Mon Sep 17 00:00:00 2001 From: Christophe Havard Date: Fri, 4 Dec 2020 11:08:39 +0100 Subject: [PATCH 08/18] added recursion to fail QG --- Helper.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Helper.cs b/Helper.cs index 7e1a86b..96db864 100644 --- a/Helper.cs +++ b/Helper.cs @@ -33,5 +33,11 @@ public static void DoNothing(){ // toto } } + public static int ComputeWithSomeRecursion(int num, int inc) + { + num = num * ComputeWithSomeRecursion(num, inc-1); + + return num; + } } } \ No newline at end of file From 61483b0a049f18a873bf9bcb0c8f8b5802d70ca1 Mon Sep 17 00:00:00 2001 From: Christophe Havard Date: Fri, 4 Dec 2020 10:40:09 +0000 Subject: [PATCH 09/18] README.md edited online with Bitbucket --- README.md | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/README.md b/README.md index 97e2fad..0fcd76c 100644 --- a/README.md +++ b/README.md @@ -1,31 +1 @@ -# Fill Bi Database -Code for the recurring job that fills Bi database schema. -This function runs **every day at 00:00** - -# Principles -Several ordered SQL request will be executed on the server in order to compute BI data. - -![image-20200505161802892](/_images/image-20200505161802892.png) - -*In red the steps we think will take time. In grey, the optionnal step we will do in a second time.* - - - -# Test it - -This project is easy to test w/ VSCode and a local installation of Node.js (https://nodejs.org/en/). -In order to test and run the project locally, you need to install the following VSCode extensions : -* C# extension https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp -* Azure Function extension https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions -* Azurite extension (optional, provides a local Azure blob storage emulator) - -After extensions installed, please check your local environement can run azure functions : open your Terminal and run "func". Is everything goes well, -the installed version is displayed. - -To test the project, go to Debug section, then click on Run. - -# Good to mention -* Documentation advise the use of AZURE_FUNCTIONS_ENVIRONMENT variable instead of ASPNETCORE_ENVIRONMENT (cf link to doc below). - -# Useful links -Application settings reference for Azure Functions : https://docs.microsoft.com/en-us/azure/azure-functions/functions-app-settings \ No newline at end of file +[![Quality gate](https://sonarcloud.io/api/project_badges/quality_gate?project=christophe-havard-sonarsource_my_dotnetcore_project)](https://sonarcloud.io/dashboard?id=christophe-havard-sonarsource_my_dotnetcore_project) \ No newline at end of file From cb32e798b01b3125380078b366ef0ccf875abf53 Mon Sep 17 00:00:00 2001 From: Christophe H <65390576+christophe-havard-sonarsource@users.noreply.github.com> Date: Thu, 4 Mar 2021 12:13:44 +0100 Subject: [PATCH 10/18] Update Helper.cs --- Helper.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Helper.cs b/Helper.cs index 96db864..8212c81 100644 --- a/Helper.cs +++ b/Helper.cs @@ -20,9 +20,7 @@ private static string GetKeyVaultConnectionString(string secretName) } public static string GetConnectionString() { - if (Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT") != "Local") - return GetKeyVaultConnectionString("db-plastico-dev-connectionstring"); - else + return Environment.GetEnvironmentVariable("postgre_connection"); } // I add another useless code line @@ -36,8 +34,7 @@ public static void DoNothing(){ public static int ComputeWithSomeRecursion(int num, int inc) { num = num * ComputeWithSomeRecursion(num, inc-1); - return num; } } -} \ No newline at end of file +} From 5e65d6797f6578ad71092da531f72e0db573afc1 Mon Sep 17 00:00:00 2001 From: Christophe H <65390576+christophe-havard-sonarsource@users.noreply.github.com> Date: Thu, 4 Mar 2021 17:06:25 +0100 Subject: [PATCH 11/18] Update Helper.cs --- Helper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Helper.cs b/Helper.cs index 8212c81..dc291d6 100644 --- a/Helper.cs +++ b/Helper.cs @@ -34,7 +34,7 @@ public static void DoNothing(){ public static int ComputeWithSomeRecursion(int num, int inc) { num = num * ComputeWithSomeRecursion(num, inc-1); - return num; + return 2*num; } } } From 4c2eb38fa9c80a70688c15080af45cffc07f47b7 Mon Sep 17 00:00:00 2001 From: Christophe H <65390576+christophe-havard-sonarsource@users.noreply.github.com> Date: Wed, 24 Mar 2021 09:37:37 +0100 Subject: [PATCH 12/18] Update Helper.cs --- Helper.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Helper.cs b/Helper.cs index dc291d6..251c867 100644 --- a/Helper.cs +++ b/Helper.cs @@ -34,6 +34,7 @@ public static void DoNothing(){ public static int ComputeWithSomeRecursion(int num, int inc) { num = num * ComputeWithSomeRecursion(num, inc-1); + for(int i = 10; i < 10; i++){} return 2*num; } } From 0ebc3cedf70f7141af4c3cbf431fc46bf962f92b Mon Sep 17 00:00:00 2001 From: Christophe H <65390576+christophe-havard-sonarsource@users.noreply.github.com> Date: Tue, 17 Aug 2021 16:49:23 +0200 Subject: [PATCH 13/18] Update main.yml --- .github/workflows/main.yml | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 39b819f..ca9061b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,19 +32,25 @@ jobs: java-version: 1.11 # Runs a set of commands using the runners shell - - name: Install SonarScanner .NET Global tool + - name: Cache SonarQube scanner + id: cache-sonar-scanner + uses: actions/cache@v1 + with: + path: .\.sonar\scanner + key: ${{ runner.os }}-sonar-scanner + restore-keys: ${{ runner.os }}-sonar-scanner + - name: Install SonarQube scanner + if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' + shell: powershell + run: | + New-Item -Path .\.sonar\scanner -ItemType Directory + dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + shell: powershell run: | - dotnet tool install --global dotnet-sonarscanner - export PATH="$PATH:/root/.dotnet/tools" - - - name: SonarScanner STEP 1 - BEGIN - run: dotnet sonarscanner begin /k:"Github_Actions_DotNetCore" /d:"sonar.login=${{secrets.SONAR_TOKEN}}" /d:"sonar.host.url=${{secrets.SONAR_URL}}" - - - name: Build & Test - run: | - dotnet restore - dotnet build --no-restore --configuration Release - dotnet test --no-build --configuration Release - - - name: SonarScanner STEP 2 - END + .\.sonar\scanner\dotnet-sonarscanner begin /k:"christophe-havard-sonarsource_Github_Actions_DotNetCore" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="${{ secrets.SONAR_HOST_URL }}" + dotnet build + .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" run: dotnet sonarscanner end /d:"sonar.login=${{secrets.SONAR_TOKEN}}" From 94abf02b992e5266d323f32a8ee69721d075c423 Mon Sep 17 00:00:00 2001 From: Christophe H <65390576+christophe-havard-sonarsource@users.noreply.github.com> Date: Tue, 17 Aug 2021 17:09:55 +0200 Subject: [PATCH 14/18] Delete no-assistance-workflow.yaml --- .github/workflows/no-assistance-workflow.yaml | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 .github/workflows/no-assistance-workflow.yaml diff --git a/.github/workflows/no-assistance-workflow.yaml b/.github/workflows/no-assistance-workflow.yaml deleted file mode 100644 index 43f395f..0000000 --- a/.github/workflows/no-assistance-workflow.yaml +++ /dev/null @@ -1,42 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: SonarQube Analysis for Other - -# Controls when the action will run. -on: [push, pull_request, workflow_dispatch] - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - # Runs a single command using the runners shell - - name: install jdk - uses: actions/setup-java@v1.4.3 - with: - java-version: 1.11 - - # Runs a set of commands using the runners shell - - name: Install SonarScanner .NET Global tool - run: | - dotnet tool install --global dotnet-sonarscanner - export PATH="$PATH:/root/.dotnet/tools" - - - name: SonarScanner STEP 1 - BEGIN - run: dotnet sonarscanner begin /k:"Github_Actions_DotNetCore" /d:"sonar.login=${{secrets.SONAR_TOKEN}}" /d:"sonar.host.url=${{secrets.SONAR_HOST_URL}}" - - - name: Build & Test - run: | - dotnet restore - dotnet build --no-restore --configuration Release - dotnet test --no-build --configuration Release - - - name: SonarScanner STEP 2 - END - run: dotnet sonarscanner end /d:"sonar.login=${{secrets.SONAR_TOKEN}}" From 4a0fa62bf683d92b016ec1f43940f2d2ab55a567 Mon Sep 17 00:00:00 2001 From: Christophe H <65390576+christophe-havard-sonarsource@users.noreply.github.com> Date: Tue, 17 Aug 2021 17:10:35 +0200 Subject: [PATCH 15/18] Update Helper.cs --- Helper.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Helper.cs b/Helper.cs index 251c867..aa027e6 100644 --- a/Helper.cs +++ b/Helper.cs @@ -37,5 +37,12 @@ public static int ComputeWithSomeRecursion(int num, int inc) for(int i = 10; i < 10; i++){} return 2*num; } + public static void DoNothingAgain(){ + Environment.GetEnvironmentVariable("postgre_connection"); + int i = 0; + while(i< 100){ + // toto + } + } } } From 3839595343a84ae3f98411cfb97964a657b35aac Mon Sep 17 00:00:00 2001 From: Christophe H <65390576+christophe-havard-sonarsource@users.noreply.github.com> Date: Wed, 18 Aug 2021 09:29:51 +0200 Subject: [PATCH 16/18] Update Helper.cs --- Helper.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Helper.cs b/Helper.cs index aa027e6..7fca2e2 100644 --- a/Helper.cs +++ b/Helper.cs @@ -6,7 +6,25 @@ namespace Surfrider { public static class Helper { - // https://docs.microsoft.com/en-us/azure/key-vault/secrets/quick-create-net + + + // https://rules.sonarsource.com/csharp/type/Bug/RSPEC-4275 + private int x; + private int y; + + public int X + { + get { return x; } + set { x = value; } + } + + public int Y + { + get { return x; } // Noncompliant: field 'y' is not used in the return value + set { x = value; } // Noncompliant: field 'y' is not updated + } + + private static string GetKeyVaultConnectionString(string secretName) { From a6b0187c4f3aec083ed1aebc1861bc020d517d79 Mon Sep 17 00:00:00 2001 From: Christophe H <65390576+christophe-havard-sonarsource@users.noreply.github.com> Date: Wed, 18 Aug 2021 09:34:31 +0200 Subject: [PATCH 17/18] Update Helper.cs --- Helper.cs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/Helper.cs b/Helper.cs index 7fca2e2..4028d0d 100644 --- a/Helper.cs +++ b/Helper.cs @@ -7,22 +7,9 @@ namespace Surfrider { public static class Helper { - - // https://rules.sonarsource.com/csharp/type/Bug/RSPEC-4275 - private int x; - private int y; - - public int X - { - get { return x; } - set { x = value; } - } - - public int Y - { - get { return x; } // Noncompliant: field 'y' is not used in the return value - set { x = value; } // Noncompliant: field 'y' is not updated - } + // https://rules.sonarsource.com/csharp/type/Bug/RSPEC-3889 + Thread.CurrentThread.Suspend(); // Noncompliant + Thread.CurrentThread.Resume(); // Noncompliant private static string GetKeyVaultConnectionString(string secretName) From 3d679c7e21cda813371a72055ad4dfc6888bc5ab Mon Sep 17 00:00:00 2001 From: Christophe Havard Date: Wed, 18 Aug 2021 09:54:13 +0200 Subject: [PATCH 18/18] added bug --- Helper.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Helper.cs b/Helper.cs index 4028d0d..91b4f9d 100644 --- a/Helper.cs +++ b/Helper.cs @@ -7,11 +7,6 @@ namespace Surfrider { public static class Helper { - // https://rules.sonarsource.com/csharp/type/Bug/RSPEC-3889 - Thread.CurrentThread.Suspend(); // Noncompliant - Thread.CurrentThread.Resume(); // Noncompliant - - private static string GetKeyVaultConnectionString(string secretName) { @@ -43,6 +38,13 @@ public static int ComputeWithSomeRecursion(int num, int inc) return 2*num; } public static void DoNothingAgain(){ + // https://rules.sonarsource.com/csharp/type/Bug/RSPEC-3984 + int x = -1; + if (x < 0) + { + new ArgumentException("x must be nonnegative"); + } + Environment.GetEnvironmentVariable("postgre_connection"); int i = 0; while(i< 100){