-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (134 loc) · 4.23 KB
/
Copy pathpython-tests.yml
File metadata and controls
159 lines (134 loc) · 4.23 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Run tests
on:
push:
branches:
- "**" # All branches, including those with /
pull_request:
branches: [main]
# Add permissions needed for GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Environment for GitHub Pages
env:
COVERAGE_REPORT_PATH: htmlcov
jobs:
CheckCoverage:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Setup Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install dependencies
run: |
poetry install --with dev
- name: Set up Docker
uses: docker/setup-buildx-action@v3
- name: Start test databases
run: |
# Make the script executable
chmod +x ./tests/start-test-databases.sh
# Run the script
./tests/start-test-databases.sh
- name: Run tests with coverage
run: |
poetry run pytest --cov=heritrace --cov-report=xml --cov-report=term
echo "=== Coverage Report ==="
poetry run coverage report
echo "COVERAGE=$(poetry run coverage report | grep TOTAL | awk '{print $4}')" >> $GITHUB_ENV
- name: Stop test databases
if: always()
run: |
# Make the script executable
chmod +x ./tests/stop-test-databases.sh
# Run the script
./tests/stop-test-databases.sh
- name: Generate HTML coverage report
run: |
poetry run coverage html -d htmlcov
# Upload coverage report as Pages artifact
- name: Upload coverage artifact
if: matrix.python-version == '3.10' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: ${{ env.COVERAGE_REPORT_PATH }}
- name: Generate coverage badge
if: matrix.python-version == '3.10'
run: |
# Extract coverage percentage as a number
COVERAGE_NUM=$(echo ${{ env.COVERAGE }} | sed 's/%//')
# Determine color based on coverage
if (( $(echo "$COVERAGE_NUM >= 90" | bc -l) )); then
COLOR="green"
elif (( $(echo "$COVERAGE_NUM >= 75" | bc -l) )); then
COLOR="yellow"
elif (( $(echo "$COVERAGE_NUM >= 60" | bc -l) )); then
COLOR="orange"
else
COLOR="red"
fi
echo "BADGE_COLOR=$COLOR" >> $GITHUB_ENV
- name: Create badge
if: matrix.python-version == '3.10'
uses: RubbaBoy/BYOB@v1.3.0
with:
name: opencitations-heritrace-coverage-${{ github.ref_name }}
label: "Coverage"
status: "${{ env.COVERAGE }}"
color: ${{ env.BADGE_COLOR }}
github_token: ${{ secrets.GIST_PAT }}
repository: arcangelo7/badges
actor: arcangelo7
# Add a new job to deploy to GitHub Pages
deploy-pages:
needs: CheckCoverage
if: always() && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install and Build Docs
working-directory: docs
run: |
npm install
npm run build
- name: Download coverage artifact
uses: actions/download-artifact@v4
with:
name: coverage-report
path: docs/dist/coverage
continue-on-error: true
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/dist
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4