Merge pull request #205 from nanotaboada/feature/c-sharp-12-primary-c… #470
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
# Building and testing .NET | |
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | |
name: .NET CI | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
env: | |
DOTNET_VERSION: 8.0.x | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up .NET ${{ env.DOTNET_VERSION }} | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: ${{ env.DOTNET_VERSION }} | |
# The action searches for packages.lock.json in the repository root, | |
# calculates their hash, and uses it as a part of the cache key. | |
cache: true | |
# Use cache-dependency-path for cases when multiple dependency files | |
# are used, or they are located in different subdirectories. | |
cache-dependency-path: | | |
src/Dotnet.Samples.AspNetCore.WebApi/packages.lock.json | |
test/Dotnet.Samples.AspNetCore.WebApi.Tests/packages.lock.json | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Build projects | |
run: dotnet build --no-restore | |
test: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Run tests and generate Cobertura coverage reports | |
run: dotnet test --results-directory "coverage" --collect:"XPlat Code Coverage" --settings .runsettings | |
- name: Install dotnet-coverage tool | |
run: dotnet tool install --global dotnet-coverage | |
- name: Merge Cobertura coverage reports | |
run: dotnet-coverage merge coverage/**/*.cobertura.xml --output coverage/cobertura.xml --output-format cobertura | |
- name: Install ReportGenerator tool | |
run: dotnet tool install --global dotnet-reportgenerator-globaltool | |
- name: Generate Markdown summary of coverage report | |
run: reportgenerator -reports:coverage/cobertura.xml -targetdir:coverage -reporttypes:"MarkdownSummaryGithub" | |
- name: Display Markdown summary of coverage report | |
run: cat coverage/SummaryGithub.md >> $GITHUB_STEP_SUMMARY | |
- name: Upload Cobertura coverage report artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: cobertura.xml | |
path: coverage/cobertura.xml | |
coverage: | |
needs: test | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
service: [codecov, codacy] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download Cobertura coverage report artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: cobertura.xml | |
- name: Upload Cobertura coverage report to ${{ matrix.service }} | |
if: ${{ matrix.service == 'codecov' }} | |
uses: codecov/[email protected] | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
files: cobertura.xml | |
use_oidc: false | |
- name: Upload Cobertura coverage report to ${{ matrix.service }} | |
if: ${{ matrix.service == 'codacy' }} | |
uses: codacy/[email protected] | |
with: | |
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} | |
coverage-reports: cobertura.xml |