| 1 |
name: CI_roles |
| 2 |
on: |
| 3 |
pull_request: |
| 4 |
schedule: |
| 5 |
- cron: "0 6 * * *" |
| 6 |
|
| 7 |
jobs: |
| 8 |
|
| 9 |
# TODO - Consider adding ansible-lint and pylint steps as molecule removed these |
| 10 |
|
| 11 |
roles_matrix: |
| 12 |
runs-on: ubuntu-24.04 |
| 13 |
defaults: |
| 14 |
run: |
| 15 |
working-directory: ansible_collections/community/mongodb |
| 16 |
outputs: |
| 17 |
matrix: ${{ steps.json-list.outputs.roles-to-test }} |
| 18 |
|
| 19 |
steps: |
| 20 |
|
| 21 |
- name: Check out code |
| 22 |
uses: actions/checkout@v4 |
| 23 |
with: |
| 24 |
path: ansible_collections/community/mongodb |
| 25 |
|
| 26 |
- name: Generate module list |
| 27 |
run: | |
| 28 |
find roles -type d -maxdepth 1 -mindepth 1 | cut -d '/' -f2 | awk NF | jq -sRc 'split("\n") | map(select(length > 0))' > int_test_roles.json |
| 29 |
|
| 30 |
- name: Set output variable |
| 31 |
id: json-list |
| 32 |
run: | |
| 33 |
output=$(cat int_test_roles.json) |
| 34 |
echo "roles-to-test=$output" >> $GITHUB_OUTPUT |
| 35 |
echo "$output" |
| 36 |
|
| 37 |
roles: |
| 38 |
runs-on: ubuntu-24.04 |
| 39 |
needs: roles_matrix |
| 40 |
defaults: |
| 41 |
run: |
| 42 |
working-directory: ansible_collections/community/mongodb |
| 43 |
|
| 44 |
strategy: |
| 45 |
matrix: |
| 46 |
python_version: |
| 47 |
- "3.11" |
| 48 |
- "3.12" |
| 49 |
mongodb_role: ${{ fromJson(needs.roles_matrix.outputs.matrix) }} |
| 50 |
|
| 51 |
steps: |
| 52 |
- name: Check out code |
| 53 |
uses: actions/checkout@v4 |
| 54 |
with: |
| 55 |
path: ansible_collections/community/mongodb |
| 56 |
|
| 57 |
- name: Set up Python ${{ matrix.test_scenario.python_version }} |
| 58 |
uses: actions/setup-python@v5 |
| 59 |
with: |
| 60 |
python-version: ${{ matrix.test_scenario.python_version }} |
| 61 |
|
| 62 |
- name: Uninstall existing ansible |
| 63 |
run: sudo apt remove ansible |
| 64 |
|
| 65 |
- name: Ensure wheel is installed |
| 66 |
run: pip install wheel |
| 67 |
|
| 68 |
- name: Install requirements |
| 69 |
run: | |
| 70 |
pip install molecule molecule-docker pytest-testinfra |
| 71 |
|
| 72 |
- name: Add molecule location to path |
| 73 |
run: echo "${HOME}/.local/bin" >> $GITHUB_PATH |
| 74 |
|
| 75 |
- name: Build the collection |
| 76 |
run: ansible-galaxy collection build |
| 77 |
|
| 78 |
- name: Rename the build artifact |
| 79 |
run: mv community-mongodb-*.tar.gz community-mongodb-latest.tar.gz |
| 80 |
|
| 81 |
- name: Install collection |
| 82 |
run: | |
| 83 |
|
| 84 |
ansible-galaxy collection install community-mongodb-*.tar.gz |
| 85 |
|
| 86 |
- name: Run molecule test for ${{ matrix.mongodb_role }} |
| 87 |
run: molecule test |
| 88 |
working-directory: ansible_collections/community/mongodb/roles/${{ matrix.mongodb_role }} |
| 89 |
env: |
| 90 |
ANSIBLE_ALLOW_BROKEN_CONDITIONALS: 1 # need for TASK [Set async_dir for HOME env] |
| 91 |
|
| 92 |
# I don't like this |
| 93 |
- name: Run molecule tests for a few extra mongodb_install role scenarios |
| 94 |
run: | |
| 95 |
molecule test --scenario-name specific_mongodb_version && \ |
| 96 |
molecule test --scenario-name mongodb_hold_packages && \ |
| 97 |
molecule test --scenario-name mongodb_nohold_packages |
| 98 |
if: ${{ matrix.mongodb_role == 'mongodb_install' }} |
| 99 |
working-directory: ansible_collections/community/mongodb/roles/mongodb_install |
| 100 |
env: |
| 101 |
ANSIBLE_ALLOW_BROKEN_CONDITIONALS: 1 |
| 102 |
|
| 103 |
# TODO - This step is hanging, probably on the first molecule test scenario... check why |
| 104 |
#- name: Run molecule tests for extra mongodb_mongod scenarios |
| 105 |
# run: | |
| 106 |
# molecule test --scenario-name custom_db_path && molecule test --scenario-name multiple_bind_ip |
| 107 |
# if: ${{ matrix.mongodb_role == 'mongodb_mongod' }} |
| 108 |
# working-directory: ansible_collections/community/mongodb/roles/mongodb_mongod |
| 109 |
|
| 110 |
- name: Run molecule tests for an extra mongodb_config scenario |
| 111 |
run: | |
| 112 |
molecule test --scenario-name custom_db_path |
| 113 |
if: ${{ matrix.mongodb_role == 'mongodb_config' }} |
| 114 |
working-directory: ansible_collections/community/mongodb/roles/mongodb_config |
| 115 |
env: |
| 116 |
ANSIBLE_ALLOW_BROKEN_CONDITIONALS: 1 |
| 117 |
|
| 118 |
- name: Run molecule tests for an extra mongodb_mongod scenario |
| 119 |
run: | |
| 120 |
molecule test --scenario-name mongodb_version_float |
| 121 |
if: ${{ matrix.mongodb_role == 'mongodb_mongod' }} |
| 122 |
working-directory: ansible_collections/community/mongodb/roles/mongodb_mongod |
| 123 |
env: |
| 124 |
ANSIBLE_ALLOW_BROKEN_CONDITIONALS: 1 |