ci: avoid GitHub action downloads #2
+29
-17
@@ -20,35 +20,47 @@ jobs:
|
|||||||
--health-timeout 5s
|
--health-timeout 5s
|
||||||
--health-retries 20
|
--health-retries 20
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Checkout repository
|
||||||
- uses: actions/setup-python@v5
|
env:
|
||||||
with:
|
REPOSITORY_URL: http://117.72.28.96:8765/Jacky/Hulumath-Web.git
|
||||||
python-version: "3.11"
|
REVISION: ${{ gitea.sha }}
|
||||||
cache: pip
|
run: |
|
||||||
|
git clone "$REPOSITORY_URL" .
|
||||||
|
git checkout --detach "$REVISION"
|
||||||
|
- name: Show Python version
|
||||||
|
run: python3 --version
|
||||||
- name: Install MySQL build dependencies
|
- name: Install MySQL build dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
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-dev \
|
||||||
|
python3-venv
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pip install -r requirements-dev.txt
|
run: |
|
||||||
|
python3 -m venv .venv-ci
|
||||||
|
.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
|
- name: Check migrations
|
||||||
working-directory: backend
|
working-directory: backend
|
||||||
run: python manage.py makemigrations --check --dry-run
|
run: ../.venv-ci/bin/python manage.py makemigrations --check --dry-run
|
||||||
- name: Django checks
|
- name: Django checks
|
||||||
working-directory: backend
|
working-directory: backend
|
||||||
run: python manage.py check
|
run: ../.venv-ci/bin/python manage.py check
|
||||||
- name: ASGI import check
|
- name: ASGI import check
|
||||||
working-directory: backend
|
working-directory: backend
|
||||||
run: python -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
|
- name: Unit tests
|
||||||
run: pytest -q
|
run: .venv-ci/bin/python -m pytest -q
|
||||||
- name: MySQL migrations and tests
|
- name: MySQL migrations and tests
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: mysql://root:ci-root-password@mysql:3306/hulumath
|
DATABASE_URL: mysql://root:ci-root-password@mysql:3306/hulumath
|
||||||
run: |
|
run: |
|
||||||
python backend/manage.py check --database default
|
.venv-ci/bin/python backend/manage.py check --database default
|
||||||
python backend/manage.py check_mysql
|
.venv-ci/bin/python backend/manage.py check_mysql
|
||||||
python backend/manage.py migrate --noinput
|
.venv-ci/bin/python backend/manage.py migrate --noinput
|
||||||
pytest -q
|
.venv-ci/bin/python -m pytest -q
|
||||||
- name: Build image
|
|
||||||
run: docker build -t hulumath:${{ gitea.sha }} .
|
|
||||||
|
|||||||
+25
-18
@@ -28,47 +28,54 @@ jobs:
|
|||||||
--health-retries 20
|
--health-retries 20
|
||||||
steps:
|
steps:
|
||||||
- name: 检出 main
|
- name: 检出 main
|
||||||
uses: actions/checkout@v4
|
env:
|
||||||
with:
|
REPOSITORY_URL: http://117.72.28.96:8765/Jacky/Hulumath-Web.git
|
||||||
ref: main
|
run: git clone --branch main --single-branch "$REPOSITORY_URL" .
|
||||||
|
|
||||||
- name: 配置 Python
|
- name: 显示 Python 版本
|
||||||
uses: actions/setup-python@v5
|
run: python3 --version
|
||||||
with:
|
|
||||||
python-version: "3.11"
|
|
||||||
cache: pip
|
|
||||||
|
|
||||||
- name: 安装 MySQL 编译依赖
|
- name: 安装 MySQL 编译依赖
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
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-dev \
|
||||||
|
python3-venv
|
||||||
|
|
||||||
- name: 安装测试依赖
|
- name: 安装测试依赖
|
||||||
run: pip install -r requirements-dev.txt
|
run: |
|
||||||
|
python3 -m venv .venv-ci
|
||||||
|
.venv-ci/bin/python -m pip install \
|
||||||
|
--index-url https://mirrors.aliyun.com/pypi/simple \
|
||||||
|
--timeout 120 \
|
||||||
|
--retries 5 \
|
||||||
|
-r requirements-dev.txt
|
||||||
|
|
||||||
- name: 检查迁移文件
|
- name: 检查迁移文件
|
||||||
working-directory: backend
|
working-directory: backend
|
||||||
run: python manage.py makemigrations --check --dry-run
|
run: ../.venv-ci/bin/python manage.py makemigrations --check --dry-run
|
||||||
|
|
||||||
- name: Django 系统检查
|
- name: Django 系统检查
|
||||||
working-directory: backend
|
working-directory: backend
|
||||||
run: python manage.py check
|
run: ../.venv-ci/bin/python manage.py check
|
||||||
|
|
||||||
- name: ASGI 启动导入检查
|
- name: ASGI 启动导入检查
|
||||||
working-directory: backend
|
working-directory: backend
|
||||||
run: python -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: 运行测试
|
- name: 运行测试
|
||||||
run: pytest -q
|
run: .venv-ci/bin/python -m pytest -q
|
||||||
|
|
||||||
- name: MySQL 迁移与全量测试
|
- name: MySQL 迁移与全量测试
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: mysql://root:ci-root-password@mysql:3306/hulumath
|
DATABASE_URL: mysql://root:ci-root-password@mysql:3306/hulumath
|
||||||
run: |
|
run: |
|
||||||
python backend/manage.py check --database default
|
.venv-ci/bin/python backend/manage.py check --database default
|
||||||
python backend/manage.py check_mysql
|
.venv-ci/bin/python backend/manage.py check_mysql
|
||||||
python backend/manage.py migrate --noinput
|
.venv-ci/bin/python backend/manage.py migrate --noinput
|
||||||
pytest -q
|
.venv-ci/bin/python -m pytest -q
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
if: ${{ github.event.pull_request.merged == true }}
|
if: ${{ github.event.pull_request.merged == true }}
|
||||||
|
|||||||
+5
-1
@@ -1,8 +1,12 @@
|
|||||||
FROM python:3.11-slim AS runtime
|
FROM python:3.11-slim AS runtime
|
||||||
|
|
||||||
|
ARG PIP_INDEX_URL=https://pypi.org/simple
|
||||||
|
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
PYTHONUNBUFFERED=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
|
WORKDIR /app
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user