-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (80 loc) · 2.68 KB
/
python.yml
File metadata and controls
96 lines (80 loc) · 2.68 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
name: CI Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
POETRY_VERSION: '1.8.2'
PYTHON_VERSION: '3.10'
permissions:
contents: read
checks: write
pull-requests: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python - --version ${{ env.POETRY_VERSION }}
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Configure Poetry
run: poetry config virtualenvs.in-project true
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
.venv
~/.cache/pypoetry
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-
- name: Install dependencies
run: poetry install --no-interaction --no-ansi
- name: Create reports directory
run: mkdir -p reports
- name: Run tests with coverage
run: |
poetry run pytest --junitxml=reports/junit.xml --cov=./ --cov-report=xml:reports/coverage.xml --cov-report=html:reports/coverage-html
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: reports/
retention-days: 30
- name: Publish Test Results
uses: dorny/test-reporter@v1
if: always()
with:
name: Pytest Tests
path: reports/junit.xml
reporter: java-junit
- name: Extract coverage percentage
id: coverage
run: |
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('reports/coverage.xml'); root = tree.getroot(); print(round(float(root.attrib['line-rate']) * 100, 2))")
echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
echo "Coverage: $COVERAGE%"
- name: Update Coverage Badge
uses: schneegans/dynamic-badges-action@v1.7.0
with:
auth: ${{ secrets.GIST_TOKEN }}
gistID: 080dc9fbb8e45d7cfa7d596572e9bf62
filename: coverage.json
label: Coverage
message: ${{ steps.coverage.outputs.coverage }}%
color: ${{ fromJSON(steps.coverage.outputs.coverage) >= 80 && 'green' || fromJSON(steps.coverage.outputs.coverage) >= 60 && 'yellow' || 'red' }}
maxColorRange: 100
minColorRange: 0