WIP: fix ci: pass coverage.xml to sonar-scanner #106

Draft
alexoundos wants to merge 5 commits from coverage-for-sonar into master
2 changed files with 8 additions and 5 deletions

View File

@ -5,8 +5,8 @@ name: default
steps:
- name: Run Tests and Generate Coverage Report
commands:
- nix flake check -L
- sonar-scanner -Dsonar.projectKey=SelfPrivacy-REST-API -Dsonar.sources=. -Dsonar.host.url=http://analyzer.lan:9000 -Dsonar.login="$SONARQUBE_TOKEN"
- VM_TEST_OUT_PATH="$(nix build .#checks.x86_64-linux.default --no-link --print-out-paths --print-build-logs)"

Will this command consistently output path? It seems like it should output a lot of other things too.

Will this command consistently output path? It seems like it should output a lot of other things too.

Yes. It outputs output path to stdout and other stuff to stderr.

Yes. It outputs output path to stdout and other stuff to stderr.

Why asking it to print logs if we only need path?

Why asking it to print logs if we only need path?

For us to see what pytest/coverage prints (lines with test name and percentage). Otherwise, it's silent about progress and it's especially tedious having tests running so slowly (~25 minutes).

For us to see what pytest/coverage prints (lines with test name and percentage). Otherwise, it's silent about progress and it's especially tedious having tests running so slowly (~25 minutes).
- sonar-scanner -Dsonar.projectKey=SelfPrivacy-REST-API -Dsonar.sources="$PWD" -Dsonar.host.url=http://analyzer.lan:9000 -Dsonar.login="$SONARQUBE_TOKEN" -Dsonar.python.coverage.reportPaths="$VM_TEST_OUT_PATH/coverage.xml" -Dsonar.python.version=3.10
environment:
SONARQUBE_TOKEN:
from_secret: SONARQUBE_TOKEN

View File

@ -85,6 +85,7 @@
rclone
redis
restic
sonar-scanner-cli
self.packages.${system}.pytest-vm
# FIXME consider loading this explicitly only after ArchLinux issue is solved
self.checks.x86_64-linux.default.driverInteractive
@ -150,9 +151,11 @@
testScript = ''
start_all()
machine.succeed("cd ${vmtest-src-dir} && coverage run --data-file=/tmp/.coverage -m pytest -p no:cacheprovider -v >&2")
machine.succeed("coverage xml --rcfile=${vmtest-src-dir}/.coveragerc --data-file=/tmp/.coverage >&2")
machine.copy_from_vm("coverage.xml", ".")
machine.succeed("coverage report >&2")
machine.succeed("cd ${vmtest-src-dir} && coverage xml --data-file=/tmp/.coverage -o /tmp/coverage.xml >&2")
machine.succeed("head /tmp/coverage.xml >&2")
machine.succeed("sed -i -E 's|<source>${pkgs.lib.strings.escapeRegex self.outPath}</source>|<source>.</source>|g' /tmp/coverage.xml")
machine.copy_from_vm("/tmp/coverage.xml", ".")
machine.succeed("coverage report --rcfile=.coveragerc --data-file=/tmp/.coverage >&2")
'';
};
};