From a39ea066fb4da9c3a054d24756d36bc2cef9686e Mon Sep 17 00:00:00 2001 From: Chris Sherlock Date: Thu, 27 Oct 2022 10:11:56 +0100 Subject: [PATCH 1/3] Add sonarcloud scanning to build and test github action --- .github/workflows/build_and_test.yml | 33 ++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 24a704322..f9df71aff 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -1,8 +1,12 @@ name: .NET on: + push: + branches: [ main ] pull_request: branches: [ main ] + types: [ opened, synchronize, reopened] + jobs: build: @@ -10,10 +14,26 @@ jobs: steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Shallow clones disabled for a better relevancy of SC analysis - name: Setup .NET uses: actions/setup-dotnet@v1 with: dotnet-version: 3.1.301 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 1.11 + - name: Cache SonarCloud packages + uses: actions/cache@v1 + with: + path: ~\sonar\cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Install SonarCloud scanners + run: dotnet tool install --global dotnet-sonarscanner + - name: Install dotnet-coverage + run: dotnet tool install --global dotnet-coverage - name: Restore dependencies run: dotnet restore - name: Setup node.js @@ -23,7 +43,12 @@ jobs: # This could be cached in the future to allow for quicker build times - name: Build Frontend run: make build-frontend - - name: Build - run: dotnet build -c Release --no-restore - - name: Test - run: dotnet test -c Release --no-build --verbosity normal + - name: Build, Test and Analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + dotnet-sonarscanner begin /k:"DFE-Digital_academy-transfers-api" /o:"dfe-digital" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml + dotnet build -c Release --no-restore + dotnet-coverage collect 'dotnet test -c Release --no-build --verbosity normal' -f xml -o 'coverage.xml' + dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" From dab7d3653af69f2606e94a1c420509b7e92df407 Mon Sep 17 00:00:00 2001 From: Chris Sherlock Date: Thu, 27 Oct 2022 11:17:58 +0100 Subject: [PATCH 2/3] Bump node version to 18 for LTS --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index f9df71aff..08321fce2 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -39,7 +39,7 @@ jobs: - name: Setup node.js uses: actions/setup-node@v1 with: - node-version: '12.x' + node-version: '18.x' # This could be cached in the future to allow for quicker build times - name: Build Frontend run: make build-frontend From ccc9fcf096867bf059b33d95e15c058853eb7b53 Mon Sep 17 00:00:00 2001 From: Chris Sherlock Date: Wed, 9 Nov 2022 16:26:51 +0000 Subject: [PATCH 3/3] Remove dotnet-coverage --- .github/workflows/build_and_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 08321fce2..4f285ebbd 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -48,7 +48,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | - dotnet-sonarscanner begin /k:"DFE-Digital_academy-transfers-api" /o:"dfe-digital" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml + dotnet-sonarscanner begin /k:"DFE-Digital_academy-transfers-api" /o:"dfe-digital" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" dotnet build -c Release --no-restore - dotnet-coverage collect 'dotnet test -c Release --no-build --verbosity normal' -f xml -o 'coverage.xml' + dotnet test -c Release --no-build --verbosity normal dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"