Skip to content

update

update #75

Workflow file for this run

name: tests
permissions:
contents: read
actions: read
issues: write
on:
workflow_dispatch: {}
push:
branches:
- "*" # matches every branch that doesn't contain a '/'
- "*/*" # matches every branch containing a single '/'
- "**" # matches every branch
jobs:
run_tests:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Check out GitHub repository ${{ github.repository }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 1
ref: ${{ github.sha }}
persist-credentials: false
- name: Set up Python on ${{ runner.os }}
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
id: setup_python
with:
python-version-file: '.python-version'
- name: Get Python version
run: echo "PYTHON_VERSION=$(python --version)" >> $GITHUB_ENV
- name: Manage Poetry cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
id: poetry-cache
with:
path: |
~/.cache/pypoetry/cache
~/.cache/pypoetry/artifacts
key: poetry-cache-${{ runner.os }}-${{ hashFiles('poetry.lock') }}
restore-keys: poetry-cache-${{ runner.os }}-
- name: Create virtual environment on ${{ env.PYTHON_VERSION }}
run: python -m venv venv
- name: Activate virtual environment and install Poetry
run: |
source venv/bin/activate
python --version
pip install --upgrade pip wheel
pip install poetry==2.1.3
- name: Install dependencies with Poetry
run: |
source venv/bin/activate
poetry install --no-root --with dev
- name: Check and fix with Ruff
run: |
source venv/bin/activate
poetry run ruff check . --fix --exit-non-zero-on-fix
- name: Format with Ruff
run: |
source venv/bin/activate
poetry run ruff format
- name: Tests with Pytest
id: pytest
continue-on-error: true
run: |
source venv/bin/activate
PYTHONPATH=${PWD} poetry run pytest -n auto \
--dist loadscope \
--cov=. \
--cov-report=term \
--cov-report=term-missing \
--cov-report=xml \
--junitxml=junit.xml
- name: Create GitHub issue on failure
if: ${{ steps.pytest.outcome == 'failure' }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
await github.rest.issues.create({
owner: 'CaptorAB',
repo: 'py-utils',
title: `Tests failed on ${new Date().toDateString()}`,
body: `See the full logs here: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`,
})
- name: Fail job if tests failed
if: ${{ steps.pytest.outcome == 'failure' }}
run: exit 1
- name: Upload test results to Codecov
if: ${{ github.ref_name == 'master' }}
uses: codecov/test-results-action@47f89e9acb64b76debcd5ea40642d25a4adced9f # v1.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: junit.xml
verbose: true
- name: Upload coverage to Codecov.io
if: ${{ github.ref_name == 'master' }}
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: CaptorAB/py-utils
verbose: true