-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (114 loc) · 4.1 KB
/
ci.yml
File metadata and controls
132 lines (114 loc) · 4.1 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
131
132
name: CI
on:
push:
pull_request:
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
name: Tests with Python ${{ matrix.python-version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Run tests with coverage
run: pytest --cov=didww --cov-report=xml --cov-report=term-missing -v
- name: Upload coverage artifact
if: matrix.python-version == '3.13'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.xml
- name: Publish coverage summary
if: always() && matrix.python-version == '3.13'
run: |
if [ ! -f coverage.xml ]; then
echo "## Test Coverage" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "Coverage report was not generated." >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
LINE_RATE=$(python3 -c "
import xml.etree.ElementTree as ET
tree = ET.parse('coverage.xml')
root = tree.getroot()
print(root.attrib.get('line-rate', '0'))
")
BRANCH_RATE=$(python3 -c "
import xml.etree.ElementTree as ET
tree = ET.parse('coverage.xml')
root = tree.getroot()
print(root.attrib.get('branch-rate', '0'))
")
LINE_PERCENT=$(python3 -c "print(f'{float(\"$LINE_RATE\") * 100:.2f}')")
BRANCH_PERCENT=$(python3 -c "print(f'{float(\"$BRANCH_RATE\") * 100:.2f}')")
{
echo "## Test Coverage"
echo ""
echo "| Metric | Coverage |"
echo "|---|---:|"
echo "| Line | ${LINE_PERCENT}% |"
echo "| Branch | ${BRANCH_PERCENT}% |"
} >> "$GITHUB_STEP_SUMMARY"
- name: Generate badge.json
if: matrix.python-version == '3.13'
run: |
if [ ! -f coverage.xml ]; then
mkdir -p badge
echo '{"schemaVersion":1,"label":"coverage","message":"unknown","color":"lightgrey"}' > badge/badge.json
exit 0
fi
LINE_RATE=$(python3 -c "
import xml.etree.ElementTree as ET
tree = ET.parse('coverage.xml')
root = tree.getroot()
print(root.attrib.get('line-rate', '0'))
")
PERCENT=$(python3 -c "print(f'{float(\"$LINE_RATE\") * 100:.1f}')")
PERCENT_CMP=$(python3 -c "print(float(\"$LINE_RATE\") * 100)")
if python3 -c "exit(0 if $PERCENT_CMP >= 90 else 1)"; then COLOR="brightgreen"
elif python3 -c "exit(0 if $PERCENT_CMP >= 75 else 1)"; then COLOR="green"
elif python3 -c "exit(0 if $PERCENT_CMP >= 60 else 1)"; then COLOR="yellow"
else COLOR="red"; fi
mkdir -p badge
echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${PERCENT}%\",\"color\":\"${COLOR}\"}" > badge/badge.json
- name: Upload badge artifact
if: matrix.python-version == '3.13'
uses: actions/upload-artifact@v4
with:
name: coverage-badge
path: badge
deploy-coverage:
needs: test
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Download coverage badge
uses: actions/download-artifact@v4
with:
name: coverage-badge
path: coverage
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: coverage
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4