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_ROOTCOPY 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
Leave a Reply