Skip to content

Commit f7d1cfb

Browse files
Merge pull request #6 from EugeneKisel-sm/code-coverage
Code coverage
2 parents 33630fd + 135b5c6 commit f7d1cfb

4 files changed

Lines changed: 64 additions & 12 deletions

File tree

.github/workflows/pull_request.yml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: CI Build
22

3+
# Cancel older, in-progress CI runs on the same branch/PR
4+
concurrency:
5+
group: ci-${{ github.head_ref || github.run_id }}
6+
cancel-in-progress: true
7+
38
on:
49
push:
510
branches:
@@ -14,23 +19,51 @@ jobs:
1419
runs-on: ubuntu-latest
1520
steps:
1621
- name: Checkout
17-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
1823
- name: Linter
1924
run: >
2025
DOCKER_BUILDKIT=1 docker build
2126
--target=linter
2227
--progress=plain
2328
.
24-
test:
29+
30+
test_and_coverage:
31+
needs: lint
2532
runs-on: ubuntu-latest
2633
steps:
2734
- name: Checkout
28-
uses: actions/checkout@v3
29-
- name: Test
35+
uses: actions/checkout@v4
36+
- name: Test and collect coverage
37+
continue-on-error: true
3038
run: >
3139
DOCKER_BUILDKIT=1 docker build
32-
--target=test
40+
--target=coverage_export
41+
--output type=local,dest=coverage
3342
--build-arg KEY=${{ secrets.KEY }}
3443
--build-arg SECRET=${{ secrets.SECRET }}
3544
--build-arg CONDUCTOR_SERVER_URL=${{ secrets.CONDUCTOR_SERVER_URL }}
3645
.
46+
47+
# Always upload the XML, even if tests failed
48+
- name: Upload Cobertura artifact
49+
if: ${{ !env.ACT }}
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: cobertura
53+
path: coverage/out/coverage.cobertura.xml
54+
55+
- name: Ensure coverage file exists
56+
run: |
57+
mkdir -p coverage
58+
if [ ! -f coverage/out/coverage.cobertura.xml ]; then
59+
echo '<coverage></coverage>' > coverage/out/coverage.cobertura.xml
60+
fi
61+
62+
- name: Codecov upload
63+
if: ${{ !env.ACT }}
64+
uses: codecov/codecov-action@v5
65+
with:
66+
token: ${{ secrets.CODECOV_TOKEN }}
67+
files: coverage/out/coverage.cobertura.xml
68+
flags: unittests
69+
name: ${{ github.workflow }}-${{ github.job }}-${{ github.run_number }}

Dockerfile

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,39 @@ RUN dotnet format --verify-no-changes *.csproj
1010
FROM csharp-sdk AS build
1111
RUN dotnet build *.csproj
1212

13-
FROM build as test
13+
FROM build AS test
1414
ARG KEY
1515
ARG SECRET
1616
ARG CONDUCTOR_SERVER_URL
1717
ENV CONDUCTOR_AUTH_KEY=${KEY}
1818
ENV CONDUCTOR_AUTH_SECRET=${SECRET}
1919
ENV CONDUCTOR_SERVER_URL=${CONDUCTOR_SERVER_URL}
20+
2021
COPY /csharp-examples /package/csharp-examples
21-
COPY /Tests /package/Tests
22+
COPY /Tests /package/Tests
2223
WORKDIR /package/Tests
23-
RUN dotnet test -p:DefineConstants=EXCLUDE_EXAMPLE_WORKERS -l "console;verbosity=normal"
24+
# collect coverage while testing
25+
RUN dotnet test -p:DefineConstants=EXCLUDE_EXAMPLE_WORKERS \
26+
--collect:"XPlat Code Coverage" \
27+
-l "console;verbosity=normal" \
28+
|| true
29+
30+
########## coverage_export ##########
31+
FROM test AS coverage_export
32+
RUN mkdir /out \
33+
&& cp $(find /package/Tests/TestResults -name 'coverage.cobertura.xml' | head -n 1) \
34+
/out/coverage.cobertura.xml
2435

25-
FROM build as pack_release
36+
FROM build AS pack_release
2637
ARG SDK_VERSION
27-
RUN dotnet pack "conductor-csharp.csproj" \
38+
RUN dotnet pack conductor-csharp.csproj \
2839
-o /build \
2940
--include-symbols \
3041
--include-source \
31-
-c Release "/p:Version=${SDK_VERSION}"
42+
-c Release \
43+
"/p:Version=${SDK_VERSION}"
3244

33-
FROM pack_release as publish_release
45+
FROM pack_release AS publish_release
3446
ARG NUGET_SRC
3547
ARG NUGET_API_KEY
3648
RUN dotnet nuget push "/build/*.symbols.nupkg" \

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Conductor OSS C# SDK
22

3+
[![CI](https://github.com/EugeneKisel-sm/csharp-sdk/actions/workflows/pull_request.yml/badge.svg)](https://github.com/EugeneKisel-sm/csharp-sdk/actions)
4+
[![Coverage](https://codecov.io/gh/EugeneKisel-sm/csharp-sdk/branch/main/graph/badge.svg?token=N14BNYZP6Q)](https://codecov.io/gh/EugeneKisel-sm/csharp-sdk)
5+
36
The conductor-csharp repository provides the client SDKs to build task workers in C#.
47

58
Building the task workers in C# mainly consists of the following steps:

Tests/conductor-csharp.test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
<TargetFramework>net8.0</TargetFramework>
44
</PropertyGroup>
55
<ItemGroup>
6+
<PackageReference Include="coverlet.collector" Version="6.0.4">
7+
<PrivateAssets>all</PrivateAssets>
8+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
9+
</PackageReference>
610
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
711
<PackageReference Include="System.Text.Json" Version="8.0.5" />
812
<PackageReference Include="xunit" Version="2.4.2" />

0 commit comments

Comments
 (0)