diff --git a/.github/workflows/configured.yml b/.github/workflows/configured.yml index bda2aa2..dded4c6 100644 --- a/.github/workflows/configured.yml +++ b/.github/workflows/configured.yml @@ -2,15 +2,10 @@ name: libvirt with configuration on: - schedule: - - cron: "0 2 * * 0" workflow_dispatch: workflow_run: workflows: - "CI" - branches: - - main - - feature/** types: - completed @@ -30,7 +25,8 @@ jobs: - debian:11 ansible-version: - '6.1' - + scenario: + - configured steps: - name: check out the codebase. uses: actions/checkout@v3 @@ -49,8 +45,11 @@ jobs: - name: test with tox run: | - tox -e ansible_$(printf "${{ matrix.ansible-version }}") \ - -- molecule test --scenario-name configured + make \ + test \ + -e TOX_SCENARIO="${{ matrix.scenario }}" \ + -e TOX_ANSIBLE="ansible_${{ matrix.ansible-version }}" \ + -e DISTRIBUTION="${{ matrix.image }}" env: PY_COLORS: '1' ANSIBLE_FORCE_COLOR: '1' diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index e968761..230af1f 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -3,12 +3,37 @@ name: code linter on: + schedule: + - cron: "45 1 * * 0" workflow_dispatch: - pull_request: + inputs: + logLevel: + description: 'Log level' + required: true + default: 'warning' + type: choice + options: + - info + - warning + - debug push: branches: - - main - - testing + - 'main' + - 'feature/**' + - '!doc/**' + paths: + - "!Makefile" + - "!README.md" + - "tasks/**" + pull_request: + branches: + - 'main' + - 'feature/**' + - '!doc/**' + paths: + - "!Makefile" + - "!README.md" + - "tasks/**" jobs: lint: @@ -17,8 +42,6 @@ jobs: steps: - name: 🛎 Checkout uses: actions/checkout@v3 - with: - fetch-depth: 0 - name: lint uses: docker://ghcr.io/github/super-linter:slim-v4 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5a6e799..23c5b7c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,15 +2,9 @@ name: CI on: - schedule: - - cron: "0 2 * * 0" - workflow_dispatch: workflow_run: workflows: - "code linter" - branches: - - main - - feature/** types: - completed @@ -31,7 +25,8 @@ jobs: ansible-version: - '5.1' - '6.1' - + scenario: + - default steps: - name: check out the codebase. uses: actions/checkout@v3 @@ -50,8 +45,11 @@ jobs: - name: test with tox run: | - tox -e ansible_$(printf "${{ matrix.ansible-version }}") \ - -- molecule test --scenario-name default + make \ + test \ + -e TOX_SCENARIO="${{ matrix.scenario }}" \ + -e TOX_ANSIBLE="ansible_${{ matrix.ansible-version }}" \ + -e DISTRIBUTION="${{ matrix.image }}" env: PY_COLORS: '1' ANSIBLE_FORCE_COLOR: '1' @@ -71,7 +69,8 @@ jobs: ansible-version: - '5.1' - '6.1' - + scenario: + - default steps: - name: check out the codebase. uses: actions/checkout@v3 @@ -90,8 +89,11 @@ jobs: - name: test with tox run: | - tox -e ansible_$(printf "${{ matrix.ansible-version }}") \ - -- molecule test --scenario-name default + make \ + test \ + -e TOX_SCENARIO="${{ matrix.scenario }}" \ + -e TOX_ANSIBLE="ansible_${{ matrix.ansible-version }}" \ + -e DISTRIBUTION="${{ matrix.image }}" env: PY_COLORS: '1' ANSIBLE_FORCE_COLOR: '1' diff --git a/Makefile b/Makefile index 40857c8..3abaf48 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,8 @@ # export TOX_SCENARIO ?= default -# export TOX_PYTHON ?= py310 export TOX_ANSIBLE ?= ansible_6.1 -.PHONY: converge destroy verify lint +.PHONY: converge destroy verify test lint default: converge @@ -16,5 +15,8 @@ destroy: verify: @hooks/verify +test: + @hooks/test + lint: @hooks/lint diff --git a/hooks/converge b/hooks/converge index 5df5ad6..0c50932 100755 --- a/hooks/converge +++ b/hooks/converge @@ -1,5 +1,3 @@ #!/usr/bin/env bash -. hooks/_tox_base - -tox ${TOX_OPTS} -- molecule converge ${TOX_ARGS} +hooks/tox.sh "converge" diff --git a/hooks/destroy b/hooks/destroy index 98fcf16..b4a3f8d 100755 --- a/hooks/destroy +++ b/hooks/destroy @@ -1,5 +1,3 @@ #!/usr/bin/env bash -. hooks/_tox_base - -tox ${TOX_OPTS} -- molecule destroy ${TOX_ARGS} +hooks/tox.sh "destroy" diff --git a/hooks/lint b/hooks/lint index 6cf7ff3..ef226a0 100755 --- a/hooks/lint +++ b/hooks/lint @@ -1,5 +1,3 @@ #!/usr/bin/env bash -. hooks/_tox_base - -tox ${TOX_OPTS} -- molecule lint ${TOX_ARGS} +hooks/tox.sh "lint" diff --git a/hooks/_tox_base b/hooks/molecule.rc similarity index 100% rename from hooks/_tox_base rename to hooks/molecule.rc diff --git a/hooks/test b/hooks/test new file mode 100755 index 0000000..2869139 --- /dev/null +++ b/hooks/test @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +hooks/tox.sh "test" diff --git a/hooks/tox.sh b/hooks/tox.sh new file mode 100755 index 0000000..62bb777 --- /dev/null +++ b/hooks/tox.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +. hooks/molecule.rc + +TOX_TEST="${1}" + +if [ -f "./collections.yml" ] +then + for collection in $(grep -v "#" collections.yml | grep "^ - name: " | awk -F ': ' '{print $2}') + do + collections_installed="$(ansible-galaxy collection list | grep ${collection} 2> /dev/null)" + + if [ -z "${collections_installed}" ] + then + echo "Install the required collection '${collection}'" + ansible-galaxy collection install ${collection} + else + collection_version=$(echo "${collections_installed}" | awk -F ' ' '{print $2}') + + echo "The required collection '${collection}' is installed in version ${collection_version}." + fi + done + echo "" +fi + +tox ${TOX_OPTS} -- molecule ${TOX_TEST} ${TOX_ARGS} diff --git a/hooks/verify b/hooks/verify index 79a38d4..5f436af 100755 --- a/hooks/verify +++ b/hooks/verify @@ -1,5 +1,3 @@ #!/usr/bin/env bash -. hooks/_tox_base - -tox ${TOX_OPTS} -- molecule verify ${TOX_ARGS} +hooks/tox.sh "verify" diff --git a/molecule/configured/molecule.yml b/molecule/configured/molecule.yml index 744241e..92a92e9 100644 --- a/molecule/configured/molecule.yml +++ b/molecule/configured/molecule.yml @@ -19,12 +19,16 @@ provisioner: name: ansible ansible_args: - --diff - # - -v + - -v config_options: defaults: - deprecation_warnings: True + deprecation_warnings: true stdout_callback: yaml callbacks_enabled: profile_tasks + gathering: smart + fact_caching: jsonfile + fact_caching_timeout: 8640 + fact_caching_connection: ansible_facts scenario: test_sequence: diff --git a/molecule/configured/prepare.yml b/molecule/configured/prepare.yml index 4dcdb28..e55c7b2 100644 --- a/molecule/configured/prepare.yml +++ b/molecule/configured/prepare.yml @@ -5,13 +5,27 @@ gather_facts: true pre_tasks: - - name: update pacman system - command: | - pacman --refresh --sync --sysupgrade --noconfirm + - name: arch- / artixlinux when: - - ansible_distribution | lower == 'archlinux' + - ansible_distribution | lower == 'archlinux' or + ansible_os_family | lower == 'artix linux' + block: + - name: update pacman system + ansible.builtin.command: | + pacman --refresh --sync --sysupgrade --noconfirm - - debug: + - name: create depends service + ansible.builtin.copy: + mode: 0755 + dest: /etc/init.d/net + content: | + #!/usr/bin/openrc-run + true + when: + - ansible_os_family | lower == 'artix linux' + + - name: environment + ansible.builtin.debug: msg: - "os family : {{ ansible_distribution }} ({{ ansible_os_family }})" - "distribution version : {{ ansible_distribution_major_version }}" diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 4dcdb28..e55c7b2 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -5,13 +5,27 @@ gather_facts: true pre_tasks: - - name: update pacman system - command: | - pacman --refresh --sync --sysupgrade --noconfirm + - name: arch- / artixlinux when: - - ansible_distribution | lower == 'archlinux' + - ansible_distribution | lower == 'archlinux' or + ansible_os_family | lower == 'artix linux' + block: + - name: update pacman system + ansible.builtin.command: | + pacman --refresh --sync --sysupgrade --noconfirm - - debug: + - name: create depends service + ansible.builtin.copy: + mode: 0755 + dest: /etc/init.d/net + content: | + #!/usr/bin/openrc-run + true + when: + - ansible_os_family | lower == 'artix linux' + + - name: environment + ansible.builtin.debug: msg: - "os family : {{ ansible_distribution }} ({{ ansible_os_family }})" - "distribution version : {{ ansible_distribution_major_version }}" diff --git a/test-requirements.txt b/test-requirements.txt index 45e18eb..c98dc83 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,7 @@ ansible-lint docker flake8 molecule -molecule-docker +molecule-plugins[docker] netaddr pytest pytest-testinfra