Skip to content

Commit

Permalink
Merge pull request #181 from shunichironomura/switch-from-tox
Browse files Browse the repository at this point in the history
Update test workflow from tox to pytest
  • Loading branch information
shunichironomura authored Feb 5, 2024
2 parents 25df15c + 8ebf57e commit 483d56c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 112 deletions.
82 changes: 22 additions & 60 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,17 @@ jobs:
- name: Run mypy
run: poetry run --no-interaction -- mypy --strict --python-version ${{ matrix.python-version }} .

tox:
pytest:
if: github.event.pull_request.draft == false
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.12", "3.11", "3.10", "3.9", "3.8"]
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
COVERAGE_FILE: .coverage.${{ matrix.os }}-${{ matrix.python-version }}

steps:
- uses: actions/checkout@v4
Expand All @@ -85,69 +89,27 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Test with tox
run: tox
env:
PLATFORM: ${{ matrix.os }}

- name: Upload coverage
uses: actions/upload-artifact@v4
- name: Set up Poetry
uses: abatilo/actions-poetry@v3
with:
name: covdata-${{ matrix.os }}-${{ matrix.python-version }}
path: .coverage.*
poetry-version: ${{ env.POETRY_VERSION }}

combine-coverage-reports:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
permissions:
contents: write
needs: tox
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Download coverage reports from all jobs
uses: actions/download-artifact@v4
- name: Install dependencies
run: poetry install --no-interaction

- name: Flatten directory structure
run: |
shopt -s dotglob
for dir in ./covdata-*; do
if [ -d "$dir" ]; then
mv "$dir"/* ./
rm -rf "$dir"
fi
done
shopt -u dotglob
- name: Run pytest
run: poetry run --no-interaction -- coverage run -m pytest ./tests --import-mode importlib

- name: Combine coverage reports
- name: Generate coverage report
run: |
python -m pip install --upgrade pip
python -m pip install coverage genbadge[coverage]
coverage combine
coverage report -m
coverage xml -o coverage/coverage.xml
coverage html -d coverage/html
genbadge coverage -i coverage/coverage.xml -o coverage/badge.svg
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
poetry run --no-interaction -- coverage report -m
poetry run --no-interaction -- coverage xml -o ./coverage/coverage.xml
- name: Commit and push
if: github.event_name == 'pull_request'
uses: EndBug/add-and-commit@v9
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
default_author: github_actions
message: "Update tox report"
push: "origin HEAD:${{ github.head_ref }} --force"
directory: ./coverage/
file: coverage.xml
env_vars: OS,PYTHON
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
52 changes: 0 additions & 52 deletions tox.ini

This file was deleted.

0 comments on commit 483d56c

Please sign in to comment.