Skip to content

Commit 4ed1c86

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

File tree

1 file changed

+258
-82
lines changed

1 file changed

+258
-82
lines changed

.github/workflows/build.yml

Lines changed: 258 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,190 @@ 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 \
92121
--no-build \
93-
--verbosity normal \
122+
--verbosity minimal \
94123
--logger "trx;LogFilePrefix=Unit" \
95124
--collect:"XPlat Code Coverage;Format=opencover" \
96125
--filter "Category!=Integration"
97126
working-directory: ./src
98127

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

159270
nats_endpoint: "nats://localhost:4222"
160271

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
272+
- name: Collect Integration Test Coverage
170273
if: success() || failure()
171274
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()
275+
mkdir -p ./coverage/integration
276+
find ./src -name "coverage.opencover.xml" -exec cp {} ./coverage/integration/ \;
277+
278+
- name: Upload Integration Test Coverage
185279
uses: actions/upload-artifact@v4
186280
with:
187-
name: test-results
188-
path: ./test-results
281+
name: integration-test-coverage
282+
path: ./coverage/integration
189283

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

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

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

0 commit comments

Comments
 (0)