Skip to content

Commit

Permalink
Test multiple versions of python.
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-de-bock committed Jul 20, 2024
1 parent 66bab3e commit 592357a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
10 changes: 7 additions & 3 deletions templates/gitlab-ci.yml.j2
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 %}
Expand Down
37 changes: 25 additions & 12 deletions templates/molecule-action.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand All @@ -60,3 +72,4 @@ jobs:
{{ item.variable }}: {% raw %}${{ {%endraw %}{{ item.name }} {% raw %}}}{% endraw %}
{% endfor %}
{% endif %}
{% endfor %}
6 changes: 6 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 592357a

Please sign in to comment.