-
Notifications
You must be signed in to change notification settings - Fork 153
130 lines (110 loc) · 4.12 KB
/
ci-tests.yml
File metadata and controls
130 lines (110 loc) · 4.12 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
130
name: tests
on:
push:
branches: [ main, dev ]
pull_request:
branches: [ main, dev ]
workflow_dispatch:
jobs:
tests-with-vcr:
strategy:
matrix:
os: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
python-version: ["3.10", "3.11", "3.12", "3.13"]
defaults:
run:
shell: bash
runs-on: ${{ matrix.os }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached pip wheels
id: cached-pip-wheels
uses: actions/cache@v4
with:
path: |
~/.cache/pip
~/Library/Caches/pip
~\AppData\Local\pip\Cache
key: pip-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: poetry install --no-interaction --with dev --no-root
- name: Code formatting checks
run: |
poetry run black --check contextgem dev tests
poetry run isort --check contextgem dev tests
poetry check --lock
- name: Run coverage (with VCR)
run: |
source $VENV
coverage run --source contextgem -m pytest --maxfail=1 --disable-warnings -v
coverage report -m
coverage xml -o coverage_quick.xml
- name: Extract coverage
id: get_coverage
run: |
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; print(round(float(ET.parse('coverage_quick.xml').getroot().attrib['line-rate'])*100))")
echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT
# Determine badge color based on coverage percentage
if [ $COVERAGE -ge 80 ]; then
echo "color=success" >> $GITHUB_OUTPUT
elif [ $COVERAGE -ge 60 ]; then
echo "color=yellow" >> $GITHUB_OUTPUT
else
echo "color=critical" >> $GITHUB_OUTPUT
fi
- name: Upload coverage artifact
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13'
uses: actions/upload-artifact@v4
with:
name: coverage-data
path: |
coverage_quick.xml
retention-days: 1
update-badge:
needs: tests-with-vcr
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Download coverage artifact
uses: actions/download-artifact@v4
with:
name: coverage-data
- name: Extract coverage
id: get_coverage
run: |
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; print(round(float(ET.parse('coverage_quick.xml').getroot().attrib['line-rate'])*100))")
echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT
# Determine badge color based on coverage percentage
if [ $COVERAGE -ge 80 ]; then
echo "color=success" >> $GITHUB_OUTPUT
elif [ $COVERAGE -ge 60 ]; then
echo "color=yellow" >> $GITHUB_OUTPUT
else
echo "color=critical" >> $GITHUB_OUTPUT
fi
- name: Update coverage badge
uses: schneegans/dynamic-badges-action@v1.7.0
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: daaee00e1dfff7a29ca10a922ec3becd
filename: coverage.json
label: coverage
message: ${{ steps.get_coverage.outputs.percentage }}%
color: ${{ steps.get_coverage.outputs.color }}
env:
CONTEXTGEM_OPENAI_API_KEY: ${{ secrets.CONTEXTGEM_OPENAI_API_KEY }}
CONTEXTGEM_AZURE_OPENAI_API_KEY: ${{ secrets.CONTEXTGEM_AZURE_OPENAI_API_KEY }}
CONTEXTGEM_AZURE_OPENAI_API_VERSION: ${{ secrets.CONTEXTGEM_AZURE_OPENAI_API_VERSION }}
CONTEXTGEM_AZURE_OPENAI_API_BASE: ${{ secrets.CONTEXTGEM_AZURE_OPENAI_API_BASE }}