Skip to content

Commit

Permalink
add test pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
pkucmus committed Nov 21, 2023
1 parent f6e5e03 commit ed81ac4
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
92 changes: 92 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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) }}
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit ed81ac4

Please sign in to comment.