From 592357a35b705b7fb71ed5c0150f963cbd024d97 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Sat, 20 Jul 2024 08:10:28 +0200 Subject: [PATCH] Test multiple versions of python. --- templates/gitlab-ci.yml.j2 | 10 ++++++--- templates/molecule-action.yml.j2 | 37 +++++++++++++++++++++----------- vars/main.yml | 6 ++++++ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 922ca55..27dfb52 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -1,13 +1,16 @@ --- -image: "{{ gitlab_container }}" variables: - PY_COLORS: 1 + DEBIAN_FRONTEND: noninteractive molecule: + image: $python script: + - apt-get update -qq + - apt-get -y -qq install yamllint docker.io + - pip install --no-cache-dir tox - if [ -f tox.ini ] ; then tox ; fi - - if [ ! -f tox.ini ] ; then molecule test ; fi + - if [ ! -f tox.ini ] ; then pip install -r requirements.yml ; pip install ansible-lint ansible-core ; molecule test ; fi rules: - if: $CI_COMMIT_REF_NAME == "master" parallel: @@ -17,6 +20,7 @@ molecule: {% for tag in distribution_version_mapping[platform.name][version] %} - image: "{{ platform_image_mapping[platform.name] }}" tag: "{{ tag }}" + python: {{ matrix_overrides[platform_image_mapping[platform.name] | lower ]["python"] | default(default_python_version) }} {% endfor %} {% endfor %} {% endfor %} diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index 2986417..43d416b 100644 --- a/templates/molecule-action.yml.j2 +++ b/templates/molecule-action.yml.j2 @@ -19,38 +19,50 @@ jobs: uses: actions/checkout@v4 - name: ansible-lint uses: ansible-community/ansible-lint-action@main - test: +{% for python_version in default_python_version %} + + {{ python_version | replace('.', '-') | replace(':', '-') }}: needs: - lint runs-on: ubuntu-20.04 + container: + image: {{ python_version }} strategy: fail-fast: false matrix: config: {% for platform in meta.galaxy_info.platforms %} {% for version in platform.versions %} +{% if matrix_overrides is defined %} +{% if matrix_overrides[platform_image_mapping[platform.name]] is defined %} +{% for override_python_version in matrix_overrides[platform_image_mapping[platform.name]]["python"] %} +{% if override_python_version == python_version %} {% for tag in distribution_version_mapping[platform.name][version] %} - image: "{{ platform_image_mapping[platform.name] }}" tag: "{{ tag }}" {% endfor %} +{% endif %} +{% endfor %} +{% else %} +{% for tag in distribution_version_mapping[platform.name][version] %} + - image: "{{ platform_image_mapping[platform.name] }}" + tag: "{{ tag }}" +{% endfor %} +{% endif %} +{% endif %} {% endfor %} {% endfor %} steps: - name: checkout uses: actions/checkout@v4 - - name: Set up Python 3. - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - name: molecule - run: molecule converge + run: | + apt-get update -qq + apt-get -y -qq install yamllint docker.io + pip install --no-cache-dir tox + if [ -f tox.ini ] ; then tox ; fi + if [ ! -f tox.ini ] ; then pip install -r requirements.yml ; pip install ansible-lint ansible-core ; molecule test ; fi env: image: {% raw %}${{ matrix.config.image }}{% endraw %} @@ -60,3 +72,4 @@ jobs: {{ item.variable }}: {% raw %}${{ {%endraw %}{{ item.name }} {% raw %}}}{% endraw %} {% endfor %} {% endif %} +{% endfor %} diff --git a/vars/main.yml b/vars/main.yml index 2b31b5a..dc50503 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,6 +1,12 @@ --- # Setting to generate files. +# A list of python version to test. +default_python_version: + - "python:3.8" + - "python:3.9" + - "python:3.10" + # A map that relates the `meta/main.yml` - `galaxy_info.platforms.name` to a name of a container. platform_image_mapping: Alpine: alpine