From 88f3660ad62220348b17ba861607bc919be36d48 Mon Sep 17 00:00:00 2001 From: Andrew Coffey Date: Sat, 13 Jul 2024 12:58:02 -0500 Subject: [PATCH 1/4] Coverage CI created, hopefully it works first time lol --- .github/workflows/build-ubuntu-coverage.yml | 96 +++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/build-ubuntu-coverage.yml diff --git a/.github/workflows/build-ubuntu-coverage.yml b/.github/workflows/build-ubuntu-coverage.yml new file mode 100644 index 0000000000..c8ee649e44 --- /dev/null +++ b/.github/workflows/build-ubuntu-coverage.yml @@ -0,0 +1,96 @@ +# 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' + # re-include current file to not be excluded + - '!.github/workflows/build-ubuntu-coverage.yml' + + # the github release drafter can call this workflow + workflow_call: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-ubuntu-coverage + cancel-in-progress: true + +jobs: + gen_coverage: + env: + CFLAGS: "-coverage" + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false # if a particular matrix build fails, don't skip the rest + matrix: + os: [ubuntu-20.04] + + steps: + - uses: actions/checkout@v4.1.7 + + - 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 build numpy>=1.21.0 cython + + - name: Build with coverage hooks and install + run: | + python3 setup.py build_ext --inplace + python3 setup.py install --user + + - 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 + if: always() + run: | + lcov --capture --directory . --output-file coverage.info + genhtml coverage.info --output-directory ${{ github.workspace}}/out + + # We upload the generated files under github actions assets + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: pygame-wheels-coverage + path: ${{ github.workspace }}/out + compression-level: 0 # already compressed, no need for more compression + From 1cca3e7de9368da3ee4462e0f617b26e79ae6f7c Mon Sep 17 00:00:00 2001 From: Ankith Date: Mon, 15 Jul 2024 22:05:53 +0530 Subject: [PATCH 2/4] Do coverage build with meson --- .github/workflows/build-ubuntu-coverage.yml | 12 ++++-------- meson.build | 13 +++++++++++++ meson_options.txt | 4 ++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-ubuntu-coverage.yml b/.github/workflows/build-ubuntu-coverage.yml index c8ee649e44..908f6621b2 100644 --- a/.github/workflows/build-ubuntu-coverage.yml +++ b/.github/workflows/build-ubuntu-coverage.yml @@ -45,13 +45,11 @@ concurrency: jobs: gen_coverage: - env: - CFLAGS: "-coverage" runs-on: ${{ matrix.os }} strategy: fail-fast: false # if a particular matrix build fails, don't skip the rest matrix: - os: [ubuntu-20.04] + os: [ubuntu-22.04] steps: - uses: actions/checkout@v4.1.7 @@ -66,12 +64,12 @@ jobs: 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 build numpy>=1.21.0 cython + 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 run: | - python3 setup.py build_ext --inplace - python3 setup.py install --user + pip3 install -e . --no-build-isolation -Cbuild-dir=.mesonpy-rel -Csetup-args=-Dcoverage=true - name: Run tests env: @@ -92,5 +90,3 @@ jobs: with: name: pygame-wheels-coverage path: ${{ github.workspace }}/out - compression-level: 0 # already compressed, no need for more compression - diff --git a/meson.build b/meson.build index cc70486f2e..a3b139c593 100644 --- a/meson.build +++ b/meson.build @@ -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 = [] diff --git a/meson_options.txt b/meson_options.txt index c34007090a..3152e69736 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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) From b62ed96f7f22e44ebf79726a42a02b0e0f8760de Mon Sep 17 00:00:00 2001 From: Andrew Coffey Date: Sat, 20 Jul 2024 09:45:40 -0500 Subject: [PATCH 3/4] minor cleanups on the coverage action --- .github/workflows/build-ubuntu-coverage.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-ubuntu-coverage.yml b/.github/workflows/build-ubuntu-coverage.yml index 908f6621b2..12a1d844f0 100644 --- a/.github/workflows/build-ubuntu-coverage.yml +++ b/.github/workflows/build-ubuntu-coverage.yml @@ -33,6 +33,8 @@ on: - '*.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' @@ -68,8 +70,9 @@ jobs: 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 + pip3 install -e ${{ github.workspace }} --no-build-isolation -Cbuild-dir=${{ github.workspace }}/.mesonpy-rel -Csetup-args=-Dcoverage=true - name: Run tests env: @@ -78,14 +81,17 @@ jobs: run: python3 -m pygame.tests -v --exclude opengl,music,timing --time_out 300 - name: Generate coverage - if: always() + 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 ${{ github.workspace}}/out + lcov --capture --directory ${{ github.workspace }}/ --output-file ${{ github.workspace }}/coverage.info + genhtml ${{ github.workspace }}/coverage.info --output-directory ${{ github.workspace }}/out # We upload the generated files under github actions assets - - name: Upload coverage - if: always() + - 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 From e04c75a280a10fc03646b5244e39cce20080fce7 Mon Sep 17 00:00:00 2001 From: Andrew Coffey Date: Wed, 14 Aug 2024 19:48:28 -0500 Subject: [PATCH 4/4] Remove unnecessary parts of action --- .github/workflows/build-ubuntu-coverage.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-ubuntu-coverage.yml b/.github/workflows/build-ubuntu-coverage.yml index 12a1d844f0..b01f623c2f 100644 --- a/.github/workflows/build-ubuntu-coverage.yml +++ b/.github/workflows/build-ubuntu-coverage.yml @@ -38,9 +38,6 @@ on: # re-include current file to not be excluded - '!.github/workflows/build-ubuntu-coverage.yml' - # the github release drafter can call this workflow - workflow_call: - concurrency: group: ${{ github.workflow }}-${{ github.ref }}-ubuntu-coverage cancel-in-progress: true @@ -72,7 +69,7 @@ jobs: - name: Build with coverage hooks and install id: build run: | - pip3 install -e ${{ github.workspace }} --no-build-isolation -Cbuild-dir=${{ github.workspace }}/.mesonpy-rel -Csetup-args=-Dcoverage=true + pip3 install -e . --no-build-isolation -Cbuild-dir=./.mesonpy-rel -Csetup-args=-Dcoverage=true - name: Run tests env: @@ -85,8 +82,8 @@ jobs: # 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 ${{ github.workspace }}/ --output-file ${{ github.workspace }}/coverage.info - genhtml ${{ github.workspace }}/coverage.info --output-directory ${{ github.workspace }}/out + 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 @@ -95,4 +92,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: pygame-wheels-coverage - path: ${{ github.workspace }}/out + path: ./out