Skip to content

Bump the test-packages group with 1 update #33

Bump the test-packages group with 1 update

Bump the test-packages group with 1 update #33

Workflow file for this run

# .github/workflows/ci.yml
name: CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
env:
DOTNET_VERSION: '9.0.x'
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
build-and-test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: testdb
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Run unit tests
run: dotnet test --no-build --configuration Release --verbosity normal --logger "console;verbosity=detailed" --collect:"XPlat Code Coverage" --results-directory ./coverage
- name: Generate coverage report
uses: danielpalme/[email protected]
with:
reports: coverage/**/coverage.cobertura.xml
targetdir: coverage-report
reporttypes: 'HtmlInline;Cobertura;MarkdownSummaryGithub'
verbosity: 'Info'
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage-report/Cobertura.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
- name: Add coverage PR comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
path: coverage-report/SummaryGithub.md
- name: Check code formatting
run: dotnet format --verify-no-changes --verbosity diagnostic
- name: Run EF Core migrations check
run: |
dotnet tool install --global dotnet-ef
dotnet ef migrations has-pending-model-changes --project src/MyOpenTelemetryApi.Infrastructure --startup-project src/MyOpenTelemetryApi.Api
env:
ConnectionStrings__DefaultConnection: "Host=localhost;Port=5432;Database=testdb;Username=postgres;Password=postgres"
- name: Test database migrations
run: |
dotnet ef database update --project src/MyOpenTelemetryApi.Infrastructure --startup-project src/MyOpenTelemetryApi.Api
env:
ConnectionStrings__DefaultConnection: "Host=localhost;Port=5432;Database=testdb;Username=postgres;Password=postgres"
- name: Run integration tests (if any)
run: |
echo "No integration tests yet - placeholder for future tests"
env:
ConnectionStrings__DefaultConnection: "Host=localhost;Port=5432;Database=testdb;Username=postgres;Password=postgres"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
name: build-artifacts
path: |
src/MyOpenTelemetryApi.Api/bin/Release/net9.0/
!src/MyOpenTelemetryApi.Api/bin/Release/net9.0/*.pdb
retention-days: 7
code-analysis:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for better analysis
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Install .NET tools
run: |
dotnet tool install --global dotnet-outdated-tool
dotnet tool install --global dotnet-reportgenerator-globaltool
- name: Check for outdated packages
run: dotnet outdated --fail-on-updates
continue-on-error: true
- name: Security scan
run: |
dotnet list package --vulnerable --include-transitive
docker-build:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create Dockerfile
run: |
cat > Dockerfile << 'EOF'
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
# Copy csproj files and restore dependencies
COPY ["src/MyOpenTelemetryApi.Api/MyOpenTelemetryApi.Api.csproj", "MyOpenTelemetryApi.Api/"]
COPY ["src/MyOpenTelemetryApi.Application/MyOpenTelemetryApi.Application.csproj", "MyOpenTelemetryApi.Application/"]
COPY ["src/MyOpenTelemetryApi.Domain/MyOpenTelemetryApi.Domain.csproj", "MyOpenTelemetryApi.Domain/"]
COPY ["src/MyOpenTelemetryApi.Infrastructure/MyOpenTelemetryApi.Infrastructure.csproj", "MyOpenTelemetryApi.Infrastructure/"]
RUN dotnet restore "MyOpenTelemetryApi.Api/MyOpenTelemetryApi.Api.csproj"
# Copy source code
COPY src/ .
# Build and publish
RUN dotnet publish "MyOpenTelemetryApi.Api/MyOpenTelemetryApi.Api.csproj" -c Release -o /app/publish
# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
WORKDIR /app
# Install OpenTelemetry Collector (optional)
# RUN apt-get update && apt-get install -y curl && \
# curl -L https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.91.0/otelcol_0.91.0_linux_amd64.tar.gz | tar -xz && \
# mv otelcol /usr/local/bin/
COPY --from=build /app/publish .
# Create non-root user
RUN adduser --disabled-password --gecos '' appuser && chown -R appuser /app
USER appuser
EXPOSE 8080
EXPOSE 8081
ENV ASPNETCORE_URLS=http://+:8080
ENV ASPNETCORE_ENVIRONMENT=Production
ENTRYPOINT ["dotnet", "MyOpenTelemetryApi.Api.dll"]
EOF
- name: Build Docker image
run: docker build -t myopentelemetryapi:${{ github.sha }} .
- name: Run Docker container test
run: |
docker run -d -p 8080:8080 --name test-container \
-e ConnectionStrings__DefaultConnection="Host=host.docker.internal;Database=test;Username=test;Password=test" \
myopentelemetryapi:${{ github.sha }}
sleep 10
curl -f http://localhost:8080/api/health || exit 1
docker logs test-container
docker stop test-container
- name: Save Docker image
if: github.ref == 'refs/heads/main'
run: |
docker save myopentelemetryapi:${{ github.sha }} | gzip > myopentelemetryapi.tar.gz
- name: Upload Docker image
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: docker-image
path: myopentelemetryapi.tar.gz
retention-days: 7