Added Caching #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: .NET Build and Test Template | ||
on: | ||
workflow_call: | ||
inputs: | ||
project_name: | ||
required: true | ||
type: string | ||
description: "The name of the project" | ||
project_path: | ||
required: true | ||
type: string | ||
description: "The relative path to the project directory" | ||
sonar_project_key: | ||
required: true | ||
type: string | ||
description: "SonarCloud project key" | ||
secrets: | ||
GITHUB_TOKEN: | ||
Check failure on line 19 in .github/workflows/built-test-template.yml GitHub Actions / .github/workflows/built-test-template.ymlInvalid workflow file
|
||
required: true | ||
SONAR_TOKEN: | ||
required: true | ||
env: | ||
DOTNET_VERSION: '8.0.x' | ||
EF_VERSION: '6.0.5' | ||
JAVA_VERSION: '17' | ||
CONNECTION_STRING: 'Server=localhost,1433;Database=sip;TrustServerCertificate=True;User Id=sa;Password=StrongPassword905' | ||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: read | ||
contents: read | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: ${{ env.DOTNET_VERSION }} | ||
- name: Setup JDK | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'microsoft' | ||
java-version: ${{ env.JAVA_VERSION }} | ||
- name: Cache SonarCloud packages | ||
uses: actions/cache@v4 | ||
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 EF for tests | ||
run: dotnet tool install --global dotnet-ef --version ${{ env.EF_VERSION }} | ||
- name: Install dotnet reportgenerator | ||
run: dotnet tool install --global dotnet-reportgenerator-globaltool | ||
- name: Add nuget package source | ||
run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/DFE-Digital/index.json" | ||
- name: Restore dependencies | ||
run: dotnet restore ${{ inputs.project_path }} | ||
- name: Build, Test and Analyze | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
ConnectionStrings__DefaultConnection: ${{ env.CONNECTION_STRING }} | ||
CI: true | ||
run: | | ||
dotnet-sonarscanner begin /k:"${{ inputs.sonar_project_key }}" /o:"dfe-digital" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.coverageReportPaths=CoverageReport/SonarQube.xml | ||
dotnet build --no-restore -p:CI=${CI} ${{ inputs.project_path }} | ||
dotnet test --no-build --verbosity normal --collect:"XPlat Code Coverage" ${{ inputs.project_path }} | ||
reportgenerator -reports:./**/coverage.cobertura.xml -targetdir:./CoverageReport -reporttypes:SonarQube | ||
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" |