Skip to content

Feat/leaderboard

Feat/leaderboard #426

Workflow file for this run

name: Build / Test
on:
push:
paths:
- 'src/**'
- '.github/workflows/dotnet.yml'
- 'coverage.runsettings'
pull_request:
paths:
- 'src/**'
- '.github/workflows/dotnet.yml'
- 'coverage.runsettings'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [ 8.0.x, 9.0.x ]
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Cache .NET packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
test:
permissions:
pull-requests: write
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [ 8.0.x, 9.0.x ]
fail-fast: false
services:
mysql:
image: mysql:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: gangs
ports:
- 3306:3306
options: --health-cmd "mysqladmin ping --silent" --health-interval 10s
mariadb:
image: mariadb:latest
env:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: yes
MARIADB_DATABASE: gangs
ports:
- 3307:3306
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Cache .NET packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test with MariaDB
env:
DB_GANGS_CONNECTION: "Server=localhost;Port=3307;Database=gangs;User=root;Pooling=false"
run: dotnet test src/GangsTest/GangsTest.csproj --no-build --verbosity normal
- name: Test with MySQL
env:
DB_GANGS_CONNECTION: "Server=localhost;Port=3306;Database=gangs;User=root;Pooling=false"
run: dotnet test src/GangsTest/GangsTest.csproj --no-build --verbosity normal
- name: Generate Code Coverage Report
env:
DB_GANGS_CONNECTION: "Server=localhost;Port=3306;Database=gangs;User=root;Pooling=false"
if: ${{ matrix.dotnet-version == '9.0.x' }}
run: dotnet test --no-build --verbosity normal --collect:"XPlat Code Coverage" --logger trx --results-directory coverage src/GangsTest/GangsTest.csproj --settings coverage.runsettings
- name: Code Coverage Summary Report
uses: irongut/[email protected]
if: ${{ matrix.dotnet-version == '9.0.x' }}
with:
filename: 'coverage/*/coverage.cobertura.xml'
badge: true
format: 'markdown'
output: 'both'
thresholds: '33 75'
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request' && matrix.dotnet-version == '9.0.x'
with:
recreate: true
path: code-coverage-results.md
- name: Export Code Coverage
if: ${{ matrix.dotnet-version == '9.0.x' }}
run: echo "CODE_COVERAGE=$(tail -n 1 code-coverage-results.md | grep -oP '(?<=\*\*Summary\*\* \|\s\*\*)[0-9]+(?=%)')" >> $GITHUB_ENV
- name: Create Test Coverage Badge
uses: Schneegans/[email protected]
id: create_coverage_badge
if: matrix.dotnet-version == '9.0.x' && github.ref_name == 'main'
with:
auth: ${{ secrets.GIST_AUTH_TOKEN }}
gistID: 72f982ea80cb7dabb6e91f21d6594ba8
filename: code-coverage.json
label: 'Code Coverage'
message: ${{ env.CODE_COVERAGE }}%
valColorRange: ${{ env.CODE_COVERAGE }}
maxColorRange: 100
minColorRange: 33
- name: Write to Job Summary
if: ${{ matrix.dotnet-version == '9.0.x' }}
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY