Skip to content

Commit 5dbf98d

Browse files
authored
Merge pull request #1 from CourseOrchestra/refactor
refactor, feat, docs, tests, ci, deps Полный рефакторинг
2 parents 7fe2683 + c4c6557 commit 5dbf98d

32 files changed

Lines changed: 2996 additions & 507 deletions

.github/release.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
changelog:
2+
exclude:
3+
labels:
4+
- skip-changelog
5+
- release
6+
categories:
7+
- title: Features
8+
labels:
9+
- feature
10+
- enhancement
11+
- feat
12+
- title: Fixes
13+
labels:
14+
- bug
15+
- bugfix
16+
- fix
17+
- title: Documentation
18+
labels:
19+
- documentation
20+
- docs
21+
- title: Tests
22+
labels:
23+
- test
24+
- tests
25+
- title: CI
26+
labels:
27+
- ci
28+
- github-actions
29+
- title: Refactoring
30+
labels:
31+
- refactor
32+
- title: Dependencies
33+
labels:
34+
- dependencies
35+
- deps
36+
- title: Other Changes
37+
labels:
38+
- "*"

.github/workflows/ci-pr.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "CI PR"
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
jobs:
8+
lint:
9+
name: "Lint"
10+
uses: ./.github/workflows/lint.yml
11+
12+
tests:
13+
name: "Tests"
14+
uses: ./.github/workflows/tests.yml
15+
16+
version-check:
17+
name: "Version Check"
18+
uses: ./.github/workflows/version-check.yml

.github/workflows/ci-push.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: "CI Push"
2+
3+
on:
4+
push:
5+
branches: [master]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
lint:
12+
name: "Lint"
13+
uses: ./.github/workflows/lint.yml
14+
15+
tests:
16+
name: "Tests"
17+
uses: ./.github/workflows/tests.yml
18+
19+
version-check:
20+
name: "Version Check"
21+
uses: ./.github/workflows/version-check.yml
22+
23+
release:
24+
name: "Release"
25+
needs: [tests, version-check]
26+
runs-on: ubuntu-latest
27+
env:
28+
VUH_VERSION: "v2.13.0"
29+
30+
steps:
31+
- name: "Checkout"
32+
uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0
35+
36+
- name: "Download version-update-helper"
37+
shell: bash
38+
run: |
39+
curl -fsSL "https://raw.githubusercontent.com/Greewil/version-update-helper/${VUH_VERSION}/vuh.sh" -o vuh.sh
40+
chmod +x vuh.sh
41+
42+
- name: "Set release tag from vuh version"
43+
id: version
44+
shell: bash
45+
run: |
46+
version="$(./vuh.sh lv -q)"
47+
echo "version=${version}" >> "$GITHUB_OUTPUT"
48+
echo "tag=v${version}" >> "$GITHUB_OUTPUT"
49+
50+
- name: "Check if tag already exists"
51+
id: tag
52+
shell: bash
53+
run: |
54+
if git rev-parse -q --verify "refs/tags/${{ steps.version.outputs.tag }}" >/dev/null; then
55+
echo "exists=true" >> "$GITHUB_OUTPUT"
56+
else
57+
echo "exists=false" >> "$GITHUB_OUTPUT"
58+
fi
59+
60+
- name: "Release decision"
61+
run: |
62+
if [ "${{ steps.tag.outputs.exists }}" = "true" ]; then
63+
echo "Decision: skip (tag already exists: ${{ steps.version.outputs.tag }})"
64+
else
65+
echo "Decision: create release ${{ steps.version.outputs.tag }}"
66+
fi
67+
68+
- name: "Create GitHub release"
69+
if: steps.tag.outputs.exists == 'false'
70+
uses: softprops/action-gh-release@v2
71+
with:
72+
tag_name: ${{ steps.version.outputs.tag }}
73+
target_commitish: ${{ github.sha }}
74+
generate_release_notes: true

.github/workflows/codeql.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
schedule:
9+
- cron: "0 3 * * 1" # At 03:00 on Monday
10+
11+
permissions:
12+
actions: read
13+
contents: read
14+
security-events: write
15+
16+
jobs:
17+
analyze:
18+
name: "Analyze (Python)"
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: "Checkout"
23+
uses: actions/checkout@v4
24+
25+
- name: "Initialize CodeQL"
26+
uses: github/codeql-action/init@v4
27+
with:
28+
languages: python
29+
30+
- name: "Perform CodeQL Analysis"
31+
uses: github/codeql-action/analyze@v4

.github/workflows/lint.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "Lint"
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
pre-commit:
8+
name: "Pre-commit"
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: "Checkout"
13+
uses: actions/checkout@v4
14+
15+
- name: "Set up Python"
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.13"
19+
20+
- name: "Run pre-commit"
21+
uses: pre-commit/action@v3.0.1

.github/workflows/tests.yml

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
name: "Tests"
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
unit:
8+
name: "Unit | Py${{ matrix.python-version }} on ${{ matrix.os }}"
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
include:
14+
- os: ubuntu-22.04
15+
python-version: '3.7'
16+
- os: ubuntu-22.04
17+
python-version: '3.8'
18+
- os: ubuntu-22.04
19+
python-version: '3.9'
20+
- os: ubuntu-22.04
21+
python-version: '3.10'
22+
- os: ubuntu-22.04
23+
python-version: '3.11'
24+
- os: ubuntu-22.04
25+
python-version: '3.12'
26+
- os: ubuntu-22.04
27+
python-version: '3.13'
28+
- os: ubuntu-22.04
29+
python-version: '3.14'
30+
- os: macos-latest
31+
python-version: '3.13'
32+
- os: windows-latest
33+
python-version: '3.13'
34+
35+
steps:
36+
- name: "Checkout"
37+
uses: actions/checkout@v4
38+
39+
- name: "Set up Python"
40+
uses: actions/setup-python@v5
41+
with:
42+
python-version: ${{ matrix.python-version }}
43+
cache: pip
44+
cache-dependency-path: |
45+
pyproject.toml
46+
uv.lock
47+
48+
- name: "Install unit test dependencies"
49+
run: python -m pip install --upgrade pip pytest pytest-cov httpx requests pyyaml
50+
51+
- name: "Run unit tests with coverage"
52+
env:
53+
COVERAGE_FILE: coverage-unit.dat
54+
run: >
55+
pytest -q tests/test_mellophone.py tests/test_structures.py
56+
--cov=src/mellophone
57+
--cov-report=
58+
59+
- name: "Upload unit coverage data"
60+
if: matrix.os == 'ubuntu-22.04' && matrix.python-version == '3.13'
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: coverage-unit-data
64+
path: coverage-unit.dat
65+
66+
integration:
67+
name: "Integration | Py3.13 on ubuntu-22.04"
68+
runs-on: ubuntu-22.04
69+
70+
steps:
71+
- name: "Checkout"
72+
uses: actions/checkout@v4
73+
74+
- name: "Set up Python"
75+
uses: actions/setup-python@v5
76+
with:
77+
python-version: '3.13'
78+
cache: pip
79+
cache-dependency-path: |
80+
pyproject.toml
81+
uv.lock
82+
83+
- name: "Install integration test dependencies"
84+
run: python -m pip install --upgrade pip pytest pytest-cov httpx requests pyyaml
85+
86+
- name: "Cache Docker images"
87+
id: docker-cache
88+
uses: actions/cache@v4
89+
with:
90+
path: /tmp/docker-image-cache
91+
key: docker-images-${{ runner.os }}-${{ hashFiles('docker-compose.yml') }}
92+
93+
- name: "Load cached Docker images"
94+
if: steps.docker-cache.outputs.cache-hit == 'true'
95+
shell: bash
96+
run: |
97+
[ -f /tmp/docker-image-cache/mellophone.tar ] && docker load -i /tmp/docker-image-cache/mellophone.tar || true
98+
[ -f /tmp/docker-image-cache/postgres.tar ] && docker load -i /tmp/docker-image-cache/postgres.tar || true
99+
100+
- name: "Pull Docker images"
101+
if: steps.docker-cache.outputs.cache-hit != 'true'
102+
shell: bash
103+
run: |
104+
docker pull curs/mellophone2:1.6.1
105+
docker pull postgres:16.3-alpine
106+
107+
- name: "Save Docker images to cache"
108+
if: steps.docker-cache.outputs.cache-hit != 'true'
109+
shell: bash
110+
run: |
111+
mkdir -p /tmp/docker-image-cache
112+
docker save curs/mellophone2:1.6.1 -o /tmp/docker-image-cache/mellophone.tar
113+
docker save postgres:16.3-alpine -o /tmp/docker-image-cache/postgres.tar
114+
115+
- name: "Start DB and Mellophone"
116+
run: docker compose up -d db mellophone
117+
118+
- name: "Wait for Mellophone"
119+
shell: bash
120+
run: |
121+
for i in {1..20}; do
122+
if curl -fsS "http://localhost:8082/mellophone/authentication.gif?sesid=ci-smoke" >/dev/null; then
123+
echo "Mellophone is reachable"
124+
exit 0
125+
fi
126+
sleep 2
127+
done
128+
docker compose logs
129+
exit 1
130+
131+
- name: "Run integration tests with coverage"
132+
env:
133+
COVERAGE_FILE: coverage-integration.dat
134+
run: >
135+
pytest -q tests/test_integration_mellophone.py
136+
--cov=src/mellophone
137+
--cov-report=
138+
139+
- name: "Upload integration coverage data"
140+
uses: actions/upload-artifact@v4
141+
with:
142+
name: coverage-integration-data
143+
path: coverage-integration.dat
144+
145+
- name: "Stop services"
146+
if: always()
147+
run: docker compose down -v
148+
149+
coverage-report:
150+
name: "Coverage Report"
151+
needs: [unit, integration]
152+
runs-on: ubuntu-22.04
153+
154+
steps:
155+
- name: "Checkout"
156+
uses: actions/checkout@v4
157+
158+
- name: "Set up Python"
159+
uses: actions/setup-python@v5
160+
with:
161+
python-version: '3.13'
162+
163+
- name: "Download unit coverage data"
164+
uses: actions/download-artifact@v4
165+
with:
166+
name: coverage-unit-data
167+
path: coverage_data/unit
168+
169+
- name: "Download integration coverage data"
170+
uses: actions/download-artifact@v4
171+
with:
172+
name: coverage-integration-data
173+
path: coverage_data/integration
174+
175+
- name: "Install coverage tools"
176+
run: python -m pip install --upgrade pip coverage
177+
178+
- name: "Combine and build coverage reports"
179+
run: |
180+
python -m coverage combine coverage_data/unit/coverage-unit.dat coverage_data/integration/coverage-integration.dat
181+
python -m coverage report -m
182+
python -m coverage xml -o coverage.xml
183+
python -m coverage json -o coverage.json
184+
185+
- name: "Add coverage to job summary"
186+
uses: actions/github-script@v7
187+
with:
188+
script: |
189+
const fs = require("fs");
190+
const report = JSON.parse(fs.readFileSync("coverage.json", "utf8"));
191+
const total = report.totals.percent_covered_display;
192+
core.summary
193+
.addHeading("Coverage (unit + integration)", 2)
194+
.addRaw(`- Total: ${total}%`)
195+
.write();
196+
197+
- name: "Upload coverage artifacts"
198+
uses: actions/upload-artifact@v4
199+
with:
200+
name: coverage-report
201+
path: |
202+
coverage.xml
203+
coverage.json

0 commit comments

Comments
 (0)