From 892286815bb2703890cf751deba8ed85e6a96d7b Mon Sep 17 00:00:00 2001
From: cookiecutter-e3 <cookiecutter-e3@adacore.com>
Date: Tue, 26 Nov 2024 13:43:12 +0000
Subject: [PATCH] Update cookiecutter-e3 template on e3-aws

---
 .gitlab-ci.yml | 43 ++++++++++++++++++++++++++++++++-----------
 tox.ini        |  2 +-
 2 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4edcace..092fc53 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -11,6 +11,13 @@ variables:
       - "3.12"
       - "3.13"
     value: "3.13"
+  LINUX_CI_TOX_ENV:
+    # Run coverage only with one Python version as this is costly.
+    description: "Tox environments to run on Linux."
+    value: "py39-cov-xdist,py310-xdist,py311-xdist,py312-xdist,py313-xdist"
+  WINDOWS_CI_TOX_ENV:
+    description: "Tox environments to run on Windows."
+    value: "py312-xdist"
 
 stages:
   - checks
@@ -30,7 +37,7 @@ default:
     - python -m pip install --force tox
   script:
     # Should be quoted using \' to deal with ':' in the command
-    - 'echo "Tox run environment: ${CI_TOX_ENV:=py${PYTHON_VERSION:0:1}${PYTHON_VERSION:2:2}-cov-xdist}"'
+    - 'echo "Tox run environment: ${CI_TOX_ENV}"'
     - python -m tox --colored yes -e ${CI_TOX_ENV}
 
 ### Linux jobs ###
@@ -39,8 +46,15 @@ default:
   services:
     - image:all-pythons
   before_script:
-    - source /it/activate-py${PYTHON_VERSION:0:1}${PYTHON_VERSION:2:2}
-    - python -m pip install -U pip
+    - |
+      if [ -z "$PYTHON_VERSION" ]; then
+        versions=$(echo "$LINUX_CI_TOX_ENV" | sed -E 's/py([0-9]+)-[^,]+/\1/g' | tr ',' ' ')
+        for pyversion in $versions; do
+          source /it/activate-py$pyversion
+        done
+      else
+        source /it/activate-py${PYTHON_VERSION:0:1}${PYTHON_VERSION:2}
+      fi
 
 .linux-common:
   extends:
@@ -82,9 +96,8 @@ check:
     - !reference [.linux-common, services]
     - cpu:4
   coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
-  parallel:
-    matrix:
-      - PYTHON_VERSION: ["3.9", "3.10", "3.11", "3.12", "3.13"]
+  variables:
+    CI_TOX_ENV: $LINUX_CI_TOX_ENV
   artifacts:
     when: always
     paths:
@@ -143,9 +156,18 @@ run linux tests:
     - cpu:2
     - mem:4
   before_script:
-    - source /it/activate-python ${PYTHON_VERSION}
+    - |
+      if [ -z "$PYTHON_VERSION" ]; then
+        versions=$(echo "$WINDOWS_CI_TOX_ENV" | sed -E 's/py([0-9])([0-9]+)-[^,]+/\1.\2/g' | tr ',' ' ')
+        for pyversion in $versions; do
+          if [ -d /it/python/$pyversion ]; then
+            source /it/activate-python $pyversion
+          fi
+        done
+      else
+        source /it/activate-python $PYTHON_VERSION
+      fi
     - mkdir -p "C:/tmp/Trash"
-    - python -m pip install -U pip
 
 .windows-common:
   extends:
@@ -158,9 +180,8 @@ run linux tests:
 .test-windows:
   stage: tests windows
   extends: .windows-common
-  parallel:
-    matrix:
-      - PYTHON_VERSION: ["3.9", "3.10", "3.11", "3.12", "3.13"]
+  variables:
+    CI_TOX_ENV: $WINDOWS_CI_TOX_ENV
 
 # A job tiggered by 'Run Windows tests'. This jobs will run without waiting any others
 # jobs.
diff --git a/tox.ini b/tox.ini
index 98c523f..84ae324 100644
--- a/tox.ini
+++ b/tox.ini
@@ -9,7 +9,7 @@ passenv = CI,GITHUB_*,CODECOV_*
 
 deps =
      xdist: pytest-xdist[psutil]
-     cov: pytest-cov
+     pytest-cov
      codecov: codecov
 extras = test