Improve pr 792 #326
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: "Collection Tests" | |
| concurrency: | |
| group: ${{ github.head_ref || github.run_id }} | |
| cancel-in-progress: true | |
| on: # yamllint disable-line rule:truthy | |
| pull_request: | |
| branches: [main, devel, master] | |
| push: | |
| branches: [main, devel, master] | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 0 * * *' | |
| jobs: | |
| changelog: | |
| uses: ansible/ansible-content-actions/.github/workflows/changelog.yaml@main | |
| if: github.event_name == 'pull_request' | |
| build-import: | |
| name: build-import-collection | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| collection: [juniper/device, junipernetworks/junos] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Ensure ansible-core and galaxy-importer is installed | |
| shell: bash | |
| run: | | |
| python -m pip install ansible-core galaxy-importer | |
| - name: Update galaxy-importer cfg | |
| shell: bash | |
| run: | | |
| echo "[galaxy-importer]\nCHECK_REQUIRED_TAGS=True" > /tmp/galaxy-importer.cfg | |
| export GALAXY_IMPORTER_CONFIG=/tmp/galaxy-importer.cfg | |
| - name: Build the collection tarball and run galaxy importer on it | |
| shell: bash | |
| working-directory: ansible_collections/${{ matrix.collection }} | |
| run: | | |
| python -m galaxy_importer.main --git-clone-path . --output-path /tmp | |
| ansible-lint: | |
| uses: ansible/ansible-content-actions/.github/workflows/ansible_lint.yaml@main | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| collection: [juniper/device, junipernetworks/junos] | |
| with: | |
| working_directory: ansible_collections/${{ matrix.collection }} | |
| sanity: | |
| name: Sanity Tests | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| collection: [juniper/device, junipernetworks/junos] | |
| include: | |
| - python: "3.10" | |
| ansible: "2.17" | |
| - python: "3.11" | |
| ansible: "2.17" | |
| - python: "3.11" | |
| ansible: "2.18" | |
| - python: "3.11" | |
| ansible: "2.19" | |
| - python: "3.12" | |
| ansible: "2.17" | |
| - python: "3.12" | |
| ansible: "2.18" | |
| - python: "3.12" | |
| ansible: "2.19" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: "${{ github.event.pull_request.head.sha }}" | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "${{ matrix.python }}" | |
| - name: "Install tox-ansible, includes tox" | |
| run: python -m pip install tox-ansible | |
| - name: "Check for tox-ansible.ini file, else add default" | |
| uses: ansible/ansible-content-actions/.github/actions/add_tox_ansible@main | |
| - name: Copy tox-ansible.ini to collection directory | |
| run: | | |
| if [ -f tox-ansible.ini ]; then | |
| cp tox-ansible.ini ansible_collections/${{ matrix.collection }}/ | |
| fi | |
| - name: Run tox sanity tests | |
| working-directory: ansible_collections/${{ matrix.collection }} | |
| run: >- | |
| python -m tox --ansible -c tox-ansible.ini -e sanity-py${{ matrix.python }}-${{ matrix.ansible }} | |
| env: | |
| GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | |
| unit-galaxy: | |
| name: Unit Tests (Galaxy) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| collection: [juniper/device, junipernetworks/junos] | |
| include: | |
| - python: "3.10" | |
| ansible: "2.17" | |
| - python: "3.11" | |
| ansible: "2.17" | |
| - python: "3.11" | |
| ansible: "2.18" | |
| - python: "3.11" | |
| ansible: "2.19" | |
| - python: "3.12" | |
| ansible: "2.17" | |
| - python: "3.12" | |
| ansible: "2.18" | |
| - python: "3.12" | |
| ansible: "2.19" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: "${{ github.event.pull_request.head.ref }}" | |
| repository: "${{ github.event.pull_request.head.repo.full_name }}" | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "${{ matrix.python }}" | |
| - name: Install Dependencies | |
| if: matrix.collection == 'junipernetworks/junos' | |
| run: | | |
| # 1. Install ansible.netcommon | |
| ansible-galaxy collection install ansible.netcommon | |
| # 2. Install ncclient (Required to fix the 'new_ele' bug in netcommon) | |
| python -m pip install ncclient | |
| # 3. Install juniper.device directly from the local folder | |
| # This links the local code without creating a tarball | |
| ansible-galaxy collection install ansible_collections/juniper/device/ --force | |
| - name: "Install tox-ansible, includes tox" | |
| run: python -m pip install tox-ansible | |
| - name: "Check for tox-ansible.ini file, else add default" | |
| uses: ansible/ansible-content-actions/.github/actions/add_tox_ansible@main | |
| - name: Copy tox-ansible.ini to collection directory | |
| run: | | |
| if [ -f tox-ansible.ini ]; then | |
| cp tox-ansible.ini ansible_collections/${{ matrix.collection }}/ | |
| fi | |
| - name: Run tox unit tests | |
| working-directory: ansible_collections/${{ matrix.collection }} | |
| run: >- | |
| python -m tox --ansible -c tox-ansible.ini -e unit-py${{ matrix.python }}-${{ matrix.ansible }} | |
| env: | |
| GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | |
| unit-source: | |
| name: Unit Tests (Source) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| collection: [juniper/device, junipernetworks/junos] | |
| include: | |
| - ansible_version: "stable-2.16" | |
| python_version: "3.11" | |
| - ansible_version: "stable-2.17" | |
| python_version: "3.11" | |
| - ansible_version: "stable-2.18" | |
| python_version: "3.11" | |
| - ansible_version: "stable-2.19" | |
| python_version: "3.11" | |
| - ansible_version: "stable-2.20" | |
| python_version: "3.12" | |
| - ansible_version: "milestone" | |
| python_version: "3.12" | |
| - ansible_version: "devel" | |
| python_version: "3.12" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "${{ matrix.python_version }}" | |
| - name: Install ansible-compat, for tests | |
| run: python -m pip install ansible-compat | |
| - name: Install test dependencies | |
| run: | | |
| python -m pip install pytest pytest-xdist pytest-cov lxml | |
| - name: Install ansible-core (${{ matrix.ansible_version }}) | |
| run: | | |
| if [ "${{ matrix.ansible_version }}" = "devel" ] || [ "${{ matrix.ansible_version }}" = "milestone" ]; then | |
| python -m pip install git+https://github.com/ansible/ansible.git@${{ matrix.ansible_version }} | |
| else | |
| python -m pip install git+https://github.com/ansible/ansible.git@${{ matrix.ansible_version }} | |
| fi | |
| - name: Install collection dependencies | |
| run: | | |
| # Using '-p .' installs the collections into ./ansible_collections/ | |
| # This structure allows ansible-test to find the dependencies (netcommon/utils) | |
| # without needing them installed in the system/user path. | |
| ansible-galaxy collection install ansible.netcommon ansible.utils -p . | |
| - name: Read collection metadata from galaxy.yml | |
| working-directory: ansible_collections/${{ matrix.collection }} | |
| run: | | |
| python -c "import yaml; print(yaml.safe_load(open('galaxy.yml'))['version'])" | |
| - name: Build and install the collection | |
| working-directory: ansible_collections/${{ matrix.collection }} | |
| run: | | |
| ansible-galaxy collection build --force | |
| ansible-galaxy collection install *-*.tar.gz --force | |
| - name: Print the ansible version | |
| run: ansible --version | |
| - name: Print the python dependencies | |
| run: python -m pip list | |
| - name: Run unit tests | |
| working-directory: ansible_collections/${{ matrix.collection }} | |
| run: | | |
| if [ -d "tests/unit" ]; then | |
| # Fix pycrypto here as well for unit-source | |
| if [ -f "requirements.txt" ]; then sed -i 's/pycrypto/pycryptodome/g' requirements.txt; fi | |
| ansible-test units --python ${{ matrix.python_version }} --local --requirements | |
| else | |
| echo "No unit tests directory found, skipping" | |
| fi | |
| all_green: | |
| if: ${{ always() && (github.event_name != 'schedule') }} | |
| needs: | |
| - changelog | |
| - build-import | |
| - sanity | |
| - unit-galaxy | |
| - ansible-lint | |
| - unit-source | |
| runs-on: ubuntu-latest | |
| steps: | |
| - run: >- | |
| python -c "assert 'failure' not in | |
| set([ | |
| '${{ needs.changelog.result }}', | |
| '${{ needs.build-import.result }}', | |
| '${{ needs.sanity.result }}', | |
| '${{ needs.unit-galaxy.result }}', | |
| '${{ needs.ansible-lint.result }}', | |
| '${{ needs.unit-source.result }}' | |
| ])" |