From cee657faac6004f2c2aa5ad6ec1efdc83b0e605a Mon Sep 17 00:00:00 2001 From: Jacky Date: Sat, 8 Aug 2026 22:53:09 +0800 Subject: [PATCH 1/6] ci: avoid GitHub action downloads --- .gitea/workflows/ci.yml | 26 ++++++++++++-------------- .gitea/workflows/deploy.yml | 27 ++++++++++++--------------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index bb66207..6074783 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -20,35 +20,33 @@ jobs: --health-timeout 5s --health-retries 20 steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: "3.11" - cache: pip + - uses: https://gitea.com/actions/checkout@v4 + - name: Show Python version + run: python3 --version - name: Install MySQL build dependencies run: | sudo apt-get update sudo apt-get install -y default-libmysqlclient-dev pkg-config - name: Install dependencies - run: pip install -r requirements-dev.txt + run: python3 -m pip install -r requirements-dev.txt - name: Check migrations working-directory: backend - run: python manage.py makemigrations --check --dry-run + run: python3 manage.py makemigrations --check --dry-run - name: Django checks working-directory: backend - run: python manage.py check + run: python3 manage.py check - name: ASGI import check working-directory: backend - run: python -c "from config.asgi import application; print(type(application).__name__)" + run: python3 -c "from config.asgi import application; print(type(application).__name__)" - name: Unit tests - run: pytest -q + run: python3 -m pytest -q - name: MySQL migrations and tests env: DATABASE_URL: mysql://root:ci-root-password@mysql:3306/hulumath run: | - python backend/manage.py check --database default - python backend/manage.py check_mysql - python backend/manage.py migrate --noinput - pytest -q + python3 backend/manage.py check --database default + python3 backend/manage.py check_mysql + python3 backend/manage.py migrate --noinput + python3 -m pytest -q - name: Build image run: docker build -t hulumath:${{ gitea.sha }} . diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 459626c..dcc57ae 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -28,15 +28,12 @@ jobs: --health-retries 20 steps: - name: 检出 main - uses: actions/checkout@v4 + uses: https://gitea.com/actions/checkout@v4 with: ref: main - - name: 配置 Python - uses: actions/setup-python@v5 - with: - python-version: "3.11" - cache: pip + - name: 显示 Python 版本 + run: python3 --version - name: 安装 MySQL 编译依赖 run: | @@ -44,31 +41,31 @@ jobs: sudo apt-get install -y default-libmysqlclient-dev pkg-config - name: 安装测试依赖 - run: pip install -r requirements-dev.txt + run: python3 -m pip install -r requirements-dev.txt - name: 检查迁移文件 working-directory: backend - run: python manage.py makemigrations --check --dry-run + run: python3 manage.py makemigrations --check --dry-run - name: Django 系统检查 working-directory: backend - run: python manage.py check + run: python3 manage.py check - name: ASGI 启动导入检查 working-directory: backend - run: python -c "from config.asgi import application; print(type(application).__name__)" + run: python3 -c "from config.asgi import application; print(type(application).__name__)" - name: 运行测试 - run: pytest -q + run: python3 -m pytest -q - name: MySQL 迁移与全量测试 env: DATABASE_URL: mysql://root:ci-root-password@mysql:3306/hulumath run: | - python backend/manage.py check --database default - python backend/manage.py check_mysql - python backend/manage.py migrate --noinput - pytest -q + python3 backend/manage.py check --database default + python3 backend/manage.py check_mysql + python3 backend/manage.py migrate --noinput + python3 -m pytest -q deploy: if: ${{ github.event.pull_request.merged == true }} -- 2.54.0 From cfc9d998200dda7d8bb8285feff2ce150839b3f6 Mon Sep 17 00:00:00 2001 From: Jacky Date: Sat, 8 Aug 2026 22:58:31 +0800 Subject: [PATCH 2/6] ci: checkout from local Gitea --- .gitea/workflows/ci.yml | 8 +++++++- .gitea/workflows/deploy.yml | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 6074783..94e5153 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -20,7 +20,13 @@ jobs: --health-timeout 5s --health-retries 20 steps: - - uses: https://gitea.com/actions/checkout@v4 + - name: Checkout repository + env: + REPOSITORY_URL: http://117.72.28.96:8765/Jacky/Hulumath-Web.git + REVISION: ${{ gitea.sha }} + run: | + git clone "$REPOSITORY_URL" . + git checkout --detach "$REVISION" - name: Show Python version run: python3 --version - name: Install MySQL build dependencies diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index dcc57ae..cb47264 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -28,9 +28,9 @@ jobs: --health-retries 20 steps: - name: 检出 main - uses: https://gitea.com/actions/checkout@v4 - with: - ref: main + env: + REPOSITORY_URL: http://117.72.28.96:8765/Jacky/Hulumath-Web.git + run: git clone --branch main --single-branch "$REPOSITORY_URL" . - name: 显示 Python 版本 run: python3 --version -- 2.54.0 From 672c3cf98bd9fe25b799a263a55e8e17ce973f09 Mon Sep 17 00:00:00 2001 From: Jacky Date: Sat, 8 Aug 2026 23:08:47 +0800 Subject: [PATCH 3/6] ci: install dependencies in virtualenv --- .gitea/workflows/ci.yml | 22 ++++++++++++---------- .gitea/workflows/deploy.yml | 22 ++++++++++++---------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 94e5153..44b98e0 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -32,27 +32,29 @@ jobs: - name: Install MySQL build dependencies run: | sudo apt-get update - sudo apt-get install -y default-libmysqlclient-dev pkg-config + sudo apt-get install -y default-libmysqlclient-dev pkg-config python3-venv - name: Install dependencies - run: python3 -m pip install -r requirements-dev.txt + run: | + python3 -m venv .venv-ci + .venv-ci/bin/python -m pip install -r requirements-dev.txt - name: Check migrations working-directory: backend - run: python3 manage.py makemigrations --check --dry-run + run: ../.venv-ci/bin/python manage.py makemigrations --check --dry-run - name: Django checks working-directory: backend - run: python3 manage.py check + run: ../.venv-ci/bin/python manage.py check - name: ASGI import check working-directory: backend - run: python3 -c "from config.asgi import application; print(type(application).__name__)" + run: ../.venv-ci/bin/python -c "from config.asgi import application; print(type(application).__name__)" - name: Unit tests - run: python3 -m pytest -q + run: .venv-ci/bin/python -m pytest -q - name: MySQL migrations and tests env: DATABASE_URL: mysql://root:ci-root-password@mysql:3306/hulumath run: | - python3 backend/manage.py check --database default - python3 backend/manage.py check_mysql - python3 backend/manage.py migrate --noinput - python3 -m pytest -q + .venv-ci/bin/python backend/manage.py check --database default + .venv-ci/bin/python backend/manage.py check_mysql + .venv-ci/bin/python backend/manage.py migrate --noinput + .venv-ci/bin/python -m pytest -q - name: Build image run: docker build -t hulumath:${{ gitea.sha }} . diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index cb47264..196e392 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -38,34 +38,36 @@ jobs: - name: 安装 MySQL 编译依赖 run: | sudo apt-get update - sudo apt-get install -y default-libmysqlclient-dev pkg-config + sudo apt-get install -y default-libmysqlclient-dev pkg-config python3-venv - name: 安装测试依赖 - run: python3 -m pip install -r requirements-dev.txt + run: | + python3 -m venv .venv-ci + .venv-ci/bin/python -m pip install -r requirements-dev.txt - name: 检查迁移文件 working-directory: backend - run: python3 manage.py makemigrations --check --dry-run + run: ../.venv-ci/bin/python manage.py makemigrations --check --dry-run - name: Django 系统检查 working-directory: backend - run: python3 manage.py check + run: ../.venv-ci/bin/python manage.py check - name: ASGI 启动导入检查 working-directory: backend - run: python3 -c "from config.asgi import application; print(type(application).__name__)" + run: ../.venv-ci/bin/python -c "from config.asgi import application; print(type(application).__name__)" - name: 运行测试 - run: python3 -m pytest -q + run: .venv-ci/bin/python -m pytest -q - name: MySQL 迁移与全量测试 env: DATABASE_URL: mysql://root:ci-root-password@mysql:3306/hulumath run: | - python3 backend/manage.py check --database default - python3 backend/manage.py check_mysql - python3 backend/manage.py migrate --noinput - python3 -m pytest -q + .venv-ci/bin/python backend/manage.py check --database default + .venv-ci/bin/python backend/manage.py check_mysql + .venv-ci/bin/python backend/manage.py migrate --noinput + .venv-ci/bin/python -m pytest -q deploy: if: ${{ github.event.pull_request.merged == true }} -- 2.54.0 From 1f800d713f2c49ab239abd5222eea96d6de3818b Mon Sep 17 00:00:00 2001 From: Jacky Date: Sat, 8 Aug 2026 23:23:49 +0800 Subject: [PATCH 4/6] ci: use domestic Python package mirror --- .gitea/workflows/ci.yml | 11 +++++++++-- .gitea/workflows/deploy.yml | 6 +++++- Dockerfile | 6 +++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 44b98e0..22386ee 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -36,7 +36,11 @@ jobs: - name: Install dependencies run: | python3 -m venv .venv-ci - .venv-ci/bin/python -m pip install -r requirements-dev.txt + .venv-ci/bin/python -m pip install \ + --index-url https://mirrors.aliyun.com/pypi/simple \ + --timeout 120 \ + --retries 5 \ + -r requirements-dev.txt - name: Check migrations working-directory: backend run: ../.venv-ci/bin/python manage.py makemigrations --check --dry-run @@ -57,4 +61,7 @@ jobs: .venv-ci/bin/python backend/manage.py migrate --noinput .venv-ci/bin/python -m pytest -q - name: Build image - run: docker build -t hulumath:${{ gitea.sha }} . + run: | + docker build \ + --build-arg PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple \ + -t hulumath:${{ gitea.sha }} . diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 196e392..12e2b03 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -43,7 +43,11 @@ jobs: - name: 安装测试依赖 run: | python3 -m venv .venv-ci - .venv-ci/bin/python -m pip install -r requirements-dev.txt + .venv-ci/bin/python -m pip install \ + --index-url https://mirrors.aliyun.com/pypi/simple \ + --timeout 120 \ + --retries 5 \ + -r requirements-dev.txt - name: 检查迁移文件 working-directory: backend diff --git a/Dockerfile b/Dockerfile index 3ce073e..f2f24dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,12 @@ FROM python:3.11-slim AS runtime +ARG PIP_INDEX_URL=https://pypi.org/simple + ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ - PIP_DISABLE_PIP_VERSION_CHECK=1 + PIP_DISABLE_PIP_VERSION_CHECK=1 \ + PIP_INDEX_URL=$PIP_INDEX_URL \ + PIP_DEFAULT_TIMEOUT=120 WORKDIR /app -- 2.54.0 From 4b59828544c2c04f64f5660cb1790922a1719e7b Mon Sep 17 00:00:00 2001 From: Jacky Date: Sat, 8 Aug 2026 23:26:52 +0800 Subject: [PATCH 5/6] ci: install Python development headers --- .gitea/workflows/ci.yml | 6 +++++- .gitea/workflows/deploy.yml | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 22386ee..35b2754 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -32,7 +32,11 @@ jobs: - name: Install MySQL build dependencies run: | sudo apt-get update - sudo apt-get install -y default-libmysqlclient-dev pkg-config python3-venv + sudo apt-get install -y \ + default-libmysqlclient-dev \ + pkg-config \ + python3-dev \ + python3-venv - name: Install dependencies run: | python3 -m venv .venv-ci diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 12e2b03..a248b57 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -38,7 +38,11 @@ jobs: - name: 安装 MySQL 编译依赖 run: | sudo apt-get update - sudo apt-get install -y default-libmysqlclient-dev pkg-config python3-venv + sudo apt-get install -y \ + default-libmysqlclient-dev \ + pkg-config \ + python3-dev \ + python3-venv - name: 安装测试依赖 run: | -- 2.54.0 From 8e0ab7dae750ba1eaadda161e387033e7f6e31a1 Mon Sep 17 00:00:00 2001 From: Jacky Date: Sat, 8 Aug 2026 23:36:27 +0800 Subject: [PATCH 6/6] ci: skip unused application image build --- .gitea/workflows/ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 35b2754..d4e5b4e 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -64,8 +64,3 @@ jobs: .venv-ci/bin/python backend/manage.py check_mysql .venv-ci/bin/python backend/manage.py migrate --noinput .venv-ci/bin/python -m pytest -q - - name: Build image - run: | - docker build \ - --build-arg PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple \ - -t hulumath:${{ gitea.sha }} . -- 2.54.0