diff --git a/.github/workflows/build-ubuntu-coverage.yml b/.github/workflows/build-ubuntu-coverage.yml deleted file mode 100644 index 680481ba82..0000000000 --- a/.github/workflows/build-ubuntu-coverage.yml +++ /dev/null @@ -1,97 +0,0 @@ -# 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 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-24.04] - - env: - # Pip now forces us to either make a venv or set this flag, so we will do - # this - PIP_BREAK_SYSTEM_PACKAGES: 1 - # We are using dependencies installed from apt - PG_DEPS_FROM_SYSTEM: 1 - - steps: - - uses: actions/checkout@v4.2.2 - - - name: Install deps - # 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 - - - name: Build with coverage hooks and install - id: build - run: | - python3 dev.py build --coverage - - - 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 diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml deleted file mode 100644 index 2594db25d7..0000000000 --- a/.github/workflows/cppcheck.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: cppcheck Static Analysis - -# Run cppcheck on src_c changes to main branch, or any PR to main. -on: - push: - branches: main - paths: - - 'src_c/**' - - pull_request: - branches: main - paths: - - 'src_c/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-cppcheck - cancel-in-progress: true - -# TODO: Any more static checkers can be added here -jobs: - run-cppcheck: - runs-on: ubuntu-24.04 - - steps: - - uses: actions/checkout@v4.2.2 - - - name: Install deps - # https://github.com/actions/runner-images/issues/7192 - # https://github.com/orgs/community/discussions/47863 - run: | - sudo apt-get update --fix-missing - sudo apt install cppcheck - - - name: Run Static Checker - # skip cppcheck on SDL_gfx, scrap, scale_mm* and ft_cache for now - # suppress missingReturn and syntaxError because it gives many false positives - run: cppcheck src_c --enable=performance,portability,warning \ - --suppress=*:src_c/freetype/ft_cache.c --suppress=*:src_c/scrap* \ - --suppress=*:src_c/scale_mmx*.c --suppress=*:src_c/SDL_gfx/* \ - --suppress=missingReturn --suppress=syntaxError -DWITH_THREAD -j $(nproc) \ - -DPG_MAJOR_VERSION -DPG_MINOR_VERSION -DPG_PATCH_VERSION -DPG_VERSION_TAG diff --git a/.github/workflows/build-ubuntu-debug-python.yml b/.github/workflows/run-ubuntu-checks.yml similarity index 57% rename from .github/workflows/build-ubuntu-debug-python.yml rename to .github/workflows/run-ubuntu-checks.yml index b1c24766e5..06eb1ccbd6 100644 --- a/.github/workflows/build-ubuntu-debug-python.yml +++ b/.github/workflows/run-ubuntu-checks.yml @@ -1,10 +1,13 @@ -# This workflow runs a build with a python version that has debug symbols +# This workflow runs a build with a python version that has debug symbols. +# Also generates coverage information from unit tests. 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. # Update this workflow when our min/max python minor versions update # This workflow is necessary to ensure that we can build and run with # a debug python build without too much worrying about SIGABRT being thrown # IMPORTANT: binaries are not to be uploaded from this workflow! -name: Ubuntu debug python +name: Ubuntu Checks defaults: run: shell: bash -leo pipefail {0} @@ -23,7 +26,7 @@ on: - '*.md' - '.github/workflows/*.yml' # re-include current file to not be excluded - - '!.github/workflows/build-ubuntu-debug-python.yml' + - '!.github/workflows/run-ubuntu-checks.yml' pull_request: branches: main @@ -35,14 +38,14 @@ on: - '*.md' - '.github/workflows/*.yml' # re-include current file to not be excluded - - '!.github/workflows/build-ubuntu-debug-python.yml' + - '!.github/workflows/run-ubuntu-checks.yml' concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-ubuntu-debug-python + group: ${{ github.workflow }}-${{ github.ref }}-ubuntu-checks cancel-in-progress: true jobs: - debug_python: + debug_coverage: runs-on: ${{ matrix.os }} strategy: fail-fast: false # if a particular matrix build fails, don't skip the rest @@ -69,7 +72,7 @@ jobs: # 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 -y - name: Install pyenv @@ -98,7 +101,7 @@ jobs: id: build-pygame-ce run: | pyenv global ${{ matrix.python }}-debug - python dev.py build --lax + python dev.py build --lax --coverage - name: Run tests env: @@ -107,3 +110,50 @@ jobs: run: | pyenv global ${{ matrix.python }}-debug python -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-pygame-ce.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-coverage-${{ matrix.os }}-${{ matrix.python }} + path: ./out + + # Run cppcheck static analysis on src_c changes + run-cppcheck: + runs-on: ubuntu-24.04 + needs: debug_coverage + + steps: + - uses: actions/checkout@v4.2.2 + + - name: Check if any src_c files changed + id: check-changes + run: | + git fetch origin ${{ github.base_ref }} --depth=1 || true + git checkout ${{ github.base_ref }} + CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD) + echo "$CHANGED_FILES" | grep '^src_c/' || echo "skip=true" >> "$GITHUB_OUTPUT" + + - name: Install cppcheck + if: steps.check-changes.outputs.skip != 'true' + run: | + sudo apt-get update --fix-missing + sudo apt install cppcheck + + - name: Run Static Checker + if: steps.check-changes.outputs.skip != 'true' + run: cppcheck src_c --enable=performance,portability,warning \ + --suppress=*:src_c/freetype/ft_cache.c --suppress=*:src_c/scrap* \ + --suppress=*:src_c/scale_mmx*.c --suppress=*:src_c/SDL_gfx/* \ + --suppress=missingReturn --suppress=syntaxError -DWITH_THREAD -j $(nproc) \ + -DPG_MAJOR_VERSION -DPG_MINOR_VERSION -DPG_PATCH_VERSION -DPG_VERSION_TAG