From ed81ac407f91dc1478871d6430bc9855ec359fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kucmus?= Date: Tue, 21 Nov 2023 16:53:11 +0100 Subject: [PATCH] add test pipeline --- .github/workflows/test.yml | 92 ++++++++++++++++++++++++++++++++++++++ pyproject.toml | 3 +- 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..825c5ba --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,92 @@ +name: test + +on: + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + +env: + STABLE_PYTHON_VERSION: '3.11' + PYTHONUNBUFFERED: "1" + FORCE_COLOR: "1" + +jobs: + run: + name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || 'Linux' }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + python-version: ['3.10', '3.11', '3.12'] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Ensure latest pip and hatch + run: | + python -m pip install --upgrade pip + pip install hatch + + - name: Lint + run: hatch run lint:all + + - name: Coverage + run: hatch run test-cov + + - name: Disambiguate coverage filename + run: mv .coverage ".coverage.${{ matrix.os }}.${{ matrix.python-version }}" + + - name: Upload coverage data + uses: actions/upload-artifact@v3 + with: + name: coverage-data + path: .coverage.* + + coverage: + name: Report coverage + runs-on: ubuntu-latest + needs: + - run + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ env.STABLE_PYTHON_VERSION }} + uses: actions/setup-python@v4 + with: + python-version: ${{ env.STABLE_PYTHON_VERSION }} + + - name: Install Hatch + run: pip install hatch + + - name: Download coverage data + uses: actions/download-artifact@v3 + with: + name: coverage-data + + - name: Combine coverage data + run: hatch run cov-report + + # https://github.com/marketplace/actions/alls-green#why + check: # This job does nothing and is only used for the branch protection + if: always() + + needs: + - coverage + + runs-on: ubuntu-latest + + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} diff --git a/pyproject.toml b/pyproject.toml index dd32576..8b06b23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,9 +56,10 @@ dependencies = [ [tool.hatch.envs.default.scripts] test = "pytest {args:src}" test-cov = "coverage run -m pytest {args:src}" -cov-report = ["- coverage combine", "coverage report"] +cov-report = ["- coverage combine", "coverage report --fail-under=50"] cov-report-html = ["- coverage combine", "coverage html -d src/saleor_sdk/.cov"] cov = ["test-cov", "cov-report-html"] +cov-check = ["test-cov", "cov-report"] [[tool.hatch.envs.all.matrix]] python = ["3.10", "3.11", "3.12"]