Skip to content

WIP - New ofsted automation #1110

WIP - New ofsted automation

WIP - New ofsted automation #1110

name: Test .NET code and scan all code with SonarScanner
on:
push:
branches: [ main ]
paths:
- '**'
- '!.gitignore'
- '!**.DotSettings'
- '!**.md'
- '!.config/**'
- '!.github/**'
- '!terraform/**'
pull_request:
branches: [ main, '**-feature' ]
types: [ opened, synchronize, reopened]
paths:
- '**'
- '!.gitignore'
- '!**.DotSettings'
- '!**.md'
- '!.config/**'
- '!.github/**'
- '!terraform/**'
env:
DOTNET_VERSION: '8.x'
JAVA_VERSION: '17'
LAST_COMMIT_SHA: default
jobs:
build:
name: Build .NET
runs-on: ubuntu-latest
environment: development
steps:
- name: Check out code
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0 # Shallow clones disabled for a better relevancy of SC analysis
- name: Set SHA environment variable
run: |
echo "LAST_COMMIT_SHA=${GITHUB_SHA:(-7)}" >> $GITHUB_ENV
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'microsoft'
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
run: dotnet tool install --global dotnet-sonarscanner --version 8.0.1
- name: Install other dotnet tools (including stryker, code coverage and entity framework cli)
run: dotnet tool restore
- name: Build and analyse solution
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
dotnet-sonarscanner begin /k:"DFE-Digital_find-information-about-academies-and-trusts" /o:"dfe-digital" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
dotnet restore DfE.FindInformationAcademiesTrusts
dotnet build DfE.FindInformationAcademiesTrusts -c Release
dotnet coverage collect "dotnet test" -f xml -o "coverage.xml"
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
- name: Run mutation tests
run: dotnet stryker
- name: Ensure there are no pending migrations
run: dotnet ef migrations has-pending-model-changes --context FiatDbContext --project DfE.FindInformationAcademiesTrusts.Data.FiatDb --startup-project DfE.FindInformationAcademiesTrusts