Skip to content

Bazel CI test report #119

Bazel CI test report

Bazel CI test report #119

name: Bazel CI test report
on:
workflow_run:
# Trigger after ci.yml completes; this means that ci-bazel.yml (invoked by it) has also completed.
workflows: [ "C/C\\+\\+ and Bazel CI" ]
# This should trigger on both completed and failed runs by passing just [ completed ]. TODO: confirm
types: [ completed ]
permissions:
checks: write
# Set some global arguments, e.g. whether to enable or disable coverage
# collection:
env:
ENABLE_BAZEL_COVERAGE: true # TODO: This should be set only in the ci-bazel.yml (which is included from ci.yml) and passed here.
# End arguments section.
jobs:
checks:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: minimal-regular
place: regular
short_name: minimal
os: " ubuntu-latest"
- name: util-regular
place: regular
short_name: util
os: " ubuntu-latest"
- name: minimal-buildbuddy
place: buildbuddy
short_name: minimal
os: ""
- name: util-buildbuddy
place: buildbuddy
short_name: util
os: ""
steps:
- name: Download Test Report
uses: dawidd6/action-download-artifact@v19
with:
name: junit-test-results-${{ matrix.place }}-${{ matrix.short_name }} test${{ matrix.os }}
workflow: ${{ github.event.workflow.id }}
run_id: ${{ github.event.workflow_run.id }}
- name: Publish Test Report
uses: mikepenz/action-junit-report@v6
# if we integrate into main bit instead of having a separate workflow:
# if: success() || failure() # always run even if the previous step fails
with:
commit: ${{github.event.workflow_run.head_sha}} # remove if we don't use separate workflow
# some_file.zip/minimal_test/test.xml
report_paths: '**/test.xml'
- name: Download lcov Coverage Report
uses: dawidd6/action-download-artifact@v19
# Run only if coverage is enabled and not on Windows artifacts.
if: env.ENABLE_BAZEL_COVERAGE == 'true' && !contains(matrix.os, 'windows')
with:
name: lcov-coverage-results-${{ matrix.place }}-${{ matrix.short_name }} test${{ matrix.os }}
workflow: ${{ github.event.workflow.id }}
run_id: ${{ github.event.workflow_run.id }}
- name: Install Python for lcov to Cobertura conversion run
uses: actions/setup-python@v6
# Run only if coverage is enabled and not on Windows artifacts.
if: env.ENABLE_BAZEL_COVERAGE == 'true' && !contains(matrix.os, 'windows')
with:
python-version: '3.11'
- name: Convert lcov to Cobertura XML
if: env.ENABLE_BAZEL_COVERAGE == 'true' && !contains(matrix.os, 'windows') # Run only if coverage is enabled and not on Windows artifacts.
# Script to use: https://raw.githubusercontent.com/eriwen/lcov-to-cobertura-xml/85f51dfd646fadf534ce2bd636befeec37148ff9/lcov_cobertura/lcov_cobertura.py
# Readme gives these examples:
# python lcov_cobertura.py lcov-file.dat
# -b/--base-dir - (Optional) Directory where source files are located. Defaults to the current directory
# -e/--excludes - (Optional) Comma-separated list of regexes of packages to exclude
# -o/--output - (Optional) Path to store cobertura xml file. Defaults to ./coverage.xml
# -d/--demangle - (Optional) Demangle C++ function names. Requires c++filt
# python lcov_cobertura.py lcov-file.dat --base-dir src/dir --excludes test.lib --output build/coverage.xml --demangle
# and also mentions installing via pip (lcov_cobertura, same name for binary)
# Requires Python 3.8+.
# Last version for Python 2.x was 1.6.
run: |
python3 -m pip install --upgrade pip
python3 -m pip install lcov_cobertura==2.0.2
# Locate the installed script using the same python3 that installed the package,
# so the interpreter and site-packages are guaranteed to match.
LCOV_COBERTURA_SCRIPT=$(python3 -c "import importlib.util; print(importlib.util.find_spec('lcov_cobertura.lcov_cobertura').origin)")
# TODO: change to output coverage.xml, not coverage.dat.xml, and update the rest of the workflow accordingly.
find ./ -name 'coverage.dat' -exec python3 "$LCOV_COBERTURA_SCRIPT" {} --output {}.xml \;
- name: Upload Cobertura Coverage Report
uses: actions/upload-artifact@v7
with:
name: cobertura-coverage-results-${{ matrix.place }}-${{ matrix.short_name }} test${{ matrix.os }}
path: './**/coverage.dat.xml'
if: always() && env.ENABLE_BAZEL_COVERAGE == 'true' && !contains(matrix.os, 'windows') # Run even if the previous step fails
- name: Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
if: env.ENABLE_BAZEL_COVERAGE == 'true' && !contains(matrix.os, 'windows') # Run only if coverage is enabled and not on Windows artifacts.
with:
filename: ./*/coverage.dat.xml
badge: true
#fail_below_min: true
fail_below_min: false # Flippable once we have builds clearly passing this.
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'
- name: Post coverage report as comment
uses: marocchino/sticky-pull-request-comment@v3
if: github.event_name == 'pull_request' && env.ENABLE_BAZEL_COVERAGE == 'true' && !contains(matrix.os, 'windows') # Run only on PRs and if coverage is enabled and not on Windows artifacts.
with:
recreate: true
header: coverage
path: code-coverage-results.md
- name: Add coverage report to job summary
if: env.ENABLE_BAZEL_COVERAGE == 'true' && !contains(matrix.os, 'windows') # Run only if coverage is enabled and not on Windows artifacts.
run: |
cat code-coverage-results.md >> "$GITHUB_STEP_SUMMARY"