ci: isolate MySQL test services
This commit is contained in:
+12
-20
@@ -8,6 +8,17 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: mysql:8.0.35
|
||||||
|
env:
|
||||||
|
MYSQL_ROOT_PASSWORD: ci-root-password
|
||||||
|
MYSQL_DATABASE: hulumath
|
||||||
|
options: >-
|
||||||
|
--health-cmd "mysqladmin ping -h 127.0.0.1 -uroot -pci-root-password --silent"
|
||||||
|
--health-interval 5s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 20
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-python@v5
|
- uses: actions/setup-python@v5
|
||||||
@@ -31,28 +42,9 @@ jobs:
|
|||||||
run: python -c "from config.asgi import application; print(type(application).__name__)"
|
run: python -c "from config.asgi import application; print(type(application).__name__)"
|
||||||
- name: Unit tests
|
- name: Unit tests
|
||||||
run: pytest -q
|
run: pytest -q
|
||||||
- name: Start MySQL 8.0.35
|
|
||||||
run: |
|
|
||||||
docker rm -f hulumath-ci-mysql 2>/dev/null || true
|
|
||||||
docker run -d --name hulumath-ci-mysql \
|
|
||||||
-p 3307:3306 \
|
|
||||||
-e MYSQL_ROOT_PASSWORD=ci-root-password \
|
|
||||||
-e MYSQL_DATABASE=hulumath \
|
|
||||||
mysql:8.0.35 \
|
|
||||||
--character-set-server=utf8mb4 \
|
|
||||||
--collation-server=utf8mb4_0900_ai_ci
|
|
||||||
for i in $(seq 1 60); do
|
|
||||||
if docker exec hulumath-ci-mysql \
|
|
||||||
mysqladmin ping -h 127.0.0.1 -uroot -pci-root-password --silent; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
docker logs hulumath-ci-mysql
|
|
||||||
exit 1
|
|
||||||
- name: MySQL migrations and tests
|
- name: MySQL migrations and tests
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: mysql://root:ci-root-password@127.0.0.1:3307/hulumath
|
DATABASE_URL: mysql://root:ci-root-password@mysql:3306/hulumath
|
||||||
run: |
|
run: |
|
||||||
python backend/manage.py check --database default
|
python backend/manage.py check --database default
|
||||||
python backend/manage.py check_mysql
|
python backend/manage.py check_mysql
|
||||||
|
|||||||
+12
-21
@@ -15,6 +15,17 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
if: ${{ github.event.pull_request.merged == true }}
|
if: ${{ github.event.pull_request.merged == true }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: mysql:8.0.35
|
||||||
|
env:
|
||||||
|
MYSQL_ROOT_PASSWORD: ci-root-password
|
||||||
|
MYSQL_DATABASE: hulumath
|
||||||
|
options: >-
|
||||||
|
--health-cmd "mysqladmin ping -h 127.0.0.1 -uroot -pci-root-password --silent"
|
||||||
|
--health-interval 5s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 20
|
||||||
steps:
|
steps:
|
||||||
- name: 检出 main
|
- name: 检出 main
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -50,29 +61,9 @@ jobs:
|
|||||||
- name: 运行测试
|
- name: 运行测试
|
||||||
run: pytest -q
|
run: pytest -q
|
||||||
|
|
||||||
- name: 启动 MySQL 8.0.35
|
|
||||||
run: |
|
|
||||||
docker rm -f hulumath-deploy-mysql 2>/dev/null || true
|
|
||||||
docker run -d --name hulumath-deploy-mysql \
|
|
||||||
-p 3307:3306 \
|
|
||||||
-e MYSQL_ROOT_PASSWORD=ci-root-password \
|
|
||||||
-e MYSQL_DATABASE=hulumath \
|
|
||||||
mysql:8.0.35 \
|
|
||||||
--character-set-server=utf8mb4 \
|
|
||||||
--collation-server=utf8mb4_0900_ai_ci
|
|
||||||
for i in $(seq 1 60); do
|
|
||||||
if docker exec hulumath-deploy-mysql \
|
|
||||||
mysqladmin ping -h 127.0.0.1 -uroot -pci-root-password --silent; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
docker logs hulumath-deploy-mysql
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
- name: MySQL 迁移与全量测试
|
- name: MySQL 迁移与全量测试
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: mysql://root:ci-root-password@127.0.0.1:3307/hulumath
|
DATABASE_URL: mysql://root:ci-root-password@mysql:3306/hulumath
|
||||||
run: |
|
run: |
|
||||||
python backend/manage.py check --database default
|
python backend/manage.py check --database default
|
||||||
python backend/manage.py check_mysql
|
python backend/manage.py check_mysql
|
||||||
|
|||||||
Reference in New Issue
Block a user