-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (111 loc) · 4.07 KB
/
Copy pathtests.yml
File metadata and controls
129 lines (111 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: tests
concurrency:
group: tests-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read # Checkout repository
actions: read # Run third-party actions
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:
name: Run tests
runs-on: ubuntu-latest
environment: production
permissions:
contents: read # Checkout repository
actions: read # Run third-party actions
issues: write # Create issue on test failure
defaults:
run:
shell: bash
steps:
- name: Check out GitHub repository ${{ github.repository }}
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 1
ref: ${{ github.sha }}
persist-credentials: false
- name: Set up Python on ${{ runner.os }}
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.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@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
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.4.1
- 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@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Tests failed on ${new Date().toDateString()}`,
body: `See the full logs here: ${runUrl}`,
})
- 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/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
report-type: test_results
files: junit.xml
verbose: true
- name: Upload coverage to Codecov.io
if: ${{ github.ref_name == 'master' }}
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: CaptorAB/py-utils
verbose: true