diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5adf675..77927a2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,4 @@ -name: Build - +name: SonarQube on: push: branches: @@ -11,20 +10,48 @@ jobs: build: name: Build and analyze runs-on: windows-latest - + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory + SONAR_SCANNER_PROJECT_KEY: SupportTeam-SC-demos_kilo-cppAndcSharp + steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - uses: SonarSource/sonarqube-scan-action@v4 + fetch-depth: 0 + + - name: Install .NET SDK + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.x' + + - name: Install SonarScanner for .NET + run: dotnet tool install --global dotnet-sonarscanner + + - name: Install Build Wrapper + uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v5 + + - name: SonarScanner for .NET - Begin + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + dotnet-sonarscanner begin ` + /k:"${{ env.SONAR_SCANNER_PROJECT_KEY }}" ` + /o:"supportteam-sc-demos" ` + /d:sonar.login="${{ secrets.SONAR_TOKEN }}" ` + /d:sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" + + - name: Setup MSBuild + uses: microsoft/setup-msbuild@v2 + + - name: Restore .NET dependencies + run: dotnet restore CPlusPlusAndCSharp.sln + + - name: Build Solution with Build Wrapper + run: | + build-wrapper-win-x86-64 --out-dir $env:BUILD_WRAPPER_OUT_DIR msbuild CPlusPlusAndCSharp.sln /p:Configuration=Release + shell: pwsh + + - name: SonarScanner for .NET - End env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} - # If you wish to fail your job when the Quality Gate is red, uncomment the - # following lines. This would typically be used to fail a deployment. - # We do not recommend to use this in a pull request. Prefer using pull request - # decoration instead. - # - uses: SonarSource/sonarqube-quality-gate-action@v1 - # timeout-minutes: 5 - # env: - # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" diff --git a/CPlusPlusAndCSharp/CPlusPlusAndCSharp.cpp b/CPlusPlusAndCSharp/CPlusPlusAndCSharp.cpp index ecfcff3..32dd028 100644 --- a/CPlusPlusAndCSharp/CPlusPlusAndCSharp.cpp +++ b/CPlusPlusAndCSharp/CPlusPlusAndCSharp.cpp @@ -30,3 +30,5 @@ void f() // 4. Use the Error List window to view errors // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file + +// Triggering Actions diff --git a/CPlusPlusAndCSharp/sonar-project.properties b/CPlusPlusAndCSharp/sonar-project.properties deleted file mode 100644 index b24cc20..0000000 --- a/CPlusPlusAndCSharp/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -sonar.projectKey=kiloecho-sonar_cppAndcSharp_31bc1e05-0358-4305-993a-c4367ca5a954 diff --git a/CSharpProject/sonar-project.properties b/CSharpProject/sonar-project.properties deleted file mode 100644 index b24cc20..0000000 --- a/CSharpProject/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -sonar.projectKey=kiloecho-sonar_cppAndcSharp_31bc1e05-0358-4305-993a-c4367ca5a954 diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index c97ee2a..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,44 +0,0 @@ -pipeline { - agent any - options { - // This is required if you want to clean before build with the "Workspace Cleanup Plugin" - skipDefaultCheckout(true) - } - stages { - stage('SCM') { - steps { - // Clean before build using the "Workspace Cleanup Plugin" - cleanWs() - checkout scm - } - } - - stage('Download Build Wrapper') { - steps { - powershell ''' - $path = ".sonar/build-wrapper-win-x86.zip" - New-Item -ItemType directory -Path .sonar -Force - [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 - (New-Object System.Net.WebClient).DownloadFile("https://ke100.ngrok.io/static/cpp/build-wrapper-win-x86.zip", $path) - Add-Type -AssemblyName System.IO.Compression.FileSystem - [System.IO.Compression.ZipFile]::ExtractToDirectory($path, ".sonar") - $env:Path += ";.sonar/build-wrapper-win-x86" - ''' - } - } - - stage('SonarQube Analysis and Build') { - steps { - script { - def msbuildHome = tool 'MSBuild'; // MSBuild from VS 2022 - def scannerHome = tool 'SonarScanner for MSBuild'; // Name of the SonarQube Scanner you created in "Global Tool Configuration" section - withSonarQubeEnv('KESQ10') { - bat "dotnet ${scannerHome}\\SonarScanner.MSBuild.dll begin /k:\"kiloecho-sonar_cppAndcSharp_AYgqQyx_BphOJVwWroRs\" /d:\"sonar.cfamily.build-wrapper-output=wrapper-output\" /d:sonar.verbose=true" - powershell "build-wrapper-win-x86-64.exe --out-dir wrapper-output ${msbuildHome} ./CPlusPlusAndCSharp.sln /t:Rebuild /nodeReuse:False /restore" - bat "dotnet ${scannerHome}\\SonarScanner.MSBuild.dll end" - } - } - } - } - } -} diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index b24cc20..0000000 --- a/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -sonar.projectKey=kiloecho-sonar_cppAndcSharp_31bc1e05-0358-4305-993a-c4367ca5a954