ci: remove duplicate release dependency installs
This commit is contained in:
+11
-62
@@ -15,75 +15,24 @@ jobs:
|
|||||||
release-check:
|
release-check:
|
||||||
if: ${{ github.event.pull_request.merged == true }}
|
if: ${{ github.event.pull_request.merged == true }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 15
|
timeout-minutes: 5
|
||||||
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
|
||||||
env:
|
env:
|
||||||
REPOSITORY_URL: http://117.72.28.96:8765/Jacky/Hulumath-Web.git
|
REPOSITORY_URL: http://117.72.28.96:8765/Jacky/Hulumath-Web.git
|
||||||
run: git clone --branch main --single-branch "$REPOSITORY_URL" .
|
run: git clone --branch main --single-branch "$REPOSITORY_URL" .
|
||||||
|
|
||||||
- name: 显示 Python 版本
|
- name: 检查发布文件和脚本语法
|
||||||
run: python3 --version
|
|
||||||
|
|
||||||
- name: 安装 MySQL 编译依赖
|
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
set -eu
|
||||||
sudo apt-get install -y \
|
test -f requirements.txt
|
||||||
default-libmysqlclient-dev \
|
test -f backend/manage.py
|
||||||
pkg-config \
|
test -f deploy/hulumath-web.service
|
||||||
python3-dev \
|
test -f scripts/deploy_production.sh
|
||||||
python3-venv
|
test -f scripts/smoke_production.py
|
||||||
|
bash -n scripts/deploy_production.sh
|
||||||
- name: 安装发布检查依赖
|
python3 -m compileall -q backend scripts
|
||||||
run: |
|
git diff-tree --check -m -r HEAD
|
||||||
python3 -m venv .venv-release
|
|
||||||
.venv-release/bin/python -m pip install \
|
|
||||||
--index-url https://mirrors.aliyun.com/pypi/simple \
|
|
||||||
--timeout 120 \
|
|
||||||
--retries 5 \
|
|
||||||
-r requirements.txt
|
|
||||||
|
|
||||||
- name: 检查迁移文件
|
|
||||||
working-directory: backend
|
|
||||||
run: ../.venv-release/bin/python manage.py makemigrations --check --dry-run
|
|
||||||
|
|
||||||
- name: Django 系统检查
|
|
||||||
working-directory: backend
|
|
||||||
run: ../.venv-release/bin/python manage.py check
|
|
||||||
|
|
||||||
- name: ASGI 启动导入检查
|
|
||||||
working-directory: backend
|
|
||||||
run: ../.venv-release/bin/python -c "from config.asgi import application; print(type(application).__name__)"
|
|
||||||
|
|
||||||
- name: 生产静态资源完整性检查
|
|
||||||
working-directory: backend
|
|
||||||
env:
|
|
||||||
DJANGO_DEBUG: "false"
|
|
||||||
DJANGO_USE_HTTPS: "false"
|
|
||||||
DJANGO_SECRET_KEY: release-static-assets-check
|
|
||||||
DJANGO_ALLOWED_HOSTS: localhost
|
|
||||||
DATABASE_URL: mysql://root:ci-root-password@mysql:3306/hulumath
|
|
||||||
REDIS_URL: redis://127.0.0.1:6379/0
|
|
||||||
run: ../.venv-release/bin/python manage.py collectstatic --noinput --clear
|
|
||||||
|
|
||||||
- name: MySQL 发布迁移检查
|
|
||||||
env:
|
|
||||||
DATABASE_URL: mysql://root:ci-root-password@mysql:3306/hulumath
|
|
||||||
run: |
|
|
||||||
.venv-release/bin/python backend/manage.py check --database default
|
|
||||||
.venv-release/bin/python backend/manage.py check_mysql
|
|
||||||
.venv-release/bin/python backend/manage.py migrate --noinput
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
if: ${{ github.event.pull_request.merged == true }}
|
if: ${{ github.event.pull_request.merged == true }}
|
||||||
|
|||||||
+1
-1
@@ -428,7 +428,7 @@ PR 描述至少包含:
|
|||||||
2. 处理审查意见,不要无解释地关闭讨论。
|
2. 处理审查意见,不要无解释地关闭讨论。
|
||||||
3. 请求 Jacky 审查。
|
3. 请求 Jacky 审查。
|
||||||
4. 只有 Jacky 明确批准后才可合并。
|
4. 只有 Jacky 明确批准后才可合并。
|
||||||
5. 合并后观察 `PR合并自动部署` 的 `release-check` 和 `deploy`。
|
5. 合并后观察 `PR合并自动部署`:`release-check` 做无依赖轻量检查,`deploy` 执行生产发布与冒烟。
|
||||||
6. 部署失败时保留日志,先判断是代码、迁移、网络还是冒烟检查问题。
|
6. 部署失败时保留日志,先判断是代码、迁移、网络还是冒烟检查问题。
|
||||||
|
|
||||||
## 14. 安全与隐私
|
## 14. 安全与隐私
|
||||||
|
|||||||
@@ -493,14 +493,18 @@ Ruff 静态检查
|
|||||||
PR 合并到 `main` 后会执行:
|
PR 合并到 `main` 后会执行:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
MySQL 8.0.35 发布迁移检查
|
最终 main 发布文件与脚本语法检查
|
||||||
→ SSH 生产服务器
|
→ SSH 生产服务器
|
||||||
→ MySQL 备份
|
→ MySQL 备份
|
||||||
|
→ collectstatic
|
||||||
→ migrate
|
→ migrate
|
||||||
→ 重启
|
→ 重启
|
||||||
→ 应用与 Nginx HTTP/WebSocket 冒烟检查
|
→ 应用与 Nginx HTTP/WebSocket 冒烟检查
|
||||||
```
|
```
|
||||||
|
|
||||||
|
合并后的轻量发布检查不再重复创建虚拟环境、启动临时 MySQL 或下载依赖;
|
||||||
|
完整 Django、MySQL 和静态资源检查由合并前必须通过的 `CI / test` 负责。
|
||||||
|
|
||||||
## 16. 备份与恢复
|
## 16. 备份与恢复
|
||||||
|
|
||||||
自动备份目录:
|
自动备份目录:
|
||||||
|
|||||||
+6
-4
@@ -13,9 +13,9 @@ PR 质量门禁由 `.gitea/workflows/ci.yml` 执行:
|
|||||||
|
|
||||||
生产发布由 `.gitea/workflows/deploy.yml` 执行。目标为 `main` 的 PR 被真正合并后:
|
生产发布由 `.gitea/workflows/deploy.yml` 执行。目标为 `main` 的 PR 被真正合并后:
|
||||||
|
|
||||||
1. Runner 检出 `main` 并在临时 MySQL 8.0.35 上执行发布迁移检查。
|
1. Runner 检出最终 `main`,检查必要发布文件、Python 语法和部署脚本语法。
|
||||||
2. 检查通过后 SSH 到生产服务器。
|
2. 轻量检查通过后 SSH 到生产服务器;该阶段不重复安装 Python/MySQL 依赖。
|
||||||
3. 服务器备份 MySQL,安装依赖,执行迁移并收集静态资源。
|
3. 服务器备份 MySQL,增量安装依赖,收集静态资源并执行迁移。
|
||||||
4. systemd 重启 Django ASGI 服务。
|
4. systemd 重启 Django ASGI 服务。
|
||||||
5. 验证应用 HTTP、Redis Channel Layer 和直连 WebSocket。
|
5. 验证应用 HTTP、Redis Channel Layer 和直连 WebSocket。
|
||||||
6. 通过 Nginx 验证健康接口、首页、后台、视频目录和 WebSocket。
|
6. 通过 Nginx 验证健康接口、首页、后台、视频目录和 WebSocket。
|
||||||
@@ -33,7 +33,9 @@ PR 质量门禁由 `.gitea/workflows/ci.yml` 执行:
|
|||||||
- 禁止在检查未完成时合并。
|
- 禁止在检查未完成时合并。
|
||||||
- 管理员也应遵守分支保护。
|
- 管理员也应遵守分支保护。
|
||||||
|
|
||||||
完整测试只在 PR 阶段执行。合并后发布流程不重复运行全量测试,因此分支保护是生产发布的必要条件。
|
完整测试、MySQL 迁移验证和生产静态资源检查只在 PR 阶段执行。合并后的
|
||||||
|
`release-check` 不创建虚拟环境或临时 MySQL,避免在一次变更中重复下载依赖;
|
||||||
|
因此分支保护和 `CI / test` 是生产发布的必要条件。
|
||||||
|
|
||||||
## Gitea Secrets
|
## Gitea Secrets
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user