Implement SonarCloud integrations #215
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: SonarCloud | |
on: | |
workflow_dispatch: | |
# workflow_run: | |
# workflows: ["Pre-commit checks"] | |
# # branches: [main] | |
# types: [completed] | |
# push: | |
pull_request: | |
jobs: | |
# pre-commit-run: | |
# uses: minvws/nl-kat-coordination/.github/workflows/pre_commit_checks.yml@feature/sonar-cloud | |
# octopoes-tests: | |
# uses: minvws/nl-kat-coordination/.github/workflows/octopoes-tests.yml@feature/sonar-cloud | |
# bytes-tests: | |
# uses: minvws/nl-kat-coordination/.github/workflows/bytes-tests.yml@feature/sonar-cloud | |
mula-tests: | |
uses: minvws/nl-kat-coordination/.github/workflows/mula-tests.yml@feature/sonar-cloud | |
# rocky-tests: | |
# uses: minvws/nl-kat-coordination/.github/workflows/rocky-tests.yml@feature/sonar-cloud | |
# todo: bytes, rocky, mula, keiko, boefjes | |
# find-coverage-reports: | |
# runs-on: ubuntu-latest | |
# needs: mula-tests | |
# steps: | |
# - name: Download artifacts | |
# uses: actions/download-artifact@v4 | |
# with: | |
# pattern: "*-coverage-unit" | |
# - name: Get coverage files | |
# run: find . -name coverage.xml -exec dirname {} \; | xargs basename | xargs | jq -R -c 'split(" ")' | |
# - name: Fix coverage reports | |
# run: | | |
# sed -i 's|<source></source>|<source>/github/workspace/mula</source>|g' mula-coverage-unit/coverage.xml | |
fix-coverage-reports: | |
runs-on: ubuntu-latest | |
# needs: find-coverage-reports | |
needs: | |
# - octopoes-tests | |
- mula-tests | |
# - bytes-tests | |
# - rocky-tests | |
strategy: | |
matrix: | |
# module: ["octopoes", "mula", "rocky", "bytes"] | |
module: | |
- name: mula | |
prefix_path: "mula/scheduler/" | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ matrix.module['name'] }}-coverage-unit | |
path: ${{ matrix.module['name'] }}-coverage-unit | |
- run: tree . | |
# - name: Print | |
# run: cat "${{ github.workspace }}/${{ matrix.module }}-coverage-unit/coverage.xml" | |
- name: Print | |
run: cat "${{ github.workspace }}/${{ matrix.module['name'] }}-coverage-unit/coverage.xml" | |
- name: Fix coverage report | |
uses: Mudlet/xmlstarlet-action@master | |
with: | |
args: edit --inplace --update "coverage/sources" --value "/github/workspace/${{ matrix.module['name'] }}/" "${{ matrix.module['name'] }}-coverage-unit/coverage.xml" | |
# todo: find a way to fix the filename attribute in the coverage, these should be relative to the base dir and not the coverage source! | |
# - name: test mula | |
# id: test_mula | |
# if: ${{ matrix.module == 'mula' }} | |
# uses: Mudlet/xmlstarlet-action@master | |
# with: | |
# # args: edit --inplace --update "coverage/sources" --value "/github/workspace/${{ matrix.module }}/scheduler/" "${{ matrix.module }}-coverage-unit/coverage.xml" | |
# # args: edit --inplace --update "coverage/sources" --value "${{ matrix.module }}/scheduler/" "${{ matrix.module }}-coverage-unit/coverage.xml" | |
# args: edit --inplace --update "//class/@filename" --expr "concat('mula/scheduler/', .)" "${{ matrix.module }}-coverage-unit/coverage.xml" | |
# - name: fix via script | |
# if: ${{ matrix.module == 'mula' }} | |
# shell: python | |
# run: | | |
# #!/usr/bin/env python | |
# import xml.etree.ElementTree as etree | |
# from pathlib import Path | |
# def path_prefixer(file: Path, prefix: Path) -> None: | |
# xml = file.read_text() | |
# root = etree.fromstring(xml) | |
# for element in root.findall(".//*[@filename]"): | |
# element.set("filename", prefix.joinpath(element.get("filename")).as_posix()) | |
# file.write_text(etree.tostring(root).decode()) | |
# path_prefixer(Path("${{ matrix.module }}-coverage-unit/coverage.xml"), Path("mula/scheduler/")) | |
# - name: fix via script | |
# if: ${{ matrix.module == 'bytes' }} | |
# shell: python | |
# run: | | |
# #!/usr/bin/env python | |
# import xml.etree.ElementTree as etree | |
# from pathlib import Path | |
# def path_prefixer(file: Path, prefix: Path) -> None: | |
# xml = file.read_text() | |
# root = etree.fromstring(xml) | |
# for element in root.findall(".//*[@filename]"): | |
# element.set("filename", prefix.joinpath(element.get("filename")).as_posix()) | |
# file.write_text(etree.tostring(root).decode()) | |
# path_prefixer(Path("${{ matrix.module }}-coverage-unit/coverage.xml"), Path("bytes/")) | |
# - name: fix via script | |
# if: ${{ matrix.module == 'rocky' }} | |
# shell: python | |
# run: | | |
# #!/usr/bin/env python | |
# import xml.etree.ElementTree as etree | |
# from pathlib import Path | |
# def path_prefixer(file: Path, prefix: Path) -> None: | |
# xml = file.read_text() | |
# root = etree.fromstring(xml) | |
# for element in root.findall(".//*[@filename]"): | |
# element.set("filename", prefix.joinpath(element.get("filename")).as_posix()) | |
# file.write_text(etree.tostring(root).decode()) | |
# path_prefixer(Path("${{ matrix.module }}-coverage-unit/coverage.xml"), Path("rocky/")) | |
- name: Fix via external script | |
run: python .github/scripts/fix_coverage.py "${{ matrix.module['name'] }}-coverage-unit/coverage.xml" "${{ matrix.module['prefix_path'] }}" | |
- name: Print | |
run: cat "${{ matrix.module['name'] }}-coverage-unit/coverage.xml" | |
- name: Upload coverage as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: "${{ matrix.module['name'] }}-coverage-unit-fixed" | |
path: "${{ matrix.module['name'] }}-coverage-unit/coverage.xml" | |
sonar-cloud: | |
runs-on: ubuntu-latest | |
# needs: pre-commit-run | |
needs: | |
# - octopoes-tests | |
# - bytes-tests | |
# - mula-tests | |
- fix-coverage-reports | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: "*-coverage-unit-fixed" | |
# workaround for https://sonarsource.atlassian.net/browse/SONARPY-1203 | |
# and https://community.sonarsource.com/t/sonar-on-github-actions-with-python-coverage-source-issue/36057 | |
# - name: Override coverage Source Path for Sonar | |
# run: sed -i 's/home\/runner\/work\/nl-kat-coordination\/nl-kat-coordination/github\/workspace/' *-coverage-unit/coverage.xml | |
# - name: test | |
# run: sed -i 's|<source></source>|<source>/github/workspace/mula</source>|g' mula-coverage-unit/coverage.xml | |
# todo: create a job matrix for fixing all the coverage.xml file sources | |
# todo: https://github.com/Mudlet/xmlstarlet-action | |
# todo: cat coverage.xml | xml ed --inplace --update "coverage/sources" --value "test" | head | |
- run: pwd && tree . | |
- run: cat *-coverage-unit-fixed/coverage.xml | |
- name: SonarCloud | |
uses: SonarSource/[email protected] | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |