summaryrefslogtreecommitdiff
path: root/.github/workflows/codecoverage.yml
blob: cefc5ddbd8c53d91dc8147f741a9601de693f7cf (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
---
name: Code Coverage
# cloned from ansible-network/github_actions/.github/workflows/coverage_network_devices.yml@main
# in order to deal with token issue in codecov

on: # yamllint disable-line rule:truthy
  push:
  pull_request:
    branches: [main]
jobs:
  codecoverage:
    env:
      PY_COLORS: "1"
      source_directory: "./source"
      python_version: "3.10"
      ansible_version: "latest"
      os: "ubuntu-latest"
      collection_pre_install: >-
        git+https://github.com/ansible-collections/ansible.utils.git
        git+https://github.com/ansible-collections/ansible.netcommon.git
    runs-on: ubuntu-latest
    name: "Code Coverage | Python 3.10"
    steps:
      - name: Checkout the collection repository
        uses: ansible-network/github_actions/.github/actions/checkout_dependency@main
        with:
          path: ${{ env.source_directory }}
          ref: ${{ github.event.pull_request.head.sha }}
          fetch-depth: "0"

      - name: Set up Python ${{ env.python_version }}
        uses: actions/setup-python@v7
        with:
          python-version: ${{ env.python_version }}

      - name: Install ansible-core (${{ env.ansible-version }})
        run: python3 -m pip install ansible-core pytest pytest-cov pytest-ansible-units pytest-forked pytest-xdist

      - name: Read collection metadata from galaxy.yml
        id: identify
        uses: ansible-network/github_actions/.github/actions/identify_collection@main
        with:
          source_path: ${{ env.source_directory }}

      - name: Build and install the collection
        uses: ansible-network/github_actions/.github/actions/build_install_collection@main
        with:
          install_python_dependencies: true
          source_path: ${{ env.source_directory }}
          collection_path: ${{ steps.identify.outputs.collection_path }}
          tar_file: ${{ steps.identify.outputs.tar_file }}

      - name: Print the ansible version
        run: ansible --version

      - name: Print the python dependencies
        run: python3 -m pip list

      - name: Run Coverage tests
        run: |
          pytest tests/unit -v --cov-report xml --cov=./ --junitxml=test-results/junit-codecoverage-codecoverage-pytest-s0.xml
        working-directory: ${{ steps.identify.outputs.collection_path }}

      - name: Upload coverage report to Codecov
        uses: codecov/codecov-action@v7.0.0
        with:
          directory: ${{ steps.identify.outputs.collection_path }}
          fail_ci_if_error: false
          token: ${{ secrets.CODECOV_TOKEN }}
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

      - name: Upload test results to Codecov
        if: >-
          ${{ !cancelled() &&
              (github.event_name != 'pull_request' ||
               github.event.pull_request.head.repo.fork == false) &&
              github.actor != 'dependabot[bot]' }}
        uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
        timeout-minutes: 5
        continue-on-error: true
        with:
          report_type: test_results
          files: ${{ steps.identify.outputs.collection_path }}/test-results/junit-codecoverage-codecoverage-pytest-s0.xml
          disable_search: true
          fail_ci_if_error: false
          flags: unit-pytest-s0
          name: unit-pytest-s0
          version: v11.3.1