-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (104 loc) · 3.58 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
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.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
run: pip install poetry
- name: Install dependencies
working-directory: backend/src
run: poetry install
- 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
[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/src
env:
KWAI_SETTINGS_FILE: ${{github.workspace}}/.kwai.toml
run: poetry run pytest --cov=kwai --cov-report html
- name: Generate coverage badge
working-directory: backend/src
run: poetry run coverage-badge -o ./htmlcov/coverage.svg
- name: Remove .gitignore from coverage report
run: rm backend/src/htmlcov/.gitignore
- name: Deploy coverage to github pages
uses: JamesIves/[email protected]
with:
branch: gh-pages
target-folder: coverage
folder: backend/src/htmlcov