deskflow/.github/workflows/valgrind-analysis.yml
Nick Bolton 47849db4d9
Run Valgrind on unit tests in CI to detect memory leaks (#7401)
* Move QApplication out of main to reduce memory impact when running individual tests

* Add --valgrind arg and colorize output when command returns non-zero exit code

* Fixed: colorama not always available

* Test multiple Qt tests

* Fixed: Windows Qt test failing due to missing QCoreApplication

* Simplify fake args for Qt

* Use --ci-env arg

* Create Valgrind analysis workflow

* Rename vars for fake args

* Parse and output valgrind summary

* Add build mode to comment

* Use GITHUB_OUTPUT to output summary

* Merge valgrind comment

* Improve comment

* Use `tee` instead of `--log-file` to also print stdout

* Improve comment about debug and release

* Simplify output writing in parse step

* Improve step name

* Correct comment about summaries

* Remove commented out code

* Better var name

* Missing copyright

* Rename global to shared

* Remove space

* Revert change to ConfigTests.cpp
2024-07-17 09:22:46 +01:00

75 lines
2 KiB
YAML

name: "Valgrind Analysis"
on:
workflow_dispatch:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
concurrency:
group: "${{ github.workflow }}-${{ github.ref || github.run_id }}"
cancel-in-progress: true
jobs:
valgrind-analysis:
runs-on: ubuntu-latest
container: symless/synergy-core:ubuntu-22.04-amd64
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: "recursive"
- name: Config Git safe dir
run: git config --global --add safe.directory $GITHUB_WORKSPACE
- name: Install dependencies
run: |
./scripts/install_deps.py --ci-env &&
apt install valgrind -y
- name: Configure
run: cmake -B build --preset=linux-release
- name: Build
run: cmake --build build -j8
- name: Run Valgrind on unit tests
env:
QT_QPA_PLATFORM: offscreen
run: |
valgrind \
--leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--verbose \
./build/bin/unittests \
2>&1 | tee valgrind.log
- name: Parse summary
id: parse
run: |
echo "summary<<EOF" >> $GITHUB_OUTPUT
echo "$(grep -A 2 "HEAP SUMMARY:" valgrind.log)" >> $GITHUB_OUTPUT
echo >> $GITHUB_OUTPUT
echo "$(awk '/LEAK SUMMARY/,/ERROR SUMMARY/' valgrind.log)" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Append to PR comment
uses: marocchino/sticky-pull-request-comment@v2
env:
URL: https://github.com/symless/synergy-core/actions/workflows/valgrind-analysis.yml
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
recreate: true
message: |
## Valgrind summary
See [workflow output](${{ env.URL }}) for full `valgrind` output.
```
${{ steps.parse.outputs.summary }}
```