Skip to content

Commit e6333b9

Browse files
committed
New build
Signed-off-by: Tomasz Maruszak <maruszaktomasz@gmail.com>
1 parent cbcdee2 commit e6333b9

File tree

1 file changed

+257
-82
lines changed

1 file changed

+257
-82
lines changed

.github/workflows/build.yml

Lines changed: 257 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ env:
1919
jobs:
2020
build:
2121
runs-on: ubuntu-latest
22-
# allow to run concurrently within separate branches
23-
concurrency:
24-
group: ${{ github.workflow }}-${{ github.ref }}
25-
cancel-in-progress: true
2622
steps:
2723
- name: PR - Checkout
2824
if: github.event_name == 'pull_request_target'
@@ -37,75 +33,189 @@ jobs:
3733
with:
3834
fetch-depth: 0
3935

40-
- name: Setup .NET 8.0
36+
- name: Setup .NET 9.0
4137
uses: actions/setup-dotnet@v4
4238
with:
4339
dotnet-version: 9.0.x
4440
cache: false
4541

46-
- name: Setup .NET
47-
uses: actions/setup-dotnet@v4
48-
with:
49-
dotnet-version: 9.0.x
50-
cache: false
42+
- name: Restore Dependencies
43+
run: dotnet restore $SOLUTION_NAME --verbosity minimal
44+
working-directory: ./src
5145

52-
- name: Restore dependencies
53-
run: dotnet restore $SOLUTION_NAME
46+
- name: Build
47+
run: dotnet build $SOLUTION_NAME --configuration $SOLUTION_CONFIGURATION --no-restore
5448
working-directory: ./src
5549

56-
- name: SonarCloud - Setup Java17
57-
#if: github.event_name == 'pull_request_target'
58-
uses: actions/setup-java@v4
50+
unit_tests:
51+
runs-on: ubuntu-latest
52+
steps:
53+
- name: PR - Checkout
54+
if: github.event_name == 'pull_request_target'
55+
uses: actions/checkout@v4
5956
with:
60-
distribution: "adopt"
61-
java-version: "17"
57+
fetch-depth: 0
58+
ref: ${{ github.event.pull_request.head.sha }}
6259

63-
- name: SonarCloud - Install SonarCloud scanner
64-
#if: github.event_name == 'pull_request_target'
65-
run: dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner
60+
- name: Checkout
61+
if: github.event_name != 'pull_request_target'
62+
uses: actions/checkout@v4
63+
with:
64+
fetch-depth: 0
6665

67-
- name: SonarCloud - SonarScanner Begin
68-
#if: github.event_name == 'pull_request_target'
69-
env:
70-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
71-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
72-
run: |
73-
params=""
74-
pr_number="${{ github.event.pull_request.number }}"
75-
if [[ -n "$pr_number" ]]; then
76-
params="/d:sonar.pullrequest.key=${pr_number}"
77-
fi
78-
../.sonar/scanner/dotnet-sonarscanner begin /k:"zarusz_SlimMessageBus" /o:"zarusz" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" /d:sonar.exclusions="Samples/**/*,Tests/**/*" $params
66+
- name: Setup .NET 8.0
67+
uses: actions/setup-dotnet@v4
68+
with:
69+
dotnet-version: 8.0.x
70+
cache: false
71+
72+
- name: Setup .NET 9.0
73+
uses: actions/setup-dotnet@v4
74+
with:
75+
dotnet-version: 9.0.x
76+
cache: false
77+
78+
# - name: SonarCloud - Setup Java17
79+
# #if: github.event_name == 'pull_request_target'
80+
# uses: actions/setup-java@v4
81+
# with:
82+
# distribution: "adopt"
83+
# java-version: "17"
84+
85+
# - name: Install SonarCloud Scanner
86+
# #if: github.event_name == 'pull_request_target'
87+
# run: dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner
88+
89+
# - name: SonarCloud - Begin Analysis
90+
# #if: github.event_name == 'pull_request_target'
91+
# env:
92+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
94+
# run: |
95+
# params=""
96+
# pr_number="${{ github.event.pull_request.number }}"
97+
# if [[ -n "$pr_number" ]]; then
98+
# params="/d:sonar.pullrequest.key=${pr_number}"
99+
# fi
100+
# ../.sonar/scanner/dotnet-sonarscanner begin \
101+
# /k:"zarusz_SlimMessageBus" /o:"zarusz" \
102+
# /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
103+
# /d:sonar.host.url="https://sonarcloud.io" \
104+
# /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" \
105+
# /d:sonar.exclusions="Samples/**/*,Tests/**/*" \
106+
# $params
107+
# working-directory: ./src
108+
109+
- name: Restore Dependencies
110+
run: dotnet restore $SOLUTION_NAME --verbosity minimal
79111
working-directory: ./src
80112

81113
- name: Build
82-
run: |
83-
dotnet build $SOLUTION_NAME \
84-
--configuration $SOLUTION_CONFIGURATION \
85-
--no-restore
114+
run: dotnet build $SOLUTION_NAME --configuration $SOLUTION_CONFIGURATION --no-restore
86115
working-directory: ./src
87116

88-
- name: Unit Tests
117+
- name: Run Unit Tests
89118
run: |
90119
dotnet test $SOLUTION_NAME \
91120
--configuration $SOLUTION_CONFIGURATION \
92-
--no-build \
93121
--verbosity normal \
94122
--logger "trx;LogFilePrefix=Unit" \
95123
--collect:"XPlat Code Coverage;Format=opencover" \
96124
--filter "Category!=Integration"
97125
working-directory: ./src
98126

99-
- name: Integration Tests - Infrastructure
127+
- name: Collect Unit Test Coverage
128+
if: success() || failure()
129+
run: |
130+
mkdir -p ./coverage/unit
131+
find ./src -name "coverage.opencover.xml" -exec cp {} ./coverage/unit/ \;
132+
133+
- name: Upload Unit Test Coverage
134+
uses: actions/upload-artifact@v4
135+
with:
136+
name: unit-test-coverage
137+
path: ./coverage/unit
138+
139+
integration_tests:
140+
runs-on: ubuntu-latest
141+
concurrency:
142+
group: ${{ github.workflow }}-${{ github.ref }}
143+
cancel-in-progress: true
144+
steps:
145+
- name: PR - Checkout
146+
if: github.event_name == 'pull_request_target'
147+
uses: actions/checkout@v4
148+
with:
149+
fetch-depth: 0
150+
ref: ${{ github.event.pull_request.head.sha }}
151+
152+
- name: Checkout
153+
if: github.event_name != 'pull_request_target'
154+
uses: actions/checkout@v4
155+
with:
156+
fetch-depth: 0
157+
158+
- name: Setup .NET 8.0
159+
uses: actions/setup-dotnet@v4
160+
with:
161+
dotnet-version: 8.0.x
162+
cache: false
163+
164+
- name: Setup .NET 9.0
165+
uses: actions/setup-dotnet@v4
166+
with:
167+
dotnet-version: 9.0.x
168+
cache: false
169+
170+
# - name: SonarCloud - Setup Java17
171+
# #if: github.event_name == 'pull_request_target'
172+
# uses: actions/setup-java@v4
173+
# with:
174+
# distribution: "adopt"
175+
# java-version: "17"
176+
177+
# - name: Install SonarCloud Scanner
178+
# #if: github.event_name == 'pull_request_target'
179+
# run: dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner
180+
181+
# - name: SonarCloud - Begin Analysis
182+
# #if: github.event_name == 'pull_request_target'
183+
# env:
184+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
185+
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
186+
# run: |
187+
# params=""
188+
# pr_number="${{ github.event.pull_request.number }}"
189+
# if [[ -n "$pr_number" ]]; then
190+
# params="/d:sonar.pullrequest.key=${pr_number}"
191+
# fi
192+
# ../.sonar/scanner/dotnet-sonarscanner begin \
193+
# /k:"zarusz_SlimMessageBus" /o:"zarusz" \
194+
# /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
195+
# /d:sonar.host.url="https://sonarcloud.io" \
196+
# /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" \
197+
# /d:sonar.exclusions="Samples/**/*,Tests/**/*" \
198+
# $params
199+
# working-directory: ./src
200+
201+
- name: Restore Dependencies
202+
run: dotnet restore $SOLUTION_NAME --verbosity minimal
203+
working-directory: ./src
204+
205+
- name: Build
206+
run: dotnet build $SOLUTION_NAME --configuration $SOLUTION_CONFIGURATION --no-restore
207+
working-directory: ./src
208+
209+
- name: Run Integration Tests - Infrastructure Setup
100210
run: |
101211
docker compose -f src/Infrastructure/docker-compose.yml up --detach --force-recreate -V
102212
103-
- name: Integration Tests
213+
- name: Run Integration Tests
104214
run: |
105215
dotnet test $SOLUTION_NAME \
106216
--configuration $SOLUTION_CONFIGURATION \
107217
--no-build \
108-
--verbosity normal \
218+
--verbosity minimal \
109219
--logger "trx;LogFilePrefix=Integration" \
110220
--collect:"XPlat Code Coverage;Format=opencover" \
111221
--filter "Category=Integration"
@@ -158,54 +268,119 @@ jobs:
158268

159269
nats_endpoint: "nats://localhost:4222"
160270

161-
- name: SonarCloud - SonarScanner End
162-
#if: github.event_name == 'pull_request_target'
163-
env:
164-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
165-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
166-
run: ../.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
167-
working-directory: ./src
168-
169-
- name: Collect test results and rename
271+
- name: Collect Integration Test Coverage
170272
if: success() || failure()
171273
run: |
172-
mkdir -p ./test-results
173-
# Find all the .trx files recursively and copy them to the test-results folder
174-
# Use the grandparent directory name and filename
175-
find ./src -name "*.trx" | while read file; do
176-
# The grand parent will correspond to the csproj name e.g. SlimMessageBus.Host.Tests
177-
grandparent_dir=$(basename $(dirname $(dirname "$file")))
178-
filename=$(basename "$file")
179-
# Copy the file and use grandparent_dir and index as the new filename
180-
cp "$file" "./test-results/${grandparent_dir}_${filename}"
181-
done
182-
183-
- name: Upload Test Results
184-
if: success() || failure()
274+
mkdir -p ./coverage/integration
275+
find ./src -name "coverage.opencover.xml" -exec cp {} ./coverage/integration/ \;
276+
277+
- name: Upload Integration Test Coverage
185278
uses: actions/upload-artifact@v4
186279
with:
187-
name: test-results
188-
path: ./test-results
280+
name: integration-test-coverage
281+
path: ./coverage/integration
189282

190-
- name: Publish Test Results
191-
if: success() || failure()
192-
uses: dorny/test-reporter@v1
283+
sonarcloud_end:
284+
runs-on: ubuntu-latest
285+
needs: [build, unit_tests, integration_tests]
286+
steps:
287+
- name: Checkout
288+
uses: actions/checkout@v4
193289
with:
194-
name: .NET Tests
195-
path: ./test-results/*.trx
196-
reporter: dotnet-trx
197-
fail-on-error: true
290+
fetch-depth: 0
198291

199-
- name: Copy NuGet packages
200-
shell: bash
292+
- name: Setup Java for SonarCloud
293+
uses: actions/setup-java@v4
294+
with:
295+
distribution: "adopt"
296+
java-version: "17"
297+
298+
- name: Install SonarCloud Scanner
299+
run: dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner
300+
301+
- name: SonarCloud - Begin Analysis
302+
env:
303+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
304+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
201305
run: |
202-
mkdir ./dist
203-
find -name "*.nupkg" -exec cp {} ./dist \;
204-
find -name "*.snupkg" -exec cp {} ./dist \;
205-
find ./dist
306+
params=""
307+
pr_number="${{ github.event.pull_request.number }}"
308+
if [[ -n "$pr_number" ]]; then
309+
params="/d:sonar.pullrequest.key=${pr_number}"
310+
fi
311+
../.sonar/scanner/dotnet-sonarscanner begin \
312+
/k:"zarusz_SlimMessageBus" /o:"zarusz" \
313+
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
314+
/d:sonar.host.url="https://sonarcloud.io" \
315+
/d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" \
316+
/d:sonar.exclusions="Samples/**/*,Tests/**/*" \
317+
$params
318+
working-directory: ./src
206319

207-
- name: Archive NuGet packages
208-
uses: actions/upload-artifact@v4
320+
- name: Download Unit Test Coverage
321+
uses: actions/download-artifact@v4
209322
with:
210-
name: nuget-packages
211-
path: "./dist"
323+
name: unit-test-coverage
324+
path: ./coverage/unit
325+
326+
- name: Download Integration Test Coverage
327+
uses: actions/download-artifact@v4
328+
with:
329+
name: integration-test-coverage
330+
path: ./coverage/integration
331+
332+
- name: SonarCloud - End Analysis
333+
env:
334+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
335+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
336+
run: ../.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
337+
working-directory: ./src
338+
# finish:
339+
# runs-on: ubuntu-latest
340+
# concurrency:
341+
# group: ${{ github.workflow }}-${{ github.ref }}
342+
# cancel-in-progress: true
343+
# steps:
344+
# - name: Collect test results and rename
345+
# if: success() || failure()
346+
# run: |
347+
# mkdir -p ./test-results
348+
# # Find all the .trx files recursively and copy them to the test-results folder
349+
# # Use the grandparent directory name and filename
350+
# find ./src -name "*.trx" | while read file; do
351+
# # The grand parent will correspond to the csproj name e.g. SlimMessageBus.Host.Tests
352+
# grandparent_dir=$(basename $(dirname $(dirname "$file")))
353+
# filename=$(basename "$file")
354+
# # Copy the file and use grandparent_dir and index as the new filename
355+
# cp "$file" "./test-results/${grandparent_dir}_${filename}"
356+
# done
357+
358+
# - name: Upload Test Results
359+
# if: success() || failure()
360+
# uses: actions/upload-artifact@v4
361+
# with:
362+
# name: test-results
363+
# path: ./test-results
364+
365+
# - name: Publish Test Results
366+
# if: success() || failure()
367+
# uses: dorny/test-reporter@v1
368+
# with:
369+
# name: .NET Tests
370+
# path: ./test-results/*.trx
371+
# reporter: dotnet-trx
372+
# fail-on-error: true
373+
374+
# - name: Copy NuGet packages
375+
# shell: bash
376+
# run: |
377+
# mkdir ./dist
378+
# find -name "*.nupkg" -exec cp {} ./dist \;
379+
# find -name "*.snupkg" -exec cp {} ./dist \;
380+
# find ./dist
381+
382+
# - name: Archive NuGet packages
383+
# uses: actions/upload-artifact@v4
384+
# with:
385+
# name: nuget-packages
386+
# path: "./dist"

0 commit comments

Comments
 (0)