Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage CI created, hopefully it works first time lol #2990

Merged
merged 5 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .github/workflows/build-ubuntu-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# this workflow generates C code coverage information from the unit test
# suite. Note that for intrinsics, it only runs what gets compiled
# and would naturally run. It also is limited to what can run in
# a CI environment
# IMPORTANT: binaries are not to be uploaded from this workflow!

name: Ubuntu coverage

# Run CI only when a release is created, on changes to main branch, or any PR
# to main. Do not run CI on any other branch. Also, skip any non-source changes
# from running on CI
on:
push:
branches: main
paths-ignore:
- 'docs/**'
- 'examples/**'
- '.gitignore'
- '*.rst'
- '*.md'
- '.github/workflows/*.yml'
# gcov/lcov only gets C coverage
- 'src_py/**'
# re-include current file to not be excluded
- '!.github/workflows/build-ubuntu-coverage.yml'

pull_request:
branches: main
paths-ignore:
- 'docs/**'
- 'examples/**'
- '.gitignore'
- '*.rst'
- '*.md'
- '.github/workflows/*.yml'
# gcov/lcov only gets C coverage
- 'src_py/**'
# re-include current file to not be excluded
- '!.github/workflows/build-ubuntu-coverage.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-ubuntu-coverage
cancel-in-progress: true

jobs:
gen_coverage:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # if a particular matrix build fails, don't skip the rest
matrix:
os: [ubuntu-22.04]

steps:
- uses: actions/[email protected]

- name: Install deps
# install numpy from pip and not apt because the one from pip is newer,
# and has typestubs
# https://github.com/actions/runner-images/issues/7192
# https://github.com/orgs/community/discussions/47863
run: |
sudo apt-get update --fix-missing
sudo apt-get install lcov -y
sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libfreetype6-dev libportmidi-dev python3-dev -y
pip3 install --upgrade pip
pip3 install meson-python ninja cython "sphinx<=7.2.6" # because we are doing --no-build-isolation
pip3 install numpy>=1.21.0

- name: Build with coverage hooks and install
id: build
run: |
pip3 install -e . --no-build-isolation -Cbuild-dir=./.mesonpy-rel -Csetup-args=-Dcoverage=true

- name: Run tests
env:
SDL_VIDEODRIVER: "dummy"
SDL_AUDIODRIVER: "disk"
run: python3 -m pygame.tests -v --exclude opengl,music,timing --time_out 300

- name: Generate coverage
id: gen-coverage
# want to continue regardless of whether a test failed or not as long as the job wasn't cancelled
if: ${{ steps.build.conclusion == 'success' && !cancelled() }}
run: |
lcov --capture --directory . --output-file ./coverage.info
genhtml ./coverage.info --output-directory ./out

# We upload the generated files under github actions assets
- name: Upload coverage html
# want to continue only if the coverage generation was successful
if: ${{ steps.gen-coverage.conclusion == 'success' && !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: pygame-wheels-coverage
path: ./out
13 changes: 13 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ if not cc.has_header('Python.h', dependencies: py_dep)
)
endif

if get_option('coverage')
if cc.has_argument('--coverage')
add_global_arguments('--coverage', language: 'c')
else
error('Requested coverage but compiler doesn\'t seem to support it')
endif
if cc.has_link_argument('--coverage')
add_global_link_arguments('--coverage', language: 'c')
else
error('Requested coverage but compiler doesn\'t seem to support it')
endif
endif

pg_dir = py.get_install_dir() / pg

pg_inc_dirs = []
Expand Down
4 changes: 4 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ option('error_on_warns', type: 'boolean', value: 'false')
# Controls whether to error on build if generated docs are missing. Defaults to
# false.
option('error_docs_missing', type: 'boolean', value: 'false')

# Controls whether to do a coverage build.
# This argument must be used together with the editable install.
option('coverage', type: 'boolean', value: false)
Loading