-
Notifications
You must be signed in to change notification settings - Fork 31
102 lines (87 loc) · 3.75 KB
/
Copy pathtests.yml
File metadata and controls
102 lines (87 loc) · 3.75 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
name: Tests and Coverage
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
test-and-coverage:
runs-on: ubuntu-latest
if: github.repository == 'basher83/Zammad-MCP'
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
version: "0.11.28"
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
uv sync --dev --frozen --python "${{ matrix.python-version }}"
- name: Run tests with coverage
run: |
# Run pytest with coverage in XML format for Codacy
uv run pytest tests/ \
--cov=mcp_zammad \
--cov-report=xml:coverage.xml \
--cov-report=term-missing \
--cov-report=html:htmlcov
- name: Check Codacy token availability
id: codacy_token
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
run: |
if [ -n "$CODACY_PROJECT_TOKEN" ]; then
echo "available=true" >> "$GITHUB_OUTPUT"
else
echo "available=false" >> "$GITHUB_OUTPUT"
fi
- name: Upload coverage to Codacy
# Coverage upload is reporting, not validation. Dependabot and fork PRs
# may not have repository secrets, so skip cleanly when the token is not
# present and keep the required test job focused on tests/coverage.
if: >-
github.event_name != 'workflow_dispatch' &&
matrix.python-version == '3.13' &&
steps.codacy_token.outputs.available == 'true'
uses: codacy/codacy-coverage-reporter-action@89d6c85cfafaec52c72b6c5e8b2878d33104c699 # v1.3.0
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage.xml
language: python
- name: Upload coverage reports as artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
if: always()
with:
name: coverage-reports-python-${{ matrix.python-version }}
path: |
coverage.xml
htmlcov/
- name: Generate Coverage Summary
if: always()
run: |
echo "## 📊 Test Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -f coverage.xml ]; then
# Parse coverage.xml to extract percentage
COVERAGE=$(uv run python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); coverage = float(root.get('line-rate', 0)) * 100; print(f'{coverage:.1f}')" | tr -d '\n')
echo "### Overall Coverage: ${COVERAGE}%" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Coverage badge
COVERAGE=$COVERAGE uv run python -c "import os; cov = float(os.environ['COVERAGE']); print('✅ **Status**: Meets coverage target (86%)' if cov >= 86 else '❌ **Status**: Below coverage target (86%)')" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "📈 Coverage details available in [Codacy](https://app.codacy.com/gh/${{ github.repository }})" >> $GITHUB_STEP_SUMMARY
else
echo "❌ Coverage report not generated" >> $GITHUB_STEP_SUMMARY
fi