summaryrefslogtreecommitdiffstats
path: root/ansible_collections/infoblox/nios_modules/.github/workflows/ansible-test.yml
blob: 0d14379b5ecb593a64f01e61919bfe806b46e4a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
name: CI
on:
# Run CI against all pushes (direct commits) and Pull Requests
  push:
  pull_request:
  schedule:
    - cron: '0 2 * * 1'

jobs:
  build:
    name: Build collection
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        ansible-version: [stable-2.14]
    steps:
      - name: Check out code
        uses: actions/checkout@v2

      - name: Set up Python 3.10
        uses: actions/setup-python@v1
        with:
          python-version: '3.10'

      - name: Install ansible (${{ matrix.ansible-version }})
        run: pip install pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check

      - name: Build a collection tarball
        run: ansible-galaxy collection build --output-path "${GITHUB_WORKSPACE}/.cache/collection-tarballs"

      - name: Store migrated collection artifacts
        uses: actions/upload-artifact@v1
        with:
          name: collection
          path: .cache/collection-tarballs


###
# Unit tests
#
# https://docs.ansible.com/ansible/latest/dev_guide/testing_units.html

  unit:
    name: Unit Tests
    needs: [build]
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ['3.8', '3.9', '3.10', '3.11']
        ansible-version: [stable-2.14, stable-2.15, stable-2.16, devel]
        exclude:
          - ansible-version: devel
            python-version: '3.8'
          - ansible-version: devel
            python-version: '3.9'
          - ansible-version: stable-2.16
            python-version: '3.8'
          - ansible-version: stable-2.16
            python-version: '3.9'
          - ansible-version: stable-2.15
            python-version: '3.8'
          - ansible-version: stable-2.14
            python-version: '3.8'

    steps:
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install ansible (${{ matrix.ansible-version }}) version
        run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check

      - name: Download migrated collection artifacts
        uses: actions/download-artifact@v1
        with:
          name: collection
          path: .cache/collection-tarballs

      - name: Setup Unit test Pre-requisites
        run: |
          ansible-galaxy collection install .cache/collection-tarballs/*.tar.gz
          git clone https://github.com/ansible/ansible.git -b ${{ matrix.ansible-version }}
          if [ "${{ matrix.ansible-version }}" != "devel" ]; then cp -rf ansible/test/units/compat /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/; fi
          cp -rf ansible/test/units/modules/utils.py /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/
          sed -i 's/units/ansible_collections.infoblox.nios_modules.tests.unit/' /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/utils.py
          if [ -f /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt ]; then pip install -r /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt; fi
      - name: Run Unit tests using ansible-test
        run: ansible-test units -v --color --python ${{ matrix.python-version }} --coverage
        working-directory: /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/

      - name: Generate coverage report
        run: |
          if [ "${{ matrix.ansible-version }}" == "stable-2.14" ]; then 
            pip install coverage==6.5.0;
          elif [ "${{ matrix.ansible-version }}" == "stable-2.15" ]; then
            pip install coverage==6.5.0;
          fi
          ansible-test coverage xml -v --group-by command --group-by version
        working-directory: /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/


###
# Integration tests
#
# https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html

  integration:
    name: Integration tests
    needs: [build]
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ['3.8', '3.9', '3.10', '3.11']
        ansible-version: [stable-2.14, stable-2.15, stable-2.16, devel]
        exclude:
          - ansible-version: devel
            python-version: '3.8'
          - ansible-version: devel
            python-version: '3.9'
          - ansible-version: stable-2.16
            python-version: '3.8'
          - ansible-version: stable-2.16
            python-version: '3.9'
          - ansible-version: stable-2.15
            python-version: '3.8'
          - ansible-version: stable-2.14
            python-version: '3.8'
    steps:
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-version }}

      - name: Check out code
        uses: actions/checkout@v2

      - name: Install ansible-base (${{ matrix.ansible-version }})
        run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check

      - name: Download migrated collection artifacts
        uses: actions/download-artifact@v1
        with:
          name: collection
          path: .cache/collection-tarball

      - name: Install the collection tarball
        run: ansible-galaxy collection install .cache/collection-tarball/*.tar.gz

      - name: Setup Integration test Pre-requisites
        run: |
             sudo apt install libgirepository1.0-dev gcc libcairo2-dev pkg-config python3-dev gir1.2-gtk-3.0
             pip install -r /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/requirements.txt

      # Run the integration tests
      - name: Run integration test
        run: |
             echo $ANSIBLE_NIOSSIM_CONTAINER
             ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python-version }} --docker --coverage
        env:
           ANSIBLE_NIOSSIM_CONTAINER: quay.io/ansible/nios-test-container:3.0.0
        working-directory: /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/

        # ansible-test support producing code coverage date
      - name: Generate coverage report
        run: ansible-test coverage xml -v --requirements --group-by command --group-by version
        working-directory: /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/

      - uses: codecov/codecov-action@v1
        with:
          fail_ci_if_error: false


###
# Sanity tests (REQUIRED)
#
# https://docs.ansible.com/ansible/latest/dev_guide/testing_sanity.html

  sanity:
    name: Sanity Tests
    runs-on: ubuntu-latest
    needs: [build]
    strategy:
      fail-fast: false
      matrix:
        ansible-version: [stable-2.14, stable-2.15, stable-2.16, devel]

    steps:
      - name: Set up Python 3.10
        uses: actions/setup-python@v1
        with:
          # it is just required to run that once as "ansible-test sanity" in the docker image
          # will run on all python versions it supports.
          python-version: '3.10'

      - name: Install ansible (${{ matrix.ansible-version }}) version
        run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check

      - name: Download migrated collection artifacts
        uses: actions/download-artifact@v1
        with:
          name: collection
          path: .cache/collection-tarballs

      - name: Setup Sanity test Pre-requisites
        run: ansible-galaxy collection install .cache/collection-tarballs/*.tar.gz

      # run ansible-test sanity inside of Docker.
      # The docker container has all the pinned dependencies that are required
      # and all python versions ansible supports.
      - name: Run sanity tests
        run: ansible-test sanity --docker -v --color
        working-directory: /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules