diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml new file mode 100644 index 0000000..b589630 --- /dev/null +++ b/.github/workflows/test-action.yml @@ -0,0 +1,73 @@ +--- +name: ๐Ÿงช +on: + push: + pull_request: + +jobs: + tests: + name: >- + โ’ถ${{ matrix.ansible-core-version }} + @ + ๐Ÿ${{ matrix.python-version }}: + ${{ matrix.testing-type }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + docker-image: + - default + git-checkout-ref: + - + pre-test-cmd: + - + target: + - + target-python-version: + - + test-deps: + - + include: + - ansible-core-version: stable-2.12 + python-version: '3.8' + testing-type: sanity + - ansible-core-version: devel + python-version: '3.9' + testing-type: units + - ansible-core-version: stable-2.13 + python-version: '3.10' + testing-type: integration + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + path: .tmp-action-checkout/ + + - name: Run ${{ matrix.testing-type }} tests + uses: ./.tmp-action-checkout/ + with: + ansible-core-version: ${{ matrix.ansible-core-version }} + collection-root: .internal/ansible/ansible_collections/internal/test + docker-image: ${{ matrix.docker-image }} + git-checkout-ref: ${{ matrix.git-checkout-ref }} + pre-test-cmd: ${{ matrix.pre-test-cmd }} + python-version: ${{ matrix.python-version }} + target: ${{ matrix.target }} + target-python-version: ${{ matrix.target-python-version }} + testing-type: ${{ matrix.testing-type }} + test-deps: ${{ matrix.test-deps }} + + check: # This job does nothing and is only used for the branch protection + if: always() + + needs: + - tests + + runs-on: Ubuntu-latest + + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} +... diff --git a/.internal/ansible/ansible_collections/internal/test/galaxy.yml b/.internal/ansible/ansible_collections/internal/test/galaxy.yml new file mode 100644 index 0000000..0291fa4 --- /dev/null +++ b/.internal/ansible/ansible_collections/internal/test/galaxy.yml @@ -0,0 +1,8 @@ +--- +namespace: internal +name: test +description: A collection internal to this repository for running tests. +version: 0.1.0 +readme: README.md +authors: +- Felix Fontein (@felixfontein) diff --git a/.internal/ansible/ansible_collections/internal/test/plugins/modules/test.py b/.internal/ansible/ansible_collections/internal/test/plugins/modules/test.py new file mode 100644 index 0000000..6ad88fe --- /dev/null +++ b/.internal/ansible/ansible_collections/internal/test/plugins/modules/test.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Copyright (c) 2022 Felix Fontein +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +DOCUMENTATION = r''' +--- +module: test +short_description: Test module +version_added: 0.1.0 +author: + - Felix Fontein (@felixfontein) +description: + - Just a test. +notes: + - Does not support C(check_mode). + +options: + test: + description: Some string that is echoed back. + required: true + type: str +''' + +EXAMPLES = r''' +- name: Does nothing + internal.test.test: + test: foo +''' + +RETURN = r''' +test: + description: The value of the I(test) input. + type: str + returned: success +''' + +from ansible.module_utils.basic import AnsibleModule + + +def main(): + module = AnsibleModule(argument_spec={'test': {'type': 'str', 'required': True}}) + module.exit_json(test=module.params['test']) + + +if __name__ == '__main__': + main() diff --git a/.internal/ansible/ansible_collections/internal/test/tests/.gitignore b/.internal/ansible/ansible_collections/internal/test/tests/.gitignore new file mode 100644 index 0000000..16be8f2 --- /dev/null +++ b/.internal/ansible/ansible_collections/internal/test/tests/.gitignore @@ -0,0 +1 @@ +/output/ diff --git a/.internal/ansible/ansible_collections/internal/test/tests/integration/targets/test/aliases b/.internal/ansible/ansible_collections/internal/test/tests/integration/targets/test/aliases new file mode 100644 index 0000000..a6dafcf --- /dev/null +++ b/.internal/ansible/ansible_collections/internal/test/tests/integration/targets/test/aliases @@ -0,0 +1 @@ +shippable/posix/group1 diff --git a/.internal/ansible/ansible_collections/internal/test/tests/integration/targets/test/tasks/main.yml b/.internal/ansible/ansible_collections/internal/test/tests/integration/targets/test/tasks/main.yml new file mode 100644 index 0000000..fa38421 --- /dev/null +++ b/.internal/ansible/ansible_collections/internal/test/tests/integration/targets/test/tasks/main.yml @@ -0,0 +1,10 @@ +--- +- name: Call module + test: + test: foo + register: result + +- name: Check return value + assert: + that: + - result.test == 'foo' diff --git a/.internal/ansible/ansible_collections/internal/test/tests/unit/plugins/modules/test_test.py b/.internal/ansible/ansible_collections/internal/test/tests/unit/plugins/modules/test_test.py new file mode 100644 index 0000000..f2a59bf --- /dev/null +++ b/.internal/ansible/ansible_collections/internal/test/tests/unit/plugins/modules/test_test.py @@ -0,0 +1,50 @@ +# Copyright (c) 2020 Felix Fontein +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import json + +import pytest + +from ansible.module_utils import basic +from ansible.module_utils.common.text.converters import to_bytes + +from ansible_collections.internal.test.plugins.modules import test + +try: + from unittest import mock +except ImportError: + import mock + + +def set_module_args(args): + if '_ansible_remote_tmp' not in args: + args['_ansible_remote_tmp'] = '/tmp' + if '_ansible_keep_remote_files' not in args: + args['_ansible_keep_remote_files'] = False + + args = json.dumps({'ANSIBLE_MODULE_ARGS': args}) + basic._ANSIBLE_ARGS = to_bytes(args) + + +class AnsibleExitJson(Exception): + def __init__(self, kwargs): + self.kwargs = kwargs + + +def exit_json(*args, **kwargs): + if 'changed' not in kwargs: + kwargs['changed'] = False + raise AnsibleExitJson(kwargs) + + +def test_test(): + set_module_args({'test': 'foo'}) + with mock.patch.multiple(basic.AnsibleModule, exit_json=exit_json): + with pytest.raises(AnsibleExitJson) as e: + test.main() + assert 'test' in e.value.kwargs + assert e.value.kwargs['test'] == 'foo' diff --git a/README.md b/README.md index c5153e4..0e66fa8 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,11 @@ and https://github.com/ansible/ansible/branches/all?query=stable- for ideas **(DEFAULT: `stable-2.13`)** +### `collection-root` + +Path to collection root relative to repository root **(DEFAULT: `.`)** + + ### `docker-image` A container image spawned by `ansible-test` **(OPTIONAL)** diff --git a/action.yml b/action.yml index e30fff5..fae1db3 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,9 @@ inputs: ideas. default: stable-2.13 required: true + collection-root: + description: Collection root relative to repository root + default: . docker-image: description: Docker image used by ansible-test default: @@ -145,7 +148,7 @@ runs: format(name=coll_name, ns=coll_ns) ) shell: python - working-directory: .tmp-ansible-collection-checkout + working-directory: .tmp-ansible-collection-checkout/${{ inputs.collection-root }} - name: Close an expandable block of code run: >- echo ::endgroup:: @@ -164,7 +167,7 @@ runs: "${{ steps.collection-metadata.outputs.collection-namespace-path }}" ; mv -v - ".tmp-ansible-collection-checkout" + ".tmp-ansible-collection-checkout/${{ inputs.collection-root }}" "${{ steps.collection-metadata.outputs.checkout-path }}" ; set +x