Skip to content

Commit

Permalink
Add pytest-xdist as test dependency & improve GH Actions
Browse files Browse the repository at this point in the history
- Upload coverage to Codecov in separate job
- Add build test
- General TLC
  • Loading branch information
MetRonnie committed Oct 19, 2023
1 parent d4fdc6e commit 4b57590
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 18 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build

# build the project whenever the configuration is changed

on:
workflow_dispatch:
pull_request:
paths:
- 'README.md' # check markdown is valid
- 'MANIFEST.in' # check packaging
- 'pyproject.toml' # check build config

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
matrix:
os: ['ubuntu-latest']
python: ['3.7', '3.8', '3.9', '3.10', '3.11']
include:
- os: 'macos-latest'
python: '3.7'
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

- name: Build
uses: cylc/release-actions/build-python-package@v1
with:
check-dependencies: false

- name: Inspect
run: |
unzip -l dist/*.whl | tee files
grep 'metomi_isodatetime.*.dist-info/LICENSE' files
# grep 'metomi/isodatetime/py.typed' files # (not yet added)
67 changes: 49 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ on:
pull_request:
push:
branches: [master]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
FORCE_COLOR: 2

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 45
timeout-minutes: 40
strategy:
matrix:
os: [ubuntu-latest]
Expand All @@ -27,8 +35,10 @@ jobs:
- os: macos-latest
python-version: '3.11'
coverage: false
name: ${{ matrix.os }} py-${{ matrix.python-version }} ${{ matrix.tz }} ${{ matrix.coverage && '(coverage)' || '' }}
env:
PYTEST_ADDOPTS: -n 5 -m 'slow or not slow'
steps:

- name: Checkout repo
uses: actions/checkout@v4

Expand All @@ -38,27 +48,48 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install
run: |
pip install --upgrade pip setuptools
pip install -e .[all]
pip install pytest-xdist
run: pip install -e .[all]

- name: Style test
run: flake8 metomi/isodatetime
- name: Style
run: flake8

- name: Run tests
env:
TZ: ${{ matrix.tz }}
run: |
PYTEST_ARGS=(-n 2 -m 'slow or not slow')
if ${{ matrix.coverage }}; then
PYTEST_ARGS+=('--cov=metomi/isodatetime')
fi
pytest "${PYTEST_ARGS[@]}"
PYTEST_ADDOPTS: ${{ matrix.coverage && format('{0} --cov=metomi/isodatetime', env.PYTEST_ADDOPTS) || env.PYTEST_ADDOPTS }}
run: pytest

- name: Upload coverage report
- name: Coverage report
if: matrix.coverage
run: |
coverage xml --ignore-errors
bash <(curl -s https://codecov.io/bash)
coverage xml
coverage report
- name: Upload coverage artifact
if: matrix.coverage
uses: actions/upload-artifact@v3
with:
name: coverage_${{ matrix.os }}_py-${{ matrix.python-version }}
path: coverage.xml
retention-days: 4

codecov-upload:
needs: test
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download coverage artifacts
uses: actions/download-artifact@v3

- name: Codecov upload
uses: codecov/codecov-action@v3
with:
name: ${{ github.workflow }}
fail_ci_if_error: true
verbose: true
# Token not required for public repos, but avoids upload failure due
# to rate-limiting (but not for PRs opened from forks)
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ test = [
"pytest>=6",
"pytest-env",
"pytest-cov",
"pytest-xdist",
"flake8",
]
all = [
Expand Down

0 comments on commit 4b57590

Please sign in to comment.