HCV–automatic CI–part 6

I want the tests to be run automatically . And have a code coverage report. So Docker will be generating the report ( with coverlet.console and dotnet-reportgenerator-globaltool ). The GitHub Actions will be responsible with running this every time. The docs folder will be responsible of hosting it .

The code for docker resides in  \src\copyFilesToDocker.txt

FROM mcr.microsoft.com/dotnet/core/sdk:3.1
ENV NODE_ROOT usr/app/
WORKDIR $NODE_ROOT

COPY HealthCheckVersion .
RUN dotnet tool install –global coverlet.console –version 1.7.2
RUN dotnet tool install  -g dotnet-reportgenerator-globaltool –version 4.6.1
RUN dotnet test TestHealthCheckVersion/TestHealthCheckVersion.csproj –logger trx  –logger “console;verbosity=normal” –collect “Code coverage”
ENV PATH=”${PATH}:/root/.dotnet/tools”
RUN coverlet TestHealthCheckVersion/bin/Debug/netcoreapp3.1/TestHealthCheckVersion.dll –target “dotnet” –targetargs “test TestHealthCheckVersion/TestHealthCheckVersion.csproj –configuration Debug –no-build”  –format opencover –exclude “[xunit*]*” –exclude “[*]NetCoreTestProject*”
RUN reportgenerator “-reports:coverage.opencover.xml” “-targetdir:coveragereport” “-reporttypes:HTMLInline;HTMLSummary;Badges”
CMD tail -f /dev/null

The running  the docker is in \src\testNetCoreWin.bat

cls
ECHO please be aware of absolute path here %cd%
docker build -t testcinetcore -f copyFilesToDocker.txt .
docker run -d –name citest  testcinetcore
docker cp citest:/usr/app/coveragereport .
docker container kill citest
docker container rm citest

The code for Github CI is in \.github\workflows\docker-image.yml

name: GenerateCodeCoverage

on:

push:

branches: [ master ]

pull_request:

branches: [ master ]

jobs:

build:

runs-on: ubuntu-latest

steps:

– uses: actions/checkout@v2

– name: Build the Docker image for code coverage

run: |

cd src

chmod +777 ./testNetCoreWin.bat

./testNetCoreWin.bat

ls -lh

echo ‘copy’

cp -r  ./coveragereport/* ../docs/coveragereport/

rm -R ./coveragereport/

echo ‘in docs/coveragereport’

ls -lh ../docs/coveragereport/

echo ‘here’

ls -lh

– name: run commit

run: |

git config –local user.email “action@github.com”

git config –local user.name “GitHub Action”

git add –all

git status

git commit -m “generate code coverage” -a –allow-empty

#shell: cmd

– name: Push changes

uses: ad-m/github-push-action@master

with:

github_token: ${{ secrets.GITHUB_TOKEN }}

And now I can update readme with CI badge and code coverage test and badge

 

You can see the modifications at https://github.com/ignatandrei/HealthCheckVersion/tree/CI

HealthCheckVersion

Health Check for Version
 NameLink
1Idea and Githubhttp://msprogrammer.serviciipeweb.ro/2020/07/20/healthcheckversion-idea-part-1/
2Documentationhttp://msprogrammer.serviciipeweb.ro/2020/07/21/healthcheckversiondocumentation-part-2/
3Testshttp://msprogrammer.serviciipeweb.ro/2020/07/22/hcv-adding-testspart-3/
4Codehttp://msprogrammer.serviciipeweb.ro/2020/07/23/hcv-adding-codepart-4/
5Test Applicationhttp://msprogrammer.serviciipeweb.ro/2020/07/27/hcvadding-test-applicationpart-5/
6CIhttp://msprogrammer.serviciipeweb.ro/2020/07/28/hcvautomatic-cipart-6/
7NuGethttp://msprogrammer.serviciipeweb.ro/2020/07/29/hcvpreparing-for-nugetpart-7/
8PostMortemhttp://msprogrammer.serviciipeweb.ro/2020/07/30/hcv-postmortempart-8/