-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (155 loc) · 5.07 KB
/
Copy pathpython-package.yml
File metadata and controls
165 lines (155 loc) · 5.07 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
160
161
162
163
164
165
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python package
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
# -- Windows: unit tests only (no MySQL) ------------------------------------
windows-unit:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.12", "3.13"]
steps:
- 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: |
python -m pip install --upgrade pip
python -m pip install pdm
pdm install
pdm install -G dev
- name: Run unit tests
run: pdm run test-unit
# -- Linux: full test suite + coverage + SonarCloud ------------------------
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13"]
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: dashboard_test
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -prootpass"
--health-interval=10s
--health-timeout=5s
--health-retries=10
env:
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_TEST_NAME: dashboard_test
DB_TEST_USER: dashboard_test
DB_TEST_PASSWORD: testpass
DB_TEST_MIGRATE_USER: dashboard_test_admin
DB_TEST_MIGRATE_PASSWORD: testpass
steps:
- 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: |
python -m pip install --upgrade pip
python -m pip install pdm
pdm install
pdm install -G dev
- name: Wait for MySQL & create test users
run: |
for i in {1..30}; do
if mysqladmin ping -h 127.0.0.1 -uroot -prootpass --silent; then
break
fi
sleep 2
done
mysql -h 127.0.0.1 -uroot -prootpass <<-SQL
CREATE USER IF NOT EXISTS 'dashboard_test'@'%' IDENTIFIED BY 'testpass';
CREATE USER IF NOT EXISTS 'dashboard_test_admin'@'%' IDENTIFIED BY 'testpass';
GRANT ALL ON dashboard_test.* TO 'dashboard_test'@'%';
GRANT ALL ON dashboard_test.* TO 'dashboard_test_admin'@'%';
GRANT CREATE ON *.* TO 'dashboard_test_admin'@'%';
FLUSH PRIVILEGES;
SQL
- name: Build with pdm
run: |
pdm build
- name: Test with pytest
run: |
pdm run test-ci
# JS toolchain (#251): Vitest produces coverage/lcov.info that Sonar
# consumes alongside the Python coverage.xml. Only run on the 3.13
# job so we don't reinstall Node + npm deps three times.
- name: Set up Node.js
if: matrix.python-version == '3.13'
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install JS dependencies
if: matrix.python-version == '3.13'
run: npm ci
- name: Run JS tests with coverage
if: matrix.python-version == '3.13'
run: pdm run js-test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage.xml for SonarCloud job
if: matrix.python-version == '3.13'
uses: actions/upload-artifact@v4
with:
name: coverage-xml
path: coverage.xml
if-no-files-found: error
retention-days: 1
- name: Upload JS lcov.info for SonarCloud job
if: matrix.python-version == '3.13'
uses: actions/upload-artifact@v4
with:
name: coverage-lcov
path: coverage/lcov.info
if-no-files-found: error
retention-days: 1
sonarcloud:
name: SonarCloud
needs: build
runs-on: ubuntu-latest
# Fork PRs cannot read SONAR_TOKEN; skip the scan there to avoid a hard fail.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
steps:
- uses: actions/checkout@v4
with:
# SonarCloud uses git blame to attribute issues to authors / new code.
fetch-depth: 0
- name: Download coverage.xml
uses: actions/download-artifact@v4
with:
name: coverage-xml
- name: Download JS lcov.info
uses: actions/download-artifact@v4
with:
name: coverage-lcov
# Sonar reads it from ``coverage/lcov.info`` per
# sonar-project.properties.
path: coverage
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@v6
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: https://sonarcloud.io