|
| 1 | +name: Test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + pull_request: |
| 8 | + types: |
| 9 | + - opened |
| 10 | + - synchronize |
| 11 | + schedule: |
| 12 | + # cron every week on monday |
| 13 | + - cron: "0 0 * * 1" |
| 14 | + |
| 15 | +jobs: |
| 16 | + test: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] |
| 21 | + fail-fast: false |
| 22 | + steps: |
| 23 | + - name: Dump GitHub context |
| 24 | + env: |
| 25 | + GITHUB_CONTEXT: ${{ toJson(github) }} |
| 26 | + run: echo "$GITHUB_CONTEXT" |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + - name: Set up Python |
| 29 | + uses: actions/setup-python@v5 |
| 30 | + with: |
| 31 | + python-version: ${{ matrix.python-version }} |
| 32 | + # Issue ref: https://github.com/actions/setup-python/issues/436 |
| 33 | + # cache: "pip" |
| 34 | + # cache-dependency-path: pyproject.toml |
| 35 | + - uses: actions/cache@v3 |
| 36 | + id: cache |
| 37 | + with: |
| 38 | + path: ${{ env.pythonLocation }} |
| 39 | + key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }} |
| 40 | + - name: Install Dependencies |
| 41 | + if: steps.cache.outputs.cache-hit != 'true' |
| 42 | + run: pip install -r requirements-tests.txt |
| 43 | + - name: Lint |
| 44 | + run: bash scripts/lint.sh |
| 45 | + - run: mkdir coverage |
| 46 | + - run: bash ./scripts/test-files.sh |
| 47 | + - name: Test |
| 48 | + run: bash scripts/test.sh |
| 49 | + env: |
| 50 | + COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }} |
| 51 | + CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }} |
| 52 | + - name: Store coverage files |
| 53 | + uses: actions/upload-artifact@v3 |
| 54 | + with: |
| 55 | + name: coverage |
| 56 | + path: coverage |
| 57 | + |
| 58 | + coverage-combine: |
| 59 | + needs: [test] |
| 60 | + runs-on: ubuntu-latest |
| 61 | + steps: |
| 62 | + - name: Dump GitHub context |
| 63 | + env: |
| 64 | + GITHUB_CONTEXT: ${{ toJson(github) }} |
| 65 | + run: echo "$GITHUB_CONTEXT" |
| 66 | + - uses: actions/checkout@v4 |
| 67 | + - uses: actions/setup-python@v5 |
| 68 | + with: |
| 69 | + python-version: '3.8' |
| 70 | + # Issue ref: https://github.com/actions/setup-python/issues/436 |
| 71 | + # cache: "pip" |
| 72 | + # cache-dependency-path: pyproject.toml |
| 73 | + - name: Get coverage files |
| 74 | + uses: actions/download-artifact@v3 |
| 75 | + with: |
| 76 | + name: coverage |
| 77 | + path: coverage |
| 78 | + - run: pip install coverage[toml] |
| 79 | + - run: ls -la coverage |
| 80 | + - run: coverage combine coverage |
| 81 | + - run: coverage report |
| 82 | + - run: coverage html --show-contexts --title "Coverage for ${{ github.sha }}" |
| 83 | + - name: Store coverage HTML |
| 84 | + uses: actions/upload-artifact@v3 |
| 85 | + with: |
| 86 | + name: coverage-html |
| 87 | + path: htmlcov |
| 88 | + |
| 89 | + # https://github.com/marketplace/actions/alls-green#why |
| 90 | + check: # This job does nothing and is only used for the branch protection |
| 91 | + if: always() |
| 92 | + needs: |
| 93 | + - coverage-combine |
| 94 | + runs-on: ubuntu-latest |
| 95 | + steps: |
| 96 | + - name: Dump GitHub context |
| 97 | + env: |
| 98 | + GITHUB_CONTEXT: ${{ toJson(github) }} |
| 99 | + run: echo "$GITHUB_CONTEXT" |
| 100 | + - name: Decide whether the needed jobs succeeded or failed |
| 101 | + uses: re-actors/alls-green@release/v1 |
| 102 | + with: |
| 103 | + jobs: ${{ toJSON(needs) }} |
0 commit comments