summaryrefslogtreecommitdiffstats
path: root/ansible_collections/sensu/sensu_go/.circleci/config.yml
blob: 96612ff4e4debc57149a327cc14931af11806f00 (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
version: "2.1"

workflows:
  version: 2
  main_workflow:
    jobs:
      - sanity_test:
          matrix: &matrix
            parameters:
              # ansible is branch name in ansible/ansible git repo
              ansible:
                - stable-2.9
                - stable-2.10
                - stable-2.11
                - stable-2.12
                - stable-2.13
                - stable-2.14


      - unit_test:
          matrix: *matrix

      - integration_test_git:
          requires:
            - sanity_test
            - unit_test
          matrix: *matrix

      - integration_test_galaxy:
          filters: { branches: { only: [ stable ] } }
          requires:
            - integration_test_git
          matrix: *matrix

  cron_master:
    triggers:
      - schedule:
          cron: "12 5 * * 0,3"
          filters: { branches: { only: [ master ] } }
    jobs:
      - integration_test_git:
          matrix: *matrix

  cron_released:
    triggers:
      - schedule:
          cron: "12 5 * * 1,4"
          filters: { branches: { only: [ stable ] } }
    jobs:
      - integration_test_galaxy:
          matrix: *matrix

  cron_ansible_devel:
    triggers:
      - schedule:
          cron: "12 5 * * 2,5"
          filters: { branches: { only: [ master ] } }
    jobs:
      - sanity_test:
          matrix: &devel-matrix
            parameters:
              ansible: [ devel ]

      - unit_test:
          matrix: *devel-matrix

      - integration_test_git:
          requires:
            - sanity_test
            - unit_test
          matrix: *devel-matrix

  windows_version_check:
    triggers:
      - schedule:
          cron: "12 3 * * 0,2,4"
          filters: { branches: { only: [ master ] } }
    jobs:
      - windows_version_check

jobs:
  sanity_test:
    parameters:
      ansible:
        description: Ansible version to use
        type: string
    machine: &ci-machine
      image: ubuntu-2004:202101-01
    working_directory: ~/ansible_collections/sensu/sensu_go
    steps:
      - wrapper:
          ansible: << parameters.ansible >>
          kind: sanity
          test_commands:
            - run: make sanity

  unit_test:
    parameters:
      ansible:
        description: Ansible version to use
        type: string
    machine: *ci-machine
    working_directory: ~/ansible_collections/sensu/sensu_go
    steps:
      - wrapper:
          ansible: << parameters.ansible >>
          kind: sanity
          test_commands:
            - run: make units
            - store_artifacts:
                path: tests/output/reports/coverage
                destination: coverage-report
            - store_test_results:
                path: tests/output/junit

  integration_test_git:
    parallelism: 6
    parameters:
      ansible:
        description: Ansible version to use
        type: string
    machine: *ci-machine
    working_directory: ~/sensu_go
    steps:
      - wrapper:
          ansible: << parameters.ansible >>
          kind: integration
          test_commands:
            - run: ansible-galaxy collection build
            - run: ansible-galaxy collection install sensu-sensu_go-*.tar.gz
            - run_integration_tests

  integration_test_galaxy:
    parallelism: 6
    parameters:
      ansible:
        description: Ansible version to use
        type: string
    machine: *ci-machine
    working_directory: ~/sensu_go
    steps:
      - wrapper:
          ansible: << parameters.ansible >>
          kind: integration
          test_commands:
            - run: |
                ansible-galaxy collection install \
                  sensu.sensu_go:$(grep version: galaxy.yml | cut -d" " -f2)
            - run_integration_tests

  windows_version_check:
    docker:
      - image: cimg/python:3.10.6
    steps:
      - checkout
      - run: pip3 install pyyaml
      - run: make check_windows_versions

commands:
  run_integration_tests:
    description: Run integration tests
    steps:
      - run: ansible-galaxy collection install community.docker
      - run:
          name: Display scheduled scenarios
          command: |
            circleci tests glob "tests/integration/molecule/*/molecule.yml" \
             | circleci tests split --split-by=timings
      - run: make integration_ci
      - store_test_results:
          path: test_results
      - store_artifacts:
          path: test_results

  wrapper:
    description: Wrapper command that takes care of venv caching
    parameters:
      ansible:
        description: Ansible version to install
        type: string
      kind:
        description: Test kind (used to construct cache name)
        type: string
      test_commands:
        description: Test commands to execute
        type: steps
    steps:
      - checkout: { path: . }
      - run:
          name: Generate cache id file
          command: |
            rm -f cache-id.txt
            echo "week $(date +%V)" >> cache-id.txt
            echo "ansible << parameters.ansible >>" >> cache-id.txt
            echo "kind << parameters.kind >>" >> cache-id.txt
            echo "cache busting string 2" >> cache-id.txt
      - restore_cache:
          key: '{{ checksum "cache-id.txt" }}'
      - run:
          name: Install Ansible
          command: pip3 install -U https://github.com/ansible/ansible/archive/<< parameters.ansible >>.tar.gz --disable-pip-version-check
      - steps: << parameters.test_commands >>
      - save_cache:
          key: '{{ checksum "cache-id.txt" }}'
          paths:
            - "~/venv"