|
| 1 | +# Runs all tests and pushes coverage report to codeclimate |
| 2 | +name: Coverage |
| 3 | + |
| 4 | +defaults: |
| 5 | + run: |
| 6 | + shell: bash |
| 7 | + |
| 8 | +on: # Runs on all push events to master branch and any push related to a pull request |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - master |
| 12 | + pull_request: # so that codeclimate gets coverage and reports on the diff |
| 13 | + |
| 14 | +jobs: |
| 15 | + coverage: |
| 16 | + name: ${{ matrix.os }} / ${{ matrix.python-version }} |
| 17 | + runs-on: ${{ matrix.os }} |
| 18 | + strategy: |
| 19 | + matrix: # only lowest supported Python on latest ubuntu |
| 20 | + os: [ubuntu-latest] |
| 21 | + python-version: [3.6] |
| 22 | + |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v2 |
| 25 | + |
| 26 | + - name: Set up Python ${{ matrix.python-version }} |
| 27 | + uses: actions/setup-python@v1 |
| 28 | + with: |
| 29 | + python-version: ${{ matrix.python-version }} |
| 30 | + |
| 31 | + - name: Get full Python version |
| 32 | + id: full-python-version |
| 33 | + run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") |
| 34 | + |
| 35 | + - name: Set up cache |
| 36 | + uses: actions/cache@v2 |
| 37 | + id: cache |
| 38 | + with: |
| 39 | + path: .venv |
| 40 | + key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }} |
| 41 | + |
| 42 | + - name: Ensure cache is healthy |
| 43 | + if: steps.cache.outputs.cache-hit == 'true' |
| 44 | + run: pip --version >/dev/null 2>&1 || rm -rf .venv |
| 45 | + |
| 46 | + - name: Upgrade pip, setuptools and wheel |
| 47 | + run: | |
| 48 | + python -m pip install --upgrade pip |
| 49 | + pip install setuptools wheel |
| 50 | +
|
| 51 | + - name: Install package |
| 52 | + run: pip install '.[test]' |
| 53 | + |
| 54 | + - name: Set up env for CodeClimate (push) |
| 55 | + run: | |
| 56 | + echo "GIT_BRANCH=$GITHUB_REF" >> $GITHUB_ENV |
| 57 | + echo "GIT_COMMIT_SHA=$GITHUB_SHA" >> $GITHUB_ENV |
| 58 | + if: github.event_name == 'push' |
| 59 | + |
| 60 | + - name: Set up env for CodeClimate (pull_request) |
| 61 | + env: |
| 62 | + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 63 | + run: | |
| 64 | + echo "GIT_BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV |
| 65 | + echo "GIT_COMMIT_SHA=$PR_HEAD_SHA" >> $GITHUB_ENV |
| 66 | + if: github.event_name == 'pull_request' |
| 67 | + |
| 68 | + - name: Prepare CodeClimate binary |
| 69 | + env: |
| 70 | + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} |
| 71 | + run: | |
| 72 | + curl -LSs 'https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64' >./cc-test-reporter; |
| 73 | + chmod +x ./cc-test-reporter |
| 74 | + ./cc-test-reporter before-build |
| 75 | +
|
| 76 | + - name: Run all tests |
| 77 | + run: python -m pytest --cov-report xml --cov=tfs |
| 78 | + |
| 79 | + - name: Push Coverage to CodeClimate |
| 80 | + if: ${{ success() }} # only if tests were successful |
| 81 | + env: |
| 82 | + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} |
| 83 | + run: ./cc-test-reporter after-build |
0 commit comments