├── .codecov.yml ├── .github ├── dependabot.yml └── workflows │ ├── bad-commit-message-blocker.yml │ └── test-action.yml ├── .gitignore ├── .internal └── ansible │ └── ansible_collections │ └── internal │ └── test │ ├── galaxy.yml │ ├── plugins │ └── modules │ │ └── test.py │ └── tests │ ├── .gitignore │ ├── integration │ └── targets │ │ └── test │ │ ├── aliases │ │ └── tasks │ │ └── main.yml │ └── unit │ └── plugins │ └── modules │ └── test_test.py ├── .pre-commit-config.yaml ├── .yamllint ├── LICENSE ├── README.md └── action.yml /.codecov.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | fixes: 4 | - "ansible_collections/::.internal/ansible/ansible_collections/" 5 | 6 | ... 7 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 2 3 | updates: 4 | - package-ecosystem: "github-actions" 5 | directory: "/" 6 | schedule: 7 | interval: "weekly" 8 | -------------------------------------------------------------------------------- /.github/workflows/bad-commit-message-blocker.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | name: 📝 Git commit messages 4 | 5 | on: # yamllint disable-line rule:truthy 6 | pull_request: 7 | 8 | env: 9 | MAX_ALLOWED_PR_COMMITS: 50 10 | 11 | jobs: 12 | check-commit-message: 13 | name: ✍ 14 | if: github.event.pull_request.user.type != 'Bot' 15 | runs-on: ubuntu-22.04 16 | timeout-minutes: 1 17 | steps: 18 | - name: Get PR commits details 19 | id: commits 20 | run: | 21 | COMMITS_NUMBER="$(\ 22 | 2>http_headers curl --verbose --show-error \ 23 | --header 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' \ 24 | --header 'Accept: application/vnd.github.v3+json' \ 25 | 'https://api.github.com/repos/${{ 26 | github.repository 27 | }}/pulls/${{ 28 | github.event.pull_request.number 29 | }}/commits?per_page=${{ 30 | env.MAX_ALLOWED_PR_COMMITS 31 | }}' | jq length \ 32 | )" 33 | echo "number=${COMMITS_NUMBER}" >> "${GITHUB_OUTPUT}" 34 | 35 | if grep 'link:' http_headers 36 | then 37 | TOO_MANY=true 38 | else 39 | TOO_MANY=false 40 | fi 41 | echo "too-many=${TOO_MANY}" >> "${GITHUB_OUTPUT}" 42 | 43 | echo check-range='${{ 44 | github.event.pull_request.base.sha 45 | }}..${{ 46 | github.event.pull_request.head.sha 47 | }}' >> "${GITHUB_OUTPUT}" 48 | 49 | echo last-commit='${{ 50 | github.event.pull_request.head.sha 51 | }}' >> "${GITHUB_OUTPUT}" 52 | shell: bash 53 | - name: Prepare helper commands 54 | id: commands 55 | run: | 56 | echo gitlint-install='pip install --user gitlint' >> "${GITHUB_OUTPUT}" 57 | 58 | echo gitlint-lint="\ 59 | python -m \ 60 | gitlint.cli \ 61 | --ignore-stdin \ 62 | --commits '${{ steps.commits.outputs.check-range }}'\ 63 | " >> "${GITHUB_OUTPUT}" 64 | # -C ./.github/workflows/.gitlint 65 | 66 | echo git-log="\ 67 | git log --color --no-patch \ 68 | '${{ steps.commits.outputs.check-range }}'\ 69 | " >> "${GITHUB_OUTPUT}" 70 | shell: bash 71 | # Ref:https://joe.gl/ombek/blog/pr-gitlint/ 72 | - name: Check out src from Git 73 | uses: actions/checkout@v4 74 | with: 75 | fetch-depth: steps.commits.outputs.number 76 | ref: ${{ github.event.pull_request.head.sha }} 77 | - name: Log the commits to be checked 78 | run: ${{ steps.commands.outputs.git-log }} 79 | - name: Install gitlint 80 | run: ${{ steps.commands.outputs.gitlint-install }} 81 | - name: Check commit messages in the PR 82 | shell: bash 83 | run: | 84 | >&2 echo Checking the following commit range: '${{ 85 | steps.commits.outputs.check-range 86 | }}' 87 | ${{ 88 | steps.commands.outputs.gitlint-lint 89 | }} 2>&1 | >&2 tee gitlint-results.txt 90 | - name: Report check summary for too many commits 91 | if: fromJSON(steps.commits.outputs.too-many) 92 | run: >- 93 | echo 94 | '# This pull request has too many commits, only the last ${{ 95 | env.MAX_ALLOWED_PR_COMMITS 96 | }} have been checked' 97 | >> 98 | "${GITHUB_STEP_SUMMARY}" 99 | shell: bash 100 | - name: Set a failing status because of too many commits 101 | if: fromJSON(steps.commits.outputs.too-many) 102 | run: exit 1 103 | shell: bash 104 | - name: Report gitlint check summary 105 | if: always() 106 | run: | 107 | echo >> "${GITHUB_STEP_SUMMARY}" 108 | echo '> **Note**' >> "${GITHUB_STEP_SUMMARY}" 109 | echo \ 110 | '> If this check is failing, check the Gitlint rule violations,' \ 111 | 'matching them with the corresponding commits listed down below.' \ 112 | 'Fix the problems and force-push the pull request branch to clear' \ 113 | 'this failure.' >> "${GITHUB_STEP_SUMMARY}" 114 | echo >> "${GITHUB_STEP_SUMMARY}" 115 | 116 | echo >> "${GITHUB_STEP_SUMMARY}" 117 | echo '# Gitlint check output' >> "${GITHUB_STEP_SUMMARY}" 118 | echo >> "${GITHUB_STEP_SUMMARY}" 119 | 120 | echo '```console' >> "${GITHUB_STEP_SUMMARY}" 121 | echo "$ ${{ 122 | steps.commands.outputs.gitlint-install 123 | }}" >> "${GITHUB_STEP_SUMMARY}" 124 | echo "$ ${{ 125 | steps.commands.outputs.gitlint-lint 126 | }}" >> "${GITHUB_STEP_SUMMARY}" 127 | if [[ \ 128 | "" != "$(cat gitlint-results.txt)" && \ 129 | ! $(grep 'Commit' gitlint-results.txt) \ 130 | ]] 131 | then 132 | echo 'Commit ${{ 133 | steps.commits.outputs.last-commit 134 | }}:' >> "${GITHUB_STEP_SUMMARY}" 135 | fi 136 | cat gitlint-results.txt >> "${GITHUB_STEP_SUMMARY}" 137 | echo '```' >> "${GITHUB_STEP_SUMMARY}" 138 | 139 | echo >> "${GITHUB_STEP_SUMMARY}" 140 | echo '# Checked commits' >> "${GITHUB_STEP_SUMMARY}" 141 | echo >> "${GITHUB_STEP_SUMMARY}" 142 | echo '```console' >> "${GITHUB_STEP_SUMMARY}" 143 | ${{ 144 | steps.commands.outputs.git-log 145 | }} --no-color >> "${GITHUB_STEP_SUMMARY}" 146 | echo '```' >> "${GITHUB_STEP_SUMMARY}" 147 | shell: bash 148 | 149 | ... 150 | -------------------------------------------------------------------------------- /.github/workflows/test-action.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🧪 3 | 4 | on: # yamllint disable-line rule:truthy 5 | merge_group: 6 | push: 7 | branches-ignore: 8 | - gh-readonly-queue/** # Temporary merge queue-related GH-made branches 9 | pull_request: 10 | 11 | jobs: 12 | tests: 13 | name: >- 14 | Ⓐ${{ matrix.ansible-core-version }} 15 | @ 16 | 🐍${{ matrix.origin-python-version }}: 17 | ${{ matrix.testing-type }} 18 | runs-on: ubuntu-latest 19 | timeout-minutes: 3 20 | services: 21 | httpbin: 22 | image: kennethreitz/httpbin 23 | strategy: 24 | fail-fast: false 25 | matrix: 26 | ansible-core-version: 27 | - '' 28 | collection-root: 29 | - '' 30 | collection-src-directory: 31 | - '' 32 | docker-image: 33 | - default 34 | git-checkout-ref: 35 | - '' 36 | integration-continue-on-error: 37 | - '' 38 | integration-diff: 39 | - '' 40 | integration-retry-on-error: 41 | - '' 42 | origin-python-version: 43 | - '' 44 | pre-action-cmd: 45 | - '' 46 | pre-test-cmd: 47 | - '' 48 | pull-request-change-detection: 49 | - '' 50 | target: 51 | - '' 52 | target-python-version: 53 | - '' 54 | test-deps: 55 | - '' 56 | testing-type: 57 | - '' 58 | coverage: 59 | - auto 60 | exclude: 61 | - ansible-core-version: '' 62 | include: 63 | - ansible-core-version: stable-2.11 64 | origin-python-version: '3.8' 65 | testing-type: sanity 66 | collection-root: . 67 | collection-src-directory: ./.tmp-action-checkout 68 | coverage: auto 69 | integration-continue-on-error: true 70 | integration-diff: true 71 | integration-retry-on-error: true 72 | pre-action-cmd: >- 73 | mv -v 74 | .internal/ansible/ansible_collections/internal/test/galaxy.yml . 75 | pre-test-cmd: rm -rfv .internal/ 76 | - ansible-core-version: stable-2.12 77 | collection-root: .internal/ansible/ansible_collections/internal/test 78 | collection-src-directory: ./.tmp-action-checkout 79 | coverage: never 80 | integration-continue-on-error: true 81 | integration-diff: true 82 | integration-retry-on-error: true 83 | origin-python-version: auto 84 | testing-type: sanity 85 | - ansible-core-version: devel 86 | collection-root: .internal/ansible/ansible_collections/internal/test 87 | collection-src-directory: ./.tmp-action-checkout 88 | coverage: always 89 | integration-continue-on-error: true 90 | integration-diff: true 91 | integration-retry-on-error: true 92 | origin-python-version: auto 93 | testing-type: units 94 | - ansible-core-version: stable-2.13 95 | collection-root: .internal/ansible/ansible_collections/internal/test 96 | # NOTE: A missing `collection-src-directory` input causes 97 | # NOTE: fetching the repo from GitHub. 98 | coverage: auto 99 | integration-continue-on-error: false 100 | integration-diff: true 101 | integration-retry-on-error: true 102 | origin-python-version: '3.9' 103 | pull-request-change-detection: 'true' 104 | testing-type: integration 105 | - ansible-core-version: stable-2.13 106 | collection-root: .internal/ansible/ansible_collections/internal/test 107 | # NOTE: A missing `collection-src-directory` input causes 108 | # NOTE: fetching the repo from GitHub. 109 | coverage: auto 110 | integration-continue-on-error: true 111 | integration-diff: true 112 | integration-retry-on-error: false 113 | origin-python-version: auto 114 | testing-type: integration 115 | test-deps: >- 116 | --no-deps 117 | git+https://github.com/ansible-collections/ansible.netcommon.git 118 | - ansible-core-version: stable-2.14 119 | collection-root: .internal/ansible/ansible_collections/internal/test 120 | collection-src-directory: ./.tmp-action-checkout 121 | coverage: auto 122 | integration-continue-on-error: true 123 | integration-diff: false 124 | integration-retry-on-error: true 125 | origin-python-version: >- 126 | 3.10 127 | testing-type: integration 128 | test-deps: >- 129 | git+https://github.com/ansible-collections/ansible.utils.git 130 | git+https://github.com/ansible-collections/ansible.netcommon.git 131 | steps: 132 | - name: Checkout 133 | uses: actions/checkout@v4 134 | with: 135 | path: .tmp-action-checkout/ 136 | 137 | - name: Run a pre-action command 138 | if: matrix.pre-action-cmd 139 | run: ${{ matrix.pre-action-cmd }} 140 | working-directory: ./.tmp-action-checkout/ 141 | 142 | - name: Run ${{ matrix.testing-type }} tests 143 | id: tests 144 | uses: ./.tmp-action-checkout/ 145 | with: 146 | ansible-core-version: ${{ matrix.ansible-core-version }} 147 | collection-root: ${{ matrix.collection-root }} 148 | collection-src-directory: ${{ matrix.collection-src-directory }} 149 | coverage: ${{ matrix.coverage }} 150 | docker-image: ${{ matrix.docker-image }} 151 | git-checkout-ref: ${{ matrix.git-checkout-ref }} 152 | integration-continue-on-error: >- 153 | ${{ matrix.integration-continue-on-error || 'true' }} 154 | integration-diff: ${{ matrix.integration-diff || 'true' }} 155 | integration-retry-on-error: >- 156 | ${{ matrix.integration-retry-on-error || 'true' }} 157 | origin-python-version: ${{ matrix.origin-python-version }} 158 | pre-test-cmd: ${{ matrix.pre-test-cmd }} 159 | pull-request-change-detection: >- 160 | ${{ matrix.pull-request-change-detection || 'false' }} 161 | target: ${{ matrix.target }} 162 | target-python-version: ${{ matrix.target-python-version }} 163 | testing-type: ${{ matrix.testing-type }} 164 | test-deps: ${{ matrix.test-deps }} 165 | 166 | - name: 📝 Log all the action outputs 167 | run: | 168 | echo '# 🤖 Action outputs as JSON:' >> "${GITHUB_STEP_SUMMARY}" 169 | echo >> "${GITHUB_STEP_SUMMARY}" 170 | echo '```json' >> "${GITHUB_STEP_SUMMARY}" 171 | echo '${{ toJSON(steps.tests.outputs) }}' \ 172 | | tee -a "${GITHUB_STEP_SUMMARY}" 173 | echo '```' >> "${GITHUB_STEP_SUMMARY}" 174 | 175 | check: # This job does nothing and is only used for the branch protection 176 | if: always() 177 | 178 | needs: 179 | - tests 180 | 181 | runs-on: ubuntu-latest 182 | 183 | timeout-minutes: 1 184 | 185 | steps: 186 | - name: Decide whether the needed jobs succeeded or failed 187 | uses: re-actors/alls-green@release/v1 188 | with: 189 | jobs: ${{ toJSON(needs) }} 190 | ... 191 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /.internal/ansible/ansible_collections/internal/test/galaxy.yml: -------------------------------------------------------------------------------- 1 | --- 2 | namespace: internal 3 | name: test 4 | description: A collection internal to this repository for running tests. 5 | version: 0.1.0 6 | readme: README.md 7 | authors: 8 | - Felix Fontein (@felixfontein) 9 | -------------------------------------------------------------------------------- /.internal/ansible/ansible_collections/internal/test/plugins/modules/test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (c) 2022 Felix Fontein 5 | # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | # SPDX-License-Identifier: GPL-3.0-or-later 7 | 8 | from __future__ import absolute_import, division, print_function 9 | 10 | __metaclass__ = type 11 | 12 | 13 | DOCUMENTATION = r''' 14 | --- 15 | module: test 16 | short_description: Test module 17 | version_added: 0.1.0 18 | author: 19 | - Felix Fontein (@felixfontein) 20 | description: 21 | - Just a test. 22 | notes: 23 | - Does not support C(check_mode). 24 | 25 | options: 26 | test: 27 | description: Some string that is echoed back. 28 | required: true 29 | type: str 30 | ''' 31 | 32 | EXAMPLES = r''' 33 | - name: Does nothing 34 | internal.test.test: 35 | test: foo 36 | ''' 37 | 38 | RETURN = r''' 39 | test: 40 | description: The value of the I(test) input. 41 | type: str 42 | returned: success 43 | ''' 44 | 45 | from ansible.module_utils.basic import AnsibleModule 46 | 47 | 48 | def main(): 49 | module = AnsibleModule(argument_spec={'test': {'type': 'str', 'required': True}}) 50 | module.exit_json(test=module.params['test']) 51 | 52 | 53 | if __name__ == '__main__': 54 | main() 55 | -------------------------------------------------------------------------------- /.internal/ansible/ansible_collections/internal/test/tests/.gitignore: -------------------------------------------------------------------------------- 1 | /output/ 2 | -------------------------------------------------------------------------------- /.internal/ansible/ansible_collections/internal/test/tests/integration/targets/test/aliases: -------------------------------------------------------------------------------- 1 | shippable/posix/group1 2 | -------------------------------------------------------------------------------- /.internal/ansible/ansible_collections/internal/test/tests/integration/targets/test/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Call module 3 | test: 4 | test: foo 5 | register: result 6 | 7 | - name: Check return value 8 | assert: 9 | that: 10 | - result.test == 'foo' 11 | -------------------------------------------------------------------------------- /.internal/ansible/ansible_collections/internal/test/tests/unit/plugins/modules/test_test.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Felix Fontein 2 | # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | # SPDX-License-Identifier: GPL-3.0-or-later 4 | 5 | from __future__ import absolute_import, division, print_function 6 | 7 | __metaclass__ = type 8 | 9 | import json 10 | 11 | import pytest 12 | from ansible.module_utils import basic 13 | from ansible.module_utils.common.text.converters import to_bytes 14 | from ansible_collections.internal.test.plugins.modules import test 15 | 16 | try: 17 | from unittest import mock 18 | except ImportError: 19 | import mock 20 | 21 | 22 | def set_module_args(args): 23 | if '_ansible_remote_tmp' not in args: 24 | args['_ansible_remote_tmp'] = '/tmp' 25 | if '_ansible_keep_remote_files' not in args: 26 | args['_ansible_keep_remote_files'] = False 27 | 28 | args = json.dumps({'ANSIBLE_MODULE_ARGS': args}) 29 | basic._ANSIBLE_ARGS = to_bytes(args) 30 | 31 | 32 | class AnsibleExitJson(Exception): 33 | def __init__(self, kwargs): 34 | self.kwargs = kwargs 35 | 36 | 37 | def exit_json(*args, **kwargs): 38 | if 'changed' not in kwargs: 39 | kwargs['changed'] = False 40 | raise AnsibleExitJson(kwargs) 41 | 42 | 43 | def test_test(): 44 | set_module_args({'test': 'foo'}) 45 | with mock.patch.multiple(basic.AnsibleModule, exit_json=exit_json): 46 | with pytest.raises(AnsibleExitJson) as e: 47 | test.main() 48 | assert 'test' in e.value.kwargs 49 | assert e.value.kwargs['test'] == 'foo' 50 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | ci: 3 | autoupdate_schedule: quarterly 4 | 5 | repos: 6 | - repo: https://github.com/asottile/add-trailing-comma.git 7 | rev: v3.1.0 8 | hooks: 9 | - id: add-trailing-comma 10 | 11 | - repo: https://github.com/PyCQA/isort.git 12 | rev: 5.13.2 13 | hooks: 14 | - id: isort 15 | args: 16 | - --honor-noqa 17 | 18 | - repo: https://github.com/Lucas-C/pre-commit-hooks.git 19 | rev: v1.5.5 20 | hooks: 21 | - id: remove-tabs 22 | 23 | - repo: https://github.com/python-jsonschema/check-jsonschema.git 24 | rev: 0.28.6 25 | hooks: 26 | - id: check-github-actions 27 | - id: check-github-workflows 28 | - id: check-jsonschema 29 | name: Check GitHub Workflows set timeout-minutes 30 | args: 31 | - --builtin-schema 32 | - github-workflows-require-timeout 33 | files: ^\.github/workflows/[^/]+$ 34 | types: 35 | - yaml 36 | - id: check-readthedocs 37 | 38 | - repo: https://github.com/pre-commit/pre-commit-hooks.git 39 | rev: v4.6.0 40 | hooks: 41 | # Side-effects: 42 | - id: end-of-file-fixer 43 | - id: requirements-txt-fixer 44 | - id: trailing-whitespace 45 | - id: mixed-line-ending 46 | # Non-modifying checks: 47 | - id: name-tests-test 48 | files: >- 49 | ^tests/[^_].*\.py$ 50 | - id: check-added-large-files 51 | - id: check-byte-order-marker 52 | - id: check-case-conflict 53 | - id: check-executables-have-shebangs 54 | - id: check-merge-conflict 55 | - id: check-json 56 | - id: check-symlinks 57 | - id: check-yaml 58 | - id: detect-private-key 59 | # Heavy checks: 60 | - id: check-ast 61 | - id: debug-statements 62 | language_version: python3 63 | 64 | - repo: https://github.com/codespell-project/codespell 65 | rev: v2.3.0 66 | hooks: 67 | - id: codespell 68 | 69 | - repo: https://github.com/adrienverge/yamllint.git 70 | rev: v1.35.1 71 | hooks: 72 | - id: yamllint 73 | files: \.(yaml|yml)$ 74 | types: 75 | - file 76 | - yaml 77 | args: 78 | - --strict 79 | 80 | - repo: https://github.com/PyCQA/flake8.git 81 | rev: 7.1.0 82 | hooks: 83 | - id: flake8 84 | alias: flake8-no-wps 85 | name: flake8 WPS-excluded 86 | args: 87 | - --ignore 88 | - >- 89 | D100, 90 | D101, 91 | D103, 92 | D107, 93 | E402, 94 | E501, 95 | additional_dependencies: 96 | - flake8-2020 ~= 1.7.0 97 | - flake8-pytest-style ~= 1.6.0 98 | language_version: python3 99 | 100 | - repo: https://github.com/PyCQA/flake8.git 101 | rev: 7.1.0 102 | hooks: 103 | - id: flake8 104 | alias: flake8-only-wps 105 | name: flake8 WPS-only 106 | args: 107 | - --ignore 108 | - >- 109 | WPS111, 110 | WPS347, 111 | WPS360, 112 | WPS422, 113 | WPS433, 114 | WPS437, 115 | WPS440, 116 | WPS441, 117 | WPS453, 118 | - --select 119 | - WPS 120 | additional_dependencies: 121 | - wemake-python-styleguide ~= 0.19.1 122 | language_version: python3 123 | 124 | - repo: https://github.com/PyCQA/pylint.git 125 | rev: v3.2.4 126 | hooks: 127 | - id: pylint 128 | args: 129 | - --disable 130 | - >- 131 | import-error, 132 | invalid-name, 133 | line-too-long, 134 | missing-class-docstring, 135 | missing-function-docstring, 136 | missing-module-docstring, 137 | protected-access, 138 | super-init-not-called, 139 | unused-argument, 140 | wrong-import-position, 141 | - --output-format 142 | - colorized 143 | 144 | ... 145 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | extends: default 4 | 5 | rules: 6 | indentation: 7 | level: error 8 | indent-sequences: false 9 | 10 | ... 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![🧪 GitHub Actions CI/CD workflow tests badge]][GHA workflow runs list] 2 | [![pre-commit.ci status badge]][pre-commit.ci results page] 3 | 4 | # ansible-test-gh-action for setting up CI in Ansible Collection repositories 5 | 6 | A composite GitHub Action encapsulating the GitHub Actions CI/CD workflows 7 | setup necessary for testing Ansible collection repositories on GitHub. 8 | 9 | 10 | ## Usage 11 | 12 | To use the action add the following step to your workflow file (e.g. 13 | `.github/workflows/ansible-test.yml`) 14 | 15 | ```yaml 16 | - name: Perform integration testing with ansible-test 17 | uses: ansible-community/ansible-test-gh-action@release/v1 18 | with: 19 | ansible-core-version: stable-2.14 20 | pre-test-cmd: echo This runs before the ansible-test invocation 21 | target-python-version: 3.11 22 | controller-python-version: auto 23 | testing-type: integration 24 | test-deps: ansible.netcommon 25 | - name: Perform sanity testing with ansible-test 26 | uses: ansible-community/ansible-test-gh-action@release/v1 27 | with: 28 | ansible-core-version: stable-2.14 29 | testing-type: sanity 30 | - name: Perform unit testing with ansible-test 31 | uses: ansible-community/ansible-test-gh-action@release/v1 32 | with: 33 | ansible-core-version: stable-2.14 34 | pre-test-cmd: echo This runs before the ansible-test invocation 35 | target-python-version: 3.11 36 | testing-type: units 37 | test-deps: >- 38 | ansible.netcommon 39 | ansible.utils 40 | ``` 41 | 42 | > **Pro tip**: instead of using branch pointers, like `main`, pin 43 | versions of Actions that you use to tagged versions or SHA-1 commit 44 | identifiers. This will make your workflows more secure and better 45 | reproducible, saving you from sudden and unpleasant surprises. 46 | 47 | 48 | ## Options 49 | 50 | 51 | ### `ansible-core-version` 52 | 53 | `ansible-core` Git revision. See https://github.com/ansible/ansible/tags 54 | and https://github.com/ansible/ansible/branches/all?query=stable- for 55 | ideas. The repository this refers to can be changed with the 56 | `ansible-core-github-repository-slug` option. **(DEFAULT: `stable-2.14`)** 57 | 58 | 59 | ### `ansible-core-github-repository-slug` 60 | 61 | The GitHub repository slug from which to check out ansible-core 62 | **(DEFAULT: `ansible/ansible`)** 63 | 64 | 65 | ### `codecov-token` 66 | 67 | The Codecov token to use when uploading coverage data. **(OPTIONAL)** 68 | 69 | 70 | ### `controller-python-version` 71 | 72 | Controller Python version. This is only used for integration tests and 73 | ansible-core 2.12 or later when `target-python-version` is also specified 74 | **(DEFAULT: `auto`)** 75 | 76 | 77 | ### `collection-root` 78 | 79 | Path to collection root relative to repository root **(DEFAULT: `.`)** 80 | 81 | 82 | ### `collection-src-directory` 83 | 84 | A pre-checked out collection directory that's already on disk 85 | **(OPTIONAL, substitutes getting the source from the remote Git 86 | repository if set, also this action will not attempt to mutate 87 | its contents)** 88 | 89 | 90 | ### `coverage` 91 | 92 | Whether to collect and upload coverage information. Can be set to 93 | `always`, `never`, and `auto`. The value `auto` will upload coverage 94 | information except when `pull-request-change-detection` is set to `true` 95 | and the action is called from a Pull Request. **(DEFAULT: `auto`)** 96 | 97 | > [!NOTE] 98 | > Coverage is only generated for modules and plugins. If your collection does 99 | > not contain any modules or plugins, set this to `never` to avoid errors in 100 | > the codecov upload step due to no coverage information being available. 101 | 102 | 103 | ### `docker-image` 104 | 105 | A container image spawned by `ansible-test` **(OPTIONAL)** 106 | 107 | 108 | ### `git-checkout-ref` 109 | 110 | Committish to check out, unused if `collection-src-directory` 111 | is set **(OPTIONAL)** 112 | 113 | 114 | ### `integration-continue-on-error` 115 | 116 | Whether the continue with the other integration tests when an error occurs. 117 | If set to `false`, will stop on the first error. When set to `false` and 118 | `coverage=auto`, code coverage uploading will be disabled. 119 | **(DEFAULT: `true`)** 120 | 121 | 122 | ### `integration-diff` 123 | 124 | Whether to show diff output when calling actions in integration tests. 125 | Actions can override this by specifying `diff: false` or `diff: true`. 126 | **(DEFAULT: `true`)** 127 | 128 | 129 | ### `integration-retry-on-error` 130 | 131 | Whether to retry the current integration test once when an error happens. 132 | **(DEFAULT: `true`)** 133 | 134 | 135 | ### `origin-python-version` 136 | 137 | Environment Python version. The value `auto` uses the maximum Python 138 | version supported by the given `ansible-core-version` **(DEFAULT: `auto`)** 139 | 140 | 141 | ### `pre-test-cmd` 142 | 143 | Extra command to invoke before ansible-test **(OPTIONAL)** 144 | 145 | 146 | ### `pull-request-change-detection` 147 | 148 | Whether to use change detection for pull requests. If set to `true`, will 149 | use change detection to determine changed files against the target branch, 150 | and will not upload code coverage results. If the invocation is not from a 151 | pull request, this option is ignored. Note that this requires 152 | `collection-src-directory` to be empty, or it has to be a git repository 153 | checkout where `collection-src-directory`/`collection-root` ends with 154 | `ansible_collections/{namespace}/{name}`, or it has to be a git 155 | repository checkout where `collection-root` is `.`. **(DEFAULT: `false`)** 156 | 157 | 158 | ### `python-version` 159 | 160 | **(DEPRECATED)** Use `origin-python-version` instead. 161 | 162 | 163 | ### `sanity-tests` 164 | 165 | Comma-separated list of sanity tests to run. If not present, all applicable tests are run. 166 | 167 | 168 | ### `sanity-skip-tests` 169 | 170 | Comma-separated list of sanity tests to skip. 171 | 172 | 173 | ### `sanity-allow-disabled` 174 | 175 | Allow running sanity tests that are disabled by default. 176 | **(DEFAULT: `false`)** 177 | 178 | 179 | ### `target` 180 | 181 | `ansible-test` TARGET **(OPTIONAL)** 182 | 183 | 184 | ### `target-python-version` 185 | 186 | Target Python version **(OPTIONAL)** 187 | 188 | 189 | ### `testing-type` 190 | 191 | `ansible-test` subcommand **(REQUIRED, Must be one of 'sanity', 'units' 192 | or 'integration')** 193 | 194 | 195 | ### `test-deps` 196 | 197 | Test dependencies to install along with this collection **(OPTIONAL)** 198 | 199 | 200 | ## Outputs 201 | 202 | 203 | ### `ansible-playbook-executable` 204 | 205 | Path to the auto-installed `ansible-playbook` executable 206 | 207 | 208 | ### `ansible-test-executable` 209 | 210 | Path to the auto-installed `ansible-test` executable 211 | 212 | 213 | ### `checkout-directory` 214 | 215 | Path to the auto-downloaded collection src directory 216 | 217 | 218 | ### `collection-fqcn` 219 | 220 | Detected collection FQCN 221 | 222 | 223 | ### `collection-name` 224 | 225 | Detected collection name 226 | 227 | 228 | ### `collection-namespace` 229 | 230 | Detected collection namespace 231 | 232 | 233 | ### `coverage-report-files` 234 | 235 | A comma-separated list of produced Cobertura XML coverage report file paths 236 | 237 | 238 | ### `origin-python-path` 239 | 240 | The [`python-path` output value][`python-path`] of the [setup-python] action 241 | 242 | 243 | ### `origin-python-version` 244 | 245 | The actual value of `origin-python-version` passed to the [setup-python] action 246 | 247 | 248 | ### `test-result-files` 249 | 250 | A comma-separated list of produced JUnit XML test result file paths 251 | 252 | 253 | ## Related community projects 254 | 255 | Check out the [Data-Bene/ansible-test-versions-gh-action] to explore 256 | a semi-automatic job matrix generation for testing your collections. This 257 | project is not maintained by us but it is a rather promising way of 258 | configuring your GitHub Actions CI/CD workflows. 259 | 260 | [🧪 GitHub Actions CI/CD workflow tests badge]: 261 | https://github.com/ansible-community/ansible-test-gh-action/actions/workflows/test-action.yml/badge.svg?branch=main&event=push 262 | [GHA workflow runs list]: https://github.com/ansible-community/ansible-test-gh-action/actions/workflows/test-action.yml?query=branch%3Amain 263 | 264 | [pre-commit.ci results page]: 265 | https://results.pre-commit.ci/latest/github/ansible-community/ansible-test-gh-action/main 266 | [pre-commit.ci status badge]: 267 | https://results.pre-commit.ci/badge/github/ansible-community/ansible-test-gh-action/main.svg 268 | 269 | [`python-path`]: 270 | https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#python-path 271 | [setup-python]: https://github.com/actions/setup-python/#readme 272 | 273 | [Data-Bene/ansible-test-versions-gh-action]: 274 | https://github.com/Data-Bene/ansible-test-versions-gh-action 275 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: ansible-test 3 | description: >- 4 | GitHub Action for checking Ansible Collections 5 | with ansible-test 6 | branding: 7 | icon: check-circle 8 | color: gray-dark 9 | inputs: 10 | ansible-core-version: 11 | description: >- 12 | `ansible-core` Git revision. See https://github.com/ansible/ansible/tags 13 | and https://github.com/ansible/ansible/branches/all?query=stable- for 14 | ideas. The repository this refers to can be changed with the 15 | `ansible-core-github-repository-slug` option. 16 | default: stable-2.14 17 | required: true 18 | ansible-core-github-repository-slug: 19 | description: The GitHub repository slug from which to check out ansible-core 20 | default: ansible/ansible 21 | codecov-token: 22 | description: >- 23 | The Codecov token to use when uploading coverage data. 24 | controller-python-version: 25 | description: >- 26 | Controller Python version. Only used for integration tests and 27 | ansible-core 2.12 or later when `target-python-version` is also 28 | specified. 29 | default: auto 30 | collection-root: 31 | description: Collection root relative to repository root 32 | default: . 33 | collection-src-directory: 34 | description: >- 35 | A pre-checked out collection directory that's already on disk, 36 | substitutes getting the source from the remote Git repository if 37 | set. This action will not attempt to mutate its contents 38 | coverage: 39 | description: >- 40 | Whether to collect and upload coverage information. Can be set to 41 | `always`, `never`, and `auto`. The value `auto` will upload coverage 42 | information except when `pull-request-change-detection` is set to `true` 43 | and the action is called from a Pull Request. 44 | default: auto 45 | docker-image: 46 | description: Docker image used by ansible-test 47 | git-checkout-ref: 48 | description: >- 49 | Committish to check out, unused 50 | if `collection-src-directory` is set 51 | integration-continue-on-error: 52 | description: >- 53 | Whether the continue with the other integration tests when an error 54 | occurs. If set to `false`, will stop on the first error. When set to 55 | `false` and `coverage=auto`, code coverage uploading will be disabled. 56 | default: 'true' 57 | integration-diff: 58 | description: >- 59 | Whether to show diff output when calling actions in integration tests. 60 | Actions can override this by specifying `diff: false` or `diff: true`. 61 | default: 'true' 62 | integration-retry-on-error: 63 | description: >- 64 | Whether to retry the current integration test once when an error happens. 65 | default: 'true' 66 | origin-python-version: 67 | description: >- 68 | Environment Python version. The value `auto` uses the maximum Python 69 | version supported by the given `ansible-core-version`. 70 | default: auto 71 | pre-test-cmd: 72 | description: Extra command to invoke before ansible-test 73 | pull-request-change-detection: 74 | description: >- 75 | Whether to use change detection for pull requests. If set to `true`, will 76 | use change detection to determine changed files against the target 77 | branch, and will not upload code coverage results. If the invocation is 78 | not from a pull request, this option is ignored. Note that this requires 79 | `collection-src-directory` to be empty, or it has to be a git repository 80 | checkout where `collection-src-directory`/`collection-root` ends with 81 | `ansible_collections/{namespace}/{name}`, or it has to be a git 82 | repository checkout where `collection-root` is `.`. 83 | default: 'false' 84 | python-version: 85 | description: >- 86 | **(DEPRECATED)** Use `origin-python-version` instead. This is only kept 87 | for backwards compatibility. 88 | deprecationMessage: >- 89 | Replace `python-version` with `origin-python-version`. 90 | It is scheduled to be removed in version 3 of this action. 91 | sanity-tests: 92 | description: >- 93 | Comma-separated list of sanity tests to run. 94 | If not present, all applicable tests are run. 95 | sanity-skip-tests: 96 | description: Comma-separated list of sanity tests to skip. 97 | sanity-allow-disabled: 98 | description: Allow sanity tests to run which are disabled by default. 99 | default: 'false' 100 | target: 101 | description: ansible-test TARGET 102 | target-python-version: 103 | description: Target Python version 104 | testing-type: 105 | description: One of 'sanity', 'units' or 'integration' 106 | required: true 107 | test-deps: 108 | description: Test dependencies to install along with this collection 109 | outputs: 110 | ansible-playbook-executable: 111 | description: Path to the auto-installed `ansible-playbook` executable 112 | value: ~/.local/bin/ansible-playbook 113 | ansible-test-executable: 114 | description: Path to the auto-installed `ansible-test` executable 115 | value: ~/.local/bin/ansible-test 116 | checkout-directory: 117 | description: >- 118 | Path to the auto-downloaded 119 | collection src directory 120 | value: ${{ steps.collection-metadata.outputs.checkout-path }} 121 | collection-fqcn: 122 | description: Detected collection FQCN 123 | value: ${{ steps.collection-metadata.outputs.fqcn }} 124 | collection-name: 125 | description: Detected collection name 126 | value: ${{ steps.collection-metadata.outputs.name }} 127 | collection-namespace: 128 | description: Detected collection namespace 129 | value: ${{ steps.collection-metadata.outputs.namespace }} 130 | coverage-report-files: 131 | description: >- 132 | A comma-separated list of produced Cobertura XML coverage 133 | report file paths 134 | value: ${{ steps.exportable-coverage-files.outputs.paths || '' }} 135 | origin-python-path: 136 | description: >- 137 | The [`python-path` output 138 | value](https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#python-path) 139 | of the [setup-python](https://github.com/actions/setup-python/#readme) 140 | action. 141 | value: ${{ steps.setup-python.outputs.python-path }} 142 | origin-python-version: 143 | description: >- 144 | The actual value of `origin-python-version` passed to the 145 | [setup-python](https://github.com/actions/setup-python/#readme) action. 146 | value: >- 147 | ${{ steps.compute-origin-python-version.outputs.origin-python-version }} 148 | test-result-files: 149 | description: >- 150 | A comma-separated list of produced JUnit XML test result file paths 151 | value: ${{ steps.exportable-junit-files.outputs.paths || '' }} 152 | runs: 153 | using: composite 154 | steps: 155 | - name: Log the next step action 156 | run: echo ▷ Figuring out the environment Python version... 157 | shell: bash 158 | - name: Compute job Python version 159 | id: compute-origin-python-version 160 | run: | 161 | # Compute job Python version 162 | import os 163 | import pathlib 164 | import sys 165 | 166 | FILE_APPEND_MODE = 'a' 167 | OUTPUTS_FILE_PATH = pathlib.Path(os.environ['GITHUB_OUTPUT']) 168 | 169 | def set_output(name, value): 170 | with OUTPUTS_FILE_PATH.open(FILE_APPEND_MODE) as outputs_file: 171 | outputs_file.writelines(f'{name}={value}{os.linesep}') 172 | 173 | # Input from GHA 174 | origin_python_version = '${{ inputs.origin-python-version }}' 175 | old_python_version = '${{ inputs.python-version }}' 176 | ansible_core_version = '${{ inputs.ansible-core-version }}' 177 | 178 | # Handle case that deprecated Python version parameter is provided 179 | if old_python_version: 180 | # Check whether the default of origin-python-version was changed 181 | if origin_python_version != 'auto': 182 | print( 183 | '::error ::`python-version` and `origin-python-version` ' 184 | 'cannot both be supplied. Use only `origin-python-version` ' 185 | 'and not its deprecated alias `python-version`.' 186 | ) 187 | sys.exit(1) 188 | 189 | origin_python_version = old_python_version 190 | 191 | if origin_python_version == 'auto': 192 | # Determine the maximum Python version supported by the 193 | # given ansible-core version. 194 | python_version_map = { 195 | 'stable-2.9': (3, 8), 196 | 'stable-2.10': (3, 9), 197 | 'stable-2.11': (3, 9), 198 | 'stable-2.12': (3, 10), 199 | 'stable-2.13': (3, 10), 200 | 'stable-2.14': (3, 11), 201 | 'stable-2.15': (3, 11), 202 | } 203 | python_version_fallback_for_devel = max( 204 | set(python_version_map.values()), 205 | ) 206 | origin_python_version_tuple = python_version_map.get( 207 | ansible_core_version, 208 | # For any non-stable branch, we assume 209 | # the latest version supported by 'devel': 210 | python_version_fallback_for_devel, 211 | ) 212 | origin_python_version = '.'.join( 213 | map(str, origin_python_version_tuple), 214 | ) 215 | 216 | # Set computed origin-python-version 217 | set_output('origin-python-version', origin_python_version) 218 | shell: python 219 | - name: Log the next step action 220 | run: >- 221 | echo ▷ Setting job Python to 222 | ${{ 223 | steps.compute-origin-python-version.outputs.origin-python-version 224 | }}... 225 | shell: bash 226 | - name: >- 227 | Set controller Python to 228 | ${{ steps.compute-origin-python-version.outputs.origin-python-version }} 229 | id: setup-python 230 | uses: actions/setup-python@v5 231 | with: 232 | python-version: >- 233 | ${{ 234 | steps.compute-origin-python-version.outputs.origin-python-version 235 | }} 236 | 237 | - name: Log the next step action 238 | run: >- 239 | echo ▷ Install Python YAML library 240 | shell: bash 241 | - name: Install PyYAML 242 | run: >- 243 | set -x 244 | ; 245 | python -m 246 | pip install 247 | PyYAML 248 | --disable-pip-version-check 249 | --prefer-binary 250 | --user 251 | ; 252 | set +x 253 | shell: bash 254 | 255 | - name: Log the next step action 256 | run: >- 257 | echo ▷ Compose the ansible-test command line 258 | shell: bash 259 | - name: Compose the ansible-test command line 260 | id: ansible-test-command 261 | env: 262 | GHA_ANSIBLE_CORE_VERSION: ${{ inputs.ansible-core-version }} 263 | GHA_CONTAINER_NETWORK: ${{ job.container.network }} 264 | GHA_CONTROLLER_PYTHON_VERSION: ${{ inputs.controller-python-version }} 265 | GHA_COVERAGE: ${{ inputs.coverage }} 266 | GHA_DOCKER_IMAGE: ${{ inputs.docker-image }} 267 | GHA_INTEGRATION_CONTINUE_ON_ERROR: >- 268 | ${{ inputs.integration-continue-on-error }} 269 | GHA_INTEGRATION_DIFF: ${{ inputs.integration-diff }} 270 | GHA_INTEGRATION_RETRY_ON_ERROR: ${{ inputs.integration-retry-on-error }} 271 | GHA_PULL_REQUEST_BASE_REF: ${{ github.event.pull_request.base.ref || '' }} 272 | GHA_PULL_REQUEST_CHANGE_DETECTION: >- 273 | ${{ inputs.pull-request-change-detection }} 274 | GHA_SANITY_TESTS: ${{ inputs.sanity-tests }} 275 | GHA_SANITY_SKIP_TESTS: ${{ inputs.sanity-skip-tests }} 276 | GHA_SANITY_ALLOW_DISABLED: ${{ inputs.sanity-allow-disabled }} 277 | GHA_TARGET: ${{ inputs.target }} 278 | GHA_TARGET_PYTHON_VERSION: ${{ inputs.target-python-version }} 279 | GHA_TESTING_TYPE: ${{ inputs.testing-type }} 280 | run: | 281 | import json 282 | import os 283 | import pathlib 284 | import shlex 285 | import sys 286 | 287 | FILE_APPEND_MODE = 'a' 288 | OUTPUTS_FILE_PATH = pathlib.Path(os.environ['GITHUB_OUTPUT']) 289 | 290 | def set_output(name, value): 291 | with OUTPUTS_FILE_PATH.open(FILE_APPEND_MODE) as outputs_file: 292 | outputs_file.writelines(f'{name}={value}{os.linesep}') 293 | 294 | # Input from GHA 295 | gha_ansible_core_version = os.environ['GHA_ANSIBLE_CORE_VERSION'] 296 | gha_container_network = os.environ['GHA_CONTAINER_NETWORK'] 297 | gha_controller_python_version = ( 298 | os.environ['GHA_CONTROLLER_PYTHON_VERSION'] 299 | ) 300 | gha_coverage = os.environ['GHA_COVERAGE'] 301 | gha_docker_image = os.environ['GHA_DOCKER_IMAGE'] 302 | gha_integration_continue_on_error = json.loads( 303 | os.environ['GHA_INTEGRATION_CONTINUE_ON_ERROR'] 304 | ) 305 | gha_integration_diff = json.loads( 306 | os.environ['GHA_INTEGRATION_DIFF'] 307 | ) 308 | gha_integration_retry_on_error = json.loads( 309 | os.environ['GHA_INTEGRATION_RETRY_ON_ERROR'] 310 | ) 311 | gha_pull_request_branch = os.environ['GHA_PULL_REQUEST_BASE_REF'] 312 | gha_pull_request_change_detection = json.loads( 313 | os.environ['GHA_PULL_REQUEST_CHANGE_DETECTION'] 314 | ) 315 | gha_sanity_tests = os.environ['GHA_SANITY_TESTS'] 316 | gha_sanity_skip_tests = os.environ['GHA_SANITY_SKIP_TESTS'] 317 | gha_sanity_allow_disabled = json.loads( 318 | os.environ['GHA_SANITY_ALLOW_DISABLED'] 319 | ) is True 320 | gha_target = os.environ['GHA_TARGET'] 321 | gha_target_python_version = os.environ['GHA_TARGET_PYTHON_VERSION'] 322 | gha_testing_type = os.environ['GHA_TESTING_TYPE'] 323 | 324 | # Validate GHA inputs 325 | if gha_coverage not in {'always', 'never', 'auto'}: 326 | print( 327 | '::error ::`coverage` must have one of the values `always`,' 328 | f' `never`, or `auto`. The current value is `{gha_coverage}`.' 329 | ) 330 | sys.exit(1) 331 | 332 | # Compose ansible-test arguments 333 | command = [gha_testing_type, '-v', '--color'] 334 | 335 | # Compute coverage and change detection arguments 336 | has_change_detection = ( 337 | gha_pull_request_branch and gha_pull_request_change_detection 338 | ) 339 | if has_change_detection: 340 | if gha_coverage == 'auto': 341 | print( 342 | 'Disabling coverage reporting due to pull request ' 343 | 'change detection being enabled.', 344 | ) 345 | gha_coverage = 'never' 346 | command.extend([ 347 | '--changed', 348 | '--base-branch', 349 | gha_pull_request_branch, 350 | ]) 351 | has_coverage = gha_coverage != 'never' 352 | if has_coverage: 353 | command.append('--coverage') 354 | 355 | if gha_testing_type == 'sanity': 356 | command.append('--junit') 357 | 358 | if gha_sanity_tests: 359 | for test in gha_sanity_tests.split(','): 360 | command.extend([ 361 | '--test', 362 | test.strip(), 363 | ]) 364 | if gha_sanity_skip_tests: 365 | for test in gha_sanity_skip_tests.split(','): 366 | command.extend([ 367 | '--skip-test', 368 | test.strip(), 369 | ]) 370 | if gha_sanity_allow_disabled: 371 | command.append('--allow-disabled') 372 | 373 | if gha_testing_type == 'integration': 374 | if gha_integration_retry_on_error: 375 | command.append('--retry-on-error') 376 | if gha_integration_continue_on_error: 377 | command.append('--continue-on-error') 378 | if gha_integration_diff: 379 | command.append('--diff') 380 | if gha_container_network != '': 381 | command.append(f"--docker-network={gha_container_network}") 382 | 383 | if ( 384 | gha_testing_type == 'integration' 385 | and gha_ansible_core_version not in { 386 | 'stable-2.9', 'stable-2.10', 'stable-2.11' 387 | } 388 | and gha_target_python_version 389 | and gha_controller_python_version not in { 390 | 'auto', gha_target_python_version 391 | } 392 | ): 393 | command.extend([ 394 | '--controller', 395 | f"docker:default,python={gha_controller_python_version}", 396 | '--target', 397 | f"docker:{gha_docker_image or 'default'}," 398 | f"python={gha_target_python_version}", 399 | ]) 400 | else: 401 | command.extend([ 402 | '--docker', 403 | gha_docker_image or 'default', 404 | ]) 405 | if gha_target_python_version: 406 | command.extend([ 407 | '--python', 408 | gha_target_python_version, 409 | ]) 410 | 411 | command.extend(shlex.split(gha_target)) 412 | 413 | set_output('command', shlex.join(command)) 414 | set_output('has-coverage', json.dumps(has_coverage)) 415 | set_output('has-change-detection', json.dumps(has_change_detection)) 416 | shell: python 417 | 418 | - name: Log the next step action 419 | if: >- 420 | !inputs.collection-src-directory 421 | run: >- 422 | echo ▷ Checking out the repository into a temporary location... 423 | shell: bash 424 | - name: Check out the collection 425 | if: >- 426 | !inputs.collection-src-directory 427 | uses: actions/checkout@v4 428 | with: 429 | path: .tmp-ansible-collection-checkout 430 | persist-credentials: false 431 | ref: ${{ inputs.git-checkout-ref }} 432 | fetch-depth: >- 433 | ${{ 434 | steps.ansible-test-command.outputs.has-change-detection == 'true' 435 | && '0' || '1' 436 | }} 437 | 438 | - name: Log the next step action 439 | if: >- 440 | !inputs.collection-src-directory 441 | && steps.ansible-test-command.outputs.has-change-detection == 'true' 442 | run: >- 443 | echo ▷ Create branches for change detection 444 | shell: bash 445 | - name: Create branches for change detection 446 | if: >- 447 | !inputs.collection-src-directory 448 | && steps.ansible-test-command.outputs.has-change-detection == 'true' 449 | run: | 450 | # Create a branch for the current HEAD, which happens to be a merge commit 451 | git checkout -b 'pull-request-${{ github.event.pull_request.number }}' 452 | 453 | # Name the target branch 454 | git branch '${{ 455 | github.event.pull_request.base.ref 456 | }}' --track 'origin/${{ 457 | github.event.pull_request.base.ref 458 | }}' 459 | 460 | # Show branch information 461 | git branch -vv 462 | shell: bash 463 | working-directory: >- 464 | .tmp-ansible-collection-checkout 465 | 466 | - name: Log the next step action 467 | run: >- 468 | echo ▷ Extracting the collection metadata from "'galaxy.yml'"... 469 | shell: bash 470 | - name: Extract the collection metadata 471 | id: collection-metadata 472 | run: | 473 | import os 474 | import pathlib 475 | import yaml 476 | 477 | FILE_APPEND_MODE = 'a' 478 | OUTPUTS_FILE_PATH = pathlib.Path(os.environ['GITHUB_OUTPUT']) 479 | 480 | def set_output(name, value): 481 | with OUTPUTS_FILE_PATH.open(FILE_APPEND_MODE) as outputs_file: 482 | outputs_file.writelines(f'{name}={value}{os.linesep}') 483 | 484 | directory = "${{ 485 | format( 486 | '{0}/{1}', 487 | ( 488 | inputs.collection-src-directory 489 | && inputs.collection-src-directory 490 | || '.tmp-ansible-collection-checkout' 491 | ), 492 | inputs.collection-root 493 | ) 494 | }}" 495 | 496 | COLLECTION_META_FILE = 'galaxy.yml' 497 | with open(os.path.join(directory, COLLECTION_META_FILE)) as galaxy_yml: 498 | collection_meta = yaml.safe_load(galaxy_yml) 499 | 500 | coll_name = collection_meta['name'] 501 | coll_ns = collection_meta['namespace'] 502 | 503 | set_output('name', coll_name) 504 | set_output('namespace', coll_ns) 505 | 506 | set_output('fqcn', f'{coll_ns}.{coll_name}') 507 | 508 | wanted_path = f'ansible_collections{os.sep}{coll_ns}{os.sep}{coll_name}' 509 | if directory.endswith(wanted_path): 510 | set_output('copy-to-checkout-path', 'false') 511 | set_output( 512 | 'collection-namespace-path', 513 | os.path.normpath(os.path.join(directory, '..'))) 514 | set_output('checkout-path', directory) 515 | else: 516 | set_output('copy-to-checkout-path', 'true') 517 | set_output( 518 | 'collection-namespace-path', 519 | os.path.join('ansible_collections', coll_ns)) 520 | set_output( 521 | 'checkout-path', 522 | os.path.join('ansible_collections', coll_ns, coll_name)) 523 | shell: python 524 | 525 | - name: Log the next step action 526 | if: >- 527 | ${{ fromJSON(steps.collection-metadata.outputs.copy-to-checkout-path) }} 528 | run: >- 529 | echo ▷ ${{ inputs.collection-src-directory && 'Copy' || 'Move' }} 530 | "'${{ steps.collection-metadata.outputs.fqcn }}'" 531 | collection to ${{ steps.collection-metadata.outputs.checkout-path }}... 532 | shell: bash 533 | - name: Move the collection to the proper path 534 | if: >- 535 | ${{ fromJSON(steps.collection-metadata.outputs.copy-to-checkout-path) }} 536 | run: >- 537 | set -x 538 | ; 539 | mkdir -pv 540 | "${{ steps.collection-metadata.outputs.collection-namespace-path }}" 541 | ; 542 | ${{ inputs.collection-src-directory && 'cp -a' || 'mv' }} 543 | -v 544 | "${{ 545 | format( 546 | '{0}/{1}', 547 | ( 548 | inputs.collection-src-directory 549 | && inputs.collection-src-directory 550 | || '.tmp-ansible-collection-checkout' 551 | ), 552 | inputs.collection-root != '.' && inputs.collection-root || '' 553 | ) 554 | }}" 555 | "${{ steps.collection-metadata.outputs.checkout-path }}" 556 | ; 557 | set +x 558 | shell: bash 559 | 560 | - name: Log the next step action 561 | run: >- 562 | echo ▷ Installing ansible-core 563 | version ${{ inputs.ansible-core-version }}... 564 | shell: bash 565 | - name: Install ansible-core (${{ inputs.ansible-core-version }}) 566 | run: >- 567 | set -x 568 | ; 569 | python -m pip install 570 | https://github.com/${{ 571 | inputs.ansible-core-github-repository-slug 572 | }}/archive/${{ 573 | inputs.ansible-core-version 574 | }}.tar.gz 575 | --disable-pip-version-check 576 | --user 577 | ; 578 | set +x 579 | shell: bash 580 | 581 | - name: Log the next step action 582 | run: >- 583 | echo ▷ Installing collection 584 | dependencies: ${{ inputs.test-deps }} 585 | shell: bash 586 | - name: Install collection dependencies 587 | # if: inputs.test-deps 588 | # yamllint disable rule:line-length 589 | run: >- 590 | ${{ 591 | inputs.test-deps 592 | && format( 593 | 'set -x; ~/.local/bin/ansible-galaxy collection install {0} -p .; set +x', 594 | inputs.test-deps 595 | ) 596 | || '>&2 echo Skipping installing the dependencies...' 597 | }} 598 | # yamllint enable rule:line-length 599 | shell: bash 600 | 601 | - name: Log the next step action 602 | run: >- 603 | echo ▷ Running a pre-test 604 | command: "'${{ inputs.pre-test-cmd }}'" 605 | shell: bash 606 | - name: Run a pre-test command 607 | # if: inputs.pre-test-cmd 608 | # run: ${{ inputs.pre-test-cmd }} 609 | run: >- 610 | ${{ 611 | inputs.pre-test-cmd 612 | && format('set -x; {0}; set +x', inputs.pre-test-cmd) 613 | || '>&2 echo Skipping running the pre test command...' 614 | }} 615 | shell: bash 616 | working-directory: ${{ steps.collection-metadata.outputs.checkout-path }} 617 | 618 | - name: Log the next step action 619 | run: >- 620 | echo ▷ Running ${{ inputs.testing-type }} tests... 621 | shell: bash 622 | - name: Run ${{ inputs.testing-type }} tests 623 | # yamllint disable rule:line-length 624 | # NOTE: Theoretically, it's best to have a `--` separator before the 625 | # NOTE: targets list but unfortunately, it causes problem with the 626 | # NOTE: arguments bypass when run with `--docker` so for now, it's 627 | # NOTE: not included in the command. 628 | # Refs: 629 | # * https://github.com/ansible-community/ansible-test-gh-action/pull/9#discussion_r748488366 630 | # * https://github.com/ansible-community/ansible-test-gh-action/issues/8#issuecomment-968505014 631 | run: >- 632 | set -x 633 | ; 634 | ~/.local/bin/ansible-test ${{ steps.ansible-test-command.outputs.command }} 635 | ; 636 | set +x 637 | # yamllint enable rule:line-length 638 | shell: bash 639 | working-directory: ${{ steps.collection-metadata.outputs.checkout-path }} 640 | 641 | - name: Identify a list of Junit XML test report files 642 | id: exportable-junit-files 643 | run: >- 644 | set +x 645 | ; 646 | echo -n "paths=" | tee -a "${GITHUB_OUTPUT}" 647 | ; 648 | $( 649 | ( 650 | find '${{ 651 | steps.collection-metadata.outputs.checkout-path 652 | }}/tests/output/junit/' -name '*.xml' -type f -print0 653 | || : 654 | ) 655 | | tr '\0' ',' 656 | | sed 's#,$##' 657 | ) | tee -a "${GITHUB_OUTPUT}" 658 | shell: bash 659 | 660 | - name: Log the next step action 661 | if: steps.ansible-test-command.outputs.has-coverage == 'true' 662 | run: >- 663 | echo ▷ Generating a coverage report... 664 | shell: bash 665 | - name: Generate coverage report 666 | if: steps.ansible-test-command.outputs.has-coverage == 'true' 667 | run: >- 668 | set -x 669 | ; 670 | ~/.local/bin/ansible-test coverage xml 671 | -v --requirements 672 | --group-by command 673 | --group-by version 674 | ; 675 | set +x 676 | shell: bash 677 | working-directory: ${{ steps.collection-metadata.outputs.checkout-path }} 678 | 679 | - name: Identify a list of Cobertura XML coverage files 680 | if: steps.ansible-test-command.outputs.has-coverage == 'true' 681 | id: exportable-coverage-files 682 | run: >- 683 | set +x 684 | ; 685 | echo -n "paths=" | tee -a "${GITHUB_OUTPUT}" 686 | ; 687 | $( 688 | ( 689 | find '${{ 690 | steps.collection-metadata.outputs.checkout-path 691 | }}/tests/output/reports/' -name 'coverage=${{ 692 | inputs.testing-type 693 | }}.xml' -type f -print0 694 | || : 695 | ) 696 | | tr '\0' ',' 697 | | sed 's#,$##' 698 | ) | tee -a "${GITHUB_OUTPUT}" 699 | shell: bash 700 | 701 | - name: Log the next step action 702 | if: steps.ansible-test-command.outputs.has-coverage == 'true' 703 | run: >- 704 | echo ▷ Generating a coverage report only grouped by command... 705 | shell: bash 706 | - name: Generate a coverage report only grouped by command 707 | if: steps.ansible-test-command.outputs.has-coverage == 'true' 708 | run: >- 709 | set -x 710 | ; 711 | ~/.local/bin/ansible-test coverage xml 712 | -v --requirements 713 | --group-by command 714 | ; 715 | set +x 716 | shell: bash 717 | working-directory: ${{ steps.collection-metadata.outputs.checkout-path }} 718 | 719 | - name: Log the next step action 720 | if: steps.exportable-coverage-files.outputs.paths != '' 721 | run: >- 722 | echo ▷ Sending the coverage data over to 723 | https://codecov.io/gh/${{ github.repository }}... 724 | shell: bash 725 | - name: >- 726 | Send the coverage data over to 727 | https://codecov.io/gh/${{ github.repository }} 728 | if: steps.exportable-coverage-files.outputs.paths != '' 729 | uses: codecov/codecov-action@v4.5.0 730 | with: 731 | files: ${{ steps.exportable-coverage-files.outputs.paths }} 732 | flags: ${{ inputs.testing-type }} 733 | token: ${{ inputs.codecov-token }} 734 | working-directory: ${{ steps.collection-metadata.outputs.checkout-path }} 735 | 736 | - name: Produce markdown test summary from JUnit 737 | if: >- 738 | always() 739 | && steps.exportable-junit-files.outputs.paths != '' 740 | uses: test-summary/action@v2 741 | with: 742 | # NOTE: The path is borrowed from 743 | # https://github.com/ansible/ansible/blob/71adb02/.azure-pipelines/scripts/process-results.sh#L6-L10 744 | # which suggests that ansible-core's location is different from 745 | # the collection ones. 746 | # Since we are targeting collections, it's fine for us not to 747 | # have a similar conditional. 748 | paths: >- 749 | ${{ 750 | steps.collection-metadata.outputs.checkout-path 751 | }}/tests/output/junit/*.xml 752 | 753 | - name: Check if Cobertura XML coverage files exist 754 | if: always() 755 | id: coverage-files 756 | run: >- 757 | set +x 758 | ; 759 | ls -1 '${{ 760 | steps.collection-metadata.outputs.checkout-path 761 | }}/tests/output/reports/coverage=${{ 762 | inputs.testing-type 763 | }}.xml' 764 | && ( echo "present=true" >> "${GITHUB_OUTPUT}" ) 765 | ; 766 | exit 0 767 | shell: bash 768 | - name: Produce markdown test summary from Cobertura XML 769 | if: steps.coverage-files.outputs.present == 'true' 770 | uses: irongut/CodeCoverageSummary@v1.3.0 771 | with: 772 | badge: true 773 | filename: >- 774 | ${{ 775 | steps.collection-metadata.outputs.checkout-path 776 | }}/tests/output/reports/coverage=${{ 777 | inputs.testing-type 778 | }}.xml 779 | format: markdown 780 | output: both 781 | # Ref: https://github.com/irongut/CodeCoverageSummary/issues/66 782 | - name: Append coverage results to Job Summary 783 | if: steps.coverage-files.outputs.present == 'true' 784 | run: >- 785 | cat code-coverage-results.md >> "${GITHUB_STEP_SUMMARY}" 786 | shell: bash 787 | 788 | ... 789 | --------------------------------------------------------------------------------