From 8abf0da90084b9f5a856a813692195d2d83b1636 Mon Sep 17 00:00:00 2001
From: Yannick Jadoul <yannick.jadoul@belgacom.net>
Date: Fri, 15 Jan 2021 14:56:58 +0100
Subject: [PATCH] Merge Valgrind and other deadsnakes builds

---
 .github/workflows/ci.yml | 77 +++++++++++++---------------------------
 1 file changed, 25 insertions(+), 52 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 09cf522037..23dfbb0c99 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -164,23 +164,35 @@ jobs:
     - name: Setuptools helpers test
       run: pytest tests/extra_setuptools
 
-  valgrind:
+
+  deadsnakes:
+    strategy:
+      fail-fast: false
+      matrix:
+        include:
+        - python-version: 3.9
+          python-debug: true
+          valgrind: true
+        - python-version: 3.10-dev
+          python-debug: false
+
+    name: "🐍 ${{ matrix.python-version }}${{ matrix.python-debug && '-dbg' || '' }} (deadsnakes)${{ matrix.valgrind && ' • Valgrind' || '' }} • x64"
     runs-on: ubuntu-latest
-    name: "🐍 3.9 (debug) • Valgrind"
 
     steps:
     - uses: actions/checkout@v2
 
-    - name: Install debug Python
+    - name: Setup Python ${{ matrix.python-version }} (deadsnakes)
       uses: deadsnakes/action@v2.1.1
       with:
-        python-version: 3.9
-        debug: true
+        python-version: ${{ matrix.python-version }}
+        debug: ${{ matrix.python-debug }}
 
     - name: Update CMake
       uses: jwlawson/actions-setup-cmake@v1.6
 
     - name: Valgrind cache
+      if: matrix.valgrind
       uses: actions/cache@v2
       id: cache-valgrind
       with:
@@ -188,7 +200,7 @@ jobs:
         key: 3.16.1 # Valgrind version
 
     - name: Compile Valgrind
-      if: steps.cache-valgrind.outputs.cache-hit != 'true'
+      if: matrix.valgrind && steps.cache-valgrind.outputs.cache-hit != 'true'
       run: |
         VALGRIND_VERSION=3.16.1
         curl https://sourceware.org/pub/valgrind/valgrind-$VALGRIND_VERSION.tar.bz2 -o - | tar xj
@@ -198,13 +210,12 @@ jobs:
         make -j 2 > /dev/null
 
     - name: Install Valgrind
+      if: matrix.valgrind
       working-directory: valgrind
-      run: sudo make install
-
-    - name: Install requirement for Valgrind
       run: |
+        sudo make install
         sudo apt-get update
-        sudo apt-get install libc6-dbg
+        sudo apt-get install libc6-dbg  # Needed by Valgrind
 
     - name: Prepare env
       run: python -m pip install -r tests/requirements.txt --prefer-binary
@@ -224,51 +235,13 @@ jobs:
     - name: Python tests
       run: cmake --build build --target pytest
 
-    - name: Run Valgrind on Python tests
-      run: cmake --build build --target memcheck
-
-  deadsnakes:
-    strategy:
-      fail-fast: false
-      matrix:
-        python:
-        - version: 3.9
-          debug: true
-        - version: 3.10-dev
-          debug: false
-
-    name: "🐍 ${{ matrix.python.version }}${{ matrix.python.debug && ' (debug)' || '' }} • deadsnakes • x64"
-    runs-on: ubuntu-latest
-
-    steps:
-    - uses: actions/checkout@v2
-
-    - name: Setup Python ${{ matrix.python.version }} (deadsnakes)
-      uses: deadsnakes/action@v2.1.1
-      with:
-        python-version: ${{ matrix.python.version }}
-        debug: ${{ matrix.python.debug }}
-
-    - name: Prepare env
-      run: python -m pip install -r tests/requirements.txt --prefer-binary
-
-    - name: Configure
-      run: >
-        cmake -S . -B build
-        -DPYBIND11_WERROR=ON
-        -DDOWNLOAD_CATCH=ON
-        -DDOWNLOAD_EIGEN=ON
-        -DCMAKE_CXX_STANDARD=17
-
-    - name: Build
-      run: cmake --build build -j 2
-
-    - name: Python tests
-      run: cmake --build build --target pytest
-
     - name: C++ tests
       run: cmake --build build --target cpptest
 
+    - name: Run Valgrind on Python tests
+      if: matrix.valgrind
+      run: cmake --build build --target memcheck
+
 
   # Testing on clang using the excellent silkeh clang docker images
   clang: