|
| 1 | +# ansible_test_splitter |
| 2 | + |
| 3 | +This action identifies the targets impacted by the changes on a pull request and split them into a number of jobs defined by the user. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +<!-- start usage --> |
| 8 | + |
| 9 | +```yaml |
| 10 | +- uses: ansible-network/github_actions/.github/actions/ansible_test_splitter@main |
| 11 | + with: |
| 12 | + # Path to a list of collections |
| 13 | + collections_to_test: | |
| 14 | + path_to_collection_1 |
| 15 | + path_to_collection_2 |
| 16 | + (...) |
| 17 | + path_to_collection_n |
| 18 | +
|
| 19 | + # The total number of jobs to share |
| 20 | + total_jobs: 5 |
| 21 | +``` |
| 22 | +
|
| 23 | +The action output is a variable `test_targets` containing a list of chunk for each collection with the targets for each chunk. |
| 24 | +e.g: `community.aws-1:dynamodb_table;community.aws-2:elb_target;community.aws-3:msk_cluster-auth;community.aws-4:secretsmanager_secret;community.aws-5:redshift,ec2_transit_gateway_vpc_attachment` |
| 25 | + |
| 26 | +<!-- end usage --> |
| 27 | + |
| 28 | +## Relationship between plugins/roles and targets |
| 29 | + |
| 30 | +This action reads elements to test from `plugins` and `roles` directories and corresponding tests from `tests/integration/targets` directory. Here after more details on the relationship between plugins/roles and integration tests targets: |
| 31 | + |
| 32 | +- `modules`, the test target should have the same name as the module or defines the module name into the `aliases` file |
| 33 | + |
| 34 | +_Example_: |
| 35 | + |
| 36 | +``` |
| 37 | + |___plugins/modules/my_module.py |
| 38 | + |___tests |
| 39 | + |___integration |
| 40 | + |___targets |
| 41 | + |___my_module |
| 42 | + |___another_test |
| 43 | + |___aliases (contains this line my_module) |
| 44 | +``` |
| 45 | + |
| 46 | +For any change on `plugins/modules/my_module.py`, this action will produce `my_module` and `another_test` as impacted targets. |
| 47 | + |
| 48 | +- `roles`, the test target should defines the role name with the prefix `role` into the `aliases` file. |
| 49 | + |
| 50 | +_Example_: |
| 51 | + |
| 52 | +``` |
| 53 | + |___roles/some_role |
| 54 | + |___tests |
| 55 | + |___integration |
| 56 | + |___targets |
| 57 | + |___test_of_some_role |
| 58 | + |___aliases (contains this line role/some_role) |
| 59 | +``` |
| 60 | + |
| 61 | +For any change on `roles/some_role`, this action will produce `test_of_some_role` as impacted target. |
| 62 | + |
| 63 | +- For any other plugin (inventory, connection, module_utils, plugin_utils, lookup), the test target should have the same name as the plugin or defines the plugin name prefixed by the plugin type and underscore (e.g: **inventory_myinventory**) into the `aliases` file. |
| 64 | + |
| 65 | +_Example_: |
| 66 | + |
| 67 | +``` |
| 68 | + |___plugins/lookup/random.py |
| 69 | + |___tests |
| 70 | + |___integration |
| 71 | + |___targets |
| 72 | + |___lookup_random |
| 73 | + |___test_random |
| 74 | + |___aliases (contains this line lookup_random) |
| 75 | +``` |
| 76 | + |
| 77 | +For any change on `plugins/lookup/random.py`, this action will produce `lookup_random` and `test_random` as impacted targets. |
| 78 | + |
| 79 | +## Debugging |
| 80 | + |
| 81 | +- Set the label `test-all-the-targets` on the pull request to run the full test suite instead of the impacted changes. |
| 82 | +- Use `TargetsToTest=collection1:target01,target02;collection2:target03,target4` in the pull request description to run a specific list of targets. |
| 83 | + _Example_: You need to test the following targets for a pull request |
| 84 | + |
| 85 | +```yaml |
| 86 | +- collection1: some_test_1 some_test_2 |
| 87 | +- collection2: another_test |
| 88 | +``` |
| 89 | + |
| 90 | +The pull request should contain the following line `TargetsToTest=collection1:some_test_1,some_test_2;collection2:another_test`. |
0 commit comments