-
-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (132 loc) · 5.94 KB
/
Copy pathci.yml
File metadata and controls
153 lines (132 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: CI
on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]
permissions:
contents: read
pull-requests: write
packages: write
jobs:
# ════════════════════════════════════════════════════════════════════
# Job 1 — Build, test, pack
# If ANY test fails the whole job fails and nothing gets published.
# ════════════════════════════════════════════════════════════════════
build-and-test:
name: Build & Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET 10
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
# .NET 8 is needed by the sample projects
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore
run: dotnet restore DSoftStudio.Mediator.slnx
- name: Build
run: dotnet build DSoftStudio.Mediator.slnx -c Release --no-restore
# Run EVERY test project in the solution in one shot. `dotnet test` on the
# solution discovers all test projects (and skips non-test ones), so a newly
# added test project is covered automatically — no need to edit this workflow
# (the old hand-listed steps silently skipped ModularMonolith.Tests). Coverage
# is collected per project and MERGED below into a single accurate report.
- name: Test
run: >
dotnet test DSoftStudio.Mediator.slnx
-c Release
--no-build
--logger "trx"
--collect:"XPlat Code Coverage"
# ── Artifacts (always uploaded, even on failure) ──
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: tests/**/TestResults/**/*.trx
- name: Upload coverage
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage
path: tests/**/TestResults/**/coverage.cobertura.xml
# MERGE all per-project coverage files into ONE report before summarizing.
# Each test project emits its own coverage.cobertura.xml covering the SAME
# assemblies only in the slice it exercises; feeding the raw glob to a summary
# lists each assembly N times with different numbers (the misleading "34%").
# ReportGenerator unions them, so every assembly shows its real combined
# coverage exactly once.
- name: Merge coverage reports
if: github.event_name == 'pull_request'
uses: danielpalme/ReportGenerator-GitHub-Action@049f7ec958c672fd31d5cc1cb01622dc8d2e23ab # v5.5.10
with:
reports: 'tests/**/TestResults/**/coverage.cobertura.xml'
targetdir: 'coverage'
reporttypes: 'Cobertura;MarkdownSummaryGithub'
- name: Add coverage to PR
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2
with:
path: coverage/SummaryGithub.md
# ── Pack (only on main/tag, and only if all tests passed) ──
- name: Pack NuGet packages
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
run: |
mkdir -p nupkgs
dotnet pack src/DSoftStudio.Mediator.Abstractions -c Release --no-build -o nupkgs
dotnet pack src/DSoftStudio.Mediator -c Release --no-build -o nupkgs
dotnet pack src/DSoftStudio.Mediator.FluentValidation -c Release --no-build -o nupkgs
dotnet pack src/DSoftStudio.Mediator.HybridCache -c Release --no-build -o nupkgs
dotnet pack src/DSoftStudio.Mediator.OpenTelemetry -c Release --no-build -o nupkgs
- name: Upload NuGet packages
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v4
with:
name: nupkgs
path: nupkgs/*
# ════════════════════════════════════════════════════════════════════
# Job 2 — Publish
# Runs ONLY after build-and-test succeeds (all tests green).
# Downloads the pre-built .nupkg artifacts — no rebuild needed.
# ════════════════════════════════════════════════════════════════════
publish:
name: Publish NuGet packages
needs: build-and-test
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Download NuGet packages
uses: actions/download-artifact@v4
with:
name: nupkgs
path: nupkgs
- name: List packages
run: ls -la nupkgs/
# Push to GitHub Packages (every push to main)
- name: Push to GitHub Packages
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
env:
GH_PKG_TOKEN: ${{ secrets.GH_PKG_TOKEN }}
run: >
dotnet nuget push "nupkgs/*.nupkg"
--source "https://nuget.pkg.github.com/DSoftStudio/index.json"
--api-key "$GH_PKG_TOKEN"
--skip-duplicate
# Push to NuGet.org (only on version tags: v*)
- name: Push to NuGet.org
if: startsWith(github.ref, 'refs/tags/v')
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: >
dotnet nuget push "nupkgs/*.nupkg"
--source "https://api.nuget.org/v3/index.json"
--api-key "$NUGET_API_KEY"
--skip-duplicate