]> granicus.if.org Git - esp-idf/commitdiff
CI: Simplify running commands with several versions of Python
authorRoland Dobai <dobai.roland@gmail.com>
Mon, 27 Aug 2018 11:47:53 +0000 (13:47 +0200)
committerRoland Dobai <dobai.roland@gmail.com>
Thu, 6 Sep 2018 09:50:17 +0000 (11:50 +0200)
.gitlab-ci.yml
tools/ci/executable-list.txt
tools/ci/multirun_with_pyenv.sh [new file with mode: 0755]

index 4de8e083673236d205917723fc7c90b5a815f0d9..efaeead13b175bb73bb5d2717ae75757ec61ac31 100644 (file)
@@ -391,12 +391,7 @@ test_idf_monitor:
     expire_in: 1 week
   script:
     - cd ${IDF_PATH}/tools/test_idf_monitor
-    - source /opt/pyenv/activate
-    - pyenv global 2.7.15
-    - ./run_test_idf_monitor.py
-    - pyenv global 3.4.8
-    - ./run_test_idf_monitor.py
-    - pyenv global system
+    - ${IDF_PATH}/tools/ci/multirun_with_pyenv.sh ./run_test_idf_monitor.py
 
 test_idf_size:
   <<: *host_test_template
@@ -408,12 +403,7 @@ test_idf_size:
     expire_in: 1 week
   script:
     - cd ${IDF_PATH}/tools/test_idf_size
-    - source /opt/pyenv/activate
-    - pyenv global 2.7.15
-    - ./test.sh
-    - pyenv global 3.4.8
-    - ./test.sh
-    - pyenv global system
+    - ${IDF_PATH}/tools/ci/multirun_with_pyenv.sh ./test.sh
 
 test_esp_err_to_name_on_host:
   <<: *host_test_template
@@ -423,15 +413,11 @@ test_esp_err_to_name_on_host:
       - components/esp32/esp_err_to_name.c
     expire_in: 1 week
   script:
-    - cd tools/
-    - source /opt/pyenv/activate
-    - pyenv global 2.7.15
-    - ./gen_esp_err_to_name.py
+    - cd ${IDF_PATH}/tools/
+    - ${IDF_PATH}/tools/ci/multirun_with_pyenv.sh -p 2.7.15 ./gen_esp_err_to_name.py
     - git diff --exit-code -- ../components/esp32/esp_err_to_name.c || (echo 'Differences found. Please run gen_esp_err_to_name.py and commit the changes.'; exit 1)
-    - pyenv global 3.4.8
-    - ./gen_esp_err_to_name.py
+    - ${IDF_PATH}/tools/ci/multirun_with_pyenv.sh -p 3.4.8 ./gen_esp_err_to_name.py
     - git diff --exit-code -- ../components/esp32/esp_err_to_name.c || (echo 'Differences found between running under Python 2 and 3.'; exit 1)
-    - pyenv global system
 
 push_to_github:
   stage: deploy
index 5a515eaccb5dd82fbf75efb14714fc5f58ea4277..4a43825f2654a23b721efcbc37f765f129bea1ff 100644 (file)
@@ -44,3 +44,4 @@ tools/unit-test-app/unit_test.py
 tools/test_idf_size/test.sh
 tools/check_python_dependencies.py
 docs/gen-dxd.py
+tools/ci/multirun_with_pyenv.sh
diff --git a/tools/ci/multirun_with_pyenv.sh b/tools/ci/multirun_with_pyenv.sh
new file mode 100755 (executable)
index 0000000..e8e23da
--- /dev/null
@@ -0,0 +1,48 @@
+#! /bin/bash
+#
+# Tool for running scripts with several versions of Python by the use of pyenv (versions must be installed before in
+# the docker image)
+#
+# Examples:
+# ./multirun_with_pyenv.sh ./exec.sh                 # Run ./exec.h with ALL installed versions of Python
+# ./multirun_with_pyenv.sh ./exec.sh arg1 arg2       # Run ./exec.h with arguments (and ALL installed versions of Python)
+# ./multirun_with_pyenv.sh -p 2.7.15 ./exec.sh       # Run ./exec.h with Python 2.7.15 (-p must be the first argument)
+# ./multirun_with_pyenv.sh -p 3.4.8,2.7.15 ./exec.sh # Run ./exec.h with Python 3.4.8 and 2.7.15 (versions must be
+#                                               # separated by coma and be without a space)
+
+PY_VERSIONS=""
+
+{ source /opt/pyenv/activate; } || { echo 'Pyenv activation has failed!' ; exit 1; }
+
+if [ "$1" = "-p" ]; then
+    if [ "$#" -ge 2 ]; then
+        IFS=',' read -a PY_VERSIONS <<< "$2"
+        shift #remove -p
+        shift #remove argument after -p
+    else
+        echo 'No value (Python version) is given for argument -p!'
+        exit 1
+    fi
+else
+    PY_VERSIONS=$(pyenv versions --bare)
+fi
+
+if [ "$#" -lt 1 ]; then
+    echo 'No executable was passed to the runner!'
+    exit 1
+fi
+
+for ver in ${PY_VERSIONS[@]}
+do
+    echo 'Switching to Python' $ver
+    $(pyenv global $ver) || exit 1
+    echo 'Running' $@
+    $@ || {
+               echo 'Run failed! Switching back to the system version of the Python interpreter.';
+               pyenv global system;
+               exit 1;
+          }
+done
+
+echo 'Switching back to the system version of Python'
+{ pyenv global system; } || { echo 'Restoring the system version of the Python interpreter has failed!' ; exit 1; }