Skip to content

feat: add Docker support and comprehensive test coverage #44

feat: add Docker support and comprehensive test coverage

feat: add Docker support and comprehensive test coverage #44

Workflow file for this run

name: Build & Test
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-and-test:
name: Build, Test & SonarCloud
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Java 21 (required by SonarScanner)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- name: Set up .NET 10
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.x
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj') }}
restore-keys: nuget-${{ runner.os }}-
- name: Install SonarScanner for .NET
run: dotnet tool install --global dotnet-sonarscanner
- name: Restore dependencies
run: dotnet restore
- name: Begin SonarCloud analysis
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
dotnet sonarscanner begin \
/k:"guibranco_grimoire-api" \
/o:"guibranco" \
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
/d:sonar.host.url="https://sonarcloud.io" \
/d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" \
/d:sonar.exclusions="**/Migrations/**,**/obj/**,**/bin/**" \
/d:sonar.coverage.exclusions="**/Migrations/**,**/Program.cs"
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Run unit and integration tests
run: |
dotnet test --no-build --configuration Release \
--filter "FullyQualifiedName!~E2eTests" \
--collect:"XPlat Code Coverage" \
--results-directory ./coverage \
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
- name: End SonarCloud analysis
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
e2e:
name: E2E Tests (Docker)
runs-on: ubuntu-latest
needs: build-and-test
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up .NET 10
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.x
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj') }}
restore-keys: nuget-${{ runner.os }}-
- name: Restore dependencies
run: dotnet restore tests/Grimoire.E2eTests
- name: Build Docker image
run: docker build -t grimoire-api:e2e .
- name: Run E2E tests
env:
GRIMOIRE_TEST_IMAGE: grimoire-api:e2e
run: |
dotnet test tests/Grimoire.E2eTests --configuration Release \
--logger "console;verbosity=normal"