-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (130 loc) · 4.39 KB
/
backend_test.yml
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
name: Backend Test
on:
push:
paths:
- "backend/src/**"
pull_request:
paths:
- "backend/src/**"
workflow_dispatch:
env:
KWAI_DB_NAME: ${{ secrets.KWAI_DB_NAME }}
KWAI_DB_USER_NAME: ${{ secrets.KWAI_DB_USER_NAME }}
KWAI_DB_PASSWORD: ${{ secrets.KWAI_DB_PASSWORD }}
MYSQL_ROOT_HOST: "%"
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
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 Poetry
run: pip install poetry
- name: Install dependencies
working-directory: backend
run: poetry install --with dev,docs
- name: Start MySQL
run: |
sudo systemctl enable mysql.service
sudo systemctl start mysql.service
- name: Create database
run: mysql -u${{ secrets.KWAI_DB_USER_NAME }} -h127.0.0.1 -p${{ secrets.KWAI_DB_PASSWORD }} -e 'CREATE DATABASE IF NOT EXISTS ${{ secrets.KWAI_DB_NAME }};'
- name: Setup Redis
run: sudo apt-get install -y redis-tools redis-server
- name: Verify that redis is up
run: redis-cli ping
- name: Create Kwai Settings
env:
KWAI_JWT_SECRET: ${{ secrets.KWAI_JWT_SECRET }}
KWAI_EMAIL_HOST: ${{ secrets.KWAI_EMAIL_HOST }}
KWAI_EMAIL_PORT: ${{ secrets.KWAI_EMAIL_PORT }}
KWAI_EMAIL_USER: ${{ secrets.KWAI_EMAIL_USER }}
KWAI_EMAIL_PASSWORD: ${{ secrets.KWAI_EMAIL_PASSWORD }}
run: |
cat <<EOF > .kwai.toml
[frontend]
test = true
path = ""
root_app = "portal"
[frontend.apps.portal]
base="/apps/portal"
base_dev="http://localhost:3000"
entries="/src/index.ts"
[frontend.apps.author]
base="/apps/author"
base_dev="http://localhost:3001"
entries="/src/index.ts"
[frontend.apps.auth]
base="/apps/auth"
base_dev="http://localhost:3002"
entries="/src/index.ts"
[frontend.apps.coach]
base="/apps/coach"
base_dev="http://localhost:3003"
entries="/src/index.ts"
[frontend.apps.club]
base="/apps/club"
base_dev="http://localhost:3004"
entries="/src/index.ts"
[files]
path = "/var/tmp/kwai"
[security]
jwt_secret="$KWAI_JWT_SECRET"
jwt_refresh_secret="$KWAI_JWT_SECRET"
[template]
path="${{ github.workspace }}/backend/templates"
[db]
host="localhost"
name="$KWAI_DB_NAME"
user="$KWAI_DB_USER_NAME"
password="$KWAI_DB_PASSWORD"
[website]
url="http://localhost"
email="[email protected]"
name="Kwai Website"
[email]
host="$KWAI_EMAIL_HOST"
user="$KWAI_EMAIL_USER"
password="$KWAI_EMAIL_PASSWORD"
port=$KWAI_EMAIL_PORT
ssl=false
tls=true
from="[email protected]"
[redis]
host="127.0.0.1"
EOF
cat .kwai.toml
- name: Download dbmate
run: |
curl -fsSL -o ./dbmate https://github.com/amacneil/dbmate/releases/latest/download/dbmate-linux-amd64
sudo chmod +x ./dbmate
- name: Migrate database
env:
DATABASE_URL: mysql://${{secrets.KWAI_DB_USER_NAME}}:${{secrets.KWAI_DB_PASSWORD}}@localhost/${{secrets.KWAI_DB_NAME}}
DBMATE_MIGRATIONS_DIR: "./backend/migrations"
DBMATE_NO_DUMP_SCHEMA: "true"
DBMATE_WAIT: "true"
DBMATE_WAIT_TIMEOUT: "30s"
run: ./dbmate up
- name: Test with pytest
working-directory: backend
env:
KWAI_SETTINGS_FILE: ${{github.workspace}}/.kwai.toml
run: poetry run pytest --cov=kwai --cov-report html
- name: Generate coverage badge
working-directory: backend
run: poetry run coverage-badge -o ./htmlcov/coverage.svg
- name: Remove .gitignore from coverage report
run: rm backend/htmlcov/.gitignore
- name: Deploy coverage to github pages
uses: JamesIves/[email protected]
with:
branch: gh-pages
target-folder: coverage
folder: backend/htmlcov