120 lines
3.7 KiB
YAML
120 lines
3.7 KiB
YAML
name: Tests
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: python:3.12-slim
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
shell: sh
|
|
run: |
|
|
set -eu
|
|
python - <<'PY'
|
|
import io
|
|
import os
|
|
import tarfile
|
|
import urllib.request
|
|
|
|
url = f"{os.environ['GITHUB_API_URL']}/repos/{os.environ['GITHUB_REPOSITORY']}/archive/{os.environ['GITHUB_SHA']}.tar.gz"
|
|
request = urllib.request.Request(url, headers={"Authorization": f"token {os.environ['GITHUB_TOKEN']}"})
|
|
with urllib.request.urlopen(request, timeout=120) as response:
|
|
archive = response.read()
|
|
|
|
with tarfile.open(fileobj=io.BytesIO(archive), mode='r:gz') as tar:
|
|
root_prefix = tar.getmembers()[0].name.split('/', 1)[0] + '/'
|
|
for member in tar.getmembers():
|
|
name = member.name
|
|
if name == root_prefix[:-1]:
|
|
continue
|
|
if name.startswith(root_prefix):
|
|
member.name = name[len(root_prefix):]
|
|
if member.name:
|
|
tar.extract(member, '.')
|
|
PY
|
|
|
|
- name: Show Python version
|
|
shell: sh
|
|
run: |
|
|
set -eu
|
|
python --version
|
|
python -m pip --version
|
|
|
|
- name: Install dependencies
|
|
shell: sh
|
|
run: |
|
|
set -eu
|
|
python -m pip install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
|
|
python -m pip install -r requirements.txt -r requirements-dev.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
|
|
|
|
- name: Run tests
|
|
shell: sh
|
|
run: |
|
|
set -eu
|
|
python -m pytest tests/integration/ -v --cov=packages --cov=apps --cov-report=xml --cov-report=term
|
|
|
|
lint:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: python:3.12-slim
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
shell: sh
|
|
run: |
|
|
set -eu
|
|
python - <<'PY'
|
|
import io
|
|
import os
|
|
import tarfile
|
|
import urllib.request
|
|
|
|
url = f"{os.environ['GITHUB_API_URL']}/repos/{os.environ['GITHUB_REPOSITORY']}/archive/{os.environ['GITHUB_SHA']}.tar.gz"
|
|
request = urllib.request.Request(url, headers={"Authorization": f"token {os.environ['GITHUB_TOKEN']}"})
|
|
with urllib.request.urlopen(request, timeout=120) as response:
|
|
archive = response.read()
|
|
|
|
with tarfile.open(fileobj=io.BytesIO(archive), mode='r:gz') as tar:
|
|
root_prefix = tar.getmembers()[0].name.split('/', 1)[0] + '/'
|
|
for member in tar.getmembers():
|
|
name = member.name
|
|
if name == root_prefix[:-1]:
|
|
continue
|
|
if name.startswith(root_prefix):
|
|
member.name = name[len(root_prefix):]
|
|
if member.name:
|
|
tar.extract(member, '.')
|
|
PY
|
|
|
|
- name: Install dependencies
|
|
shell: sh
|
|
run: |
|
|
set -eu
|
|
python -m pip install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
|
|
python -m pip install -r requirements.txt -r requirements-dev.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
|
|
|
|
- name: Run Black (check only)
|
|
shell: sh
|
|
run: |
|
|
set -eu
|
|
python -m black --check packages/ apps/ tests/
|
|
|
|
- name: Run Flake8
|
|
shell: sh
|
|
run: |
|
|
set -eu
|
|
python -m flake8 packages/ apps/ tests/ --max-line-length=120 --extend-ignore=E203,W503
|
|
|
|
- name: Run MyPy
|
|
shell: sh
|
|
run: |
|
|
set -eu
|
|
python -m mypy packages/ apps/ --ignore-missing-imports
|