Skip to content

Commit 138df61

Browse files
committed
chore: test and build with docker
1 parent 6a6be8a commit 138df61

6 files changed

Lines changed: 295 additions & 1 deletion

File tree

.github/workflows/docker-build.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build Docker Image
2+
3+
on:
4+
push:
5+
branches: [ main, master, develop ]
6+
pull_request:
7+
branches: [ main, master, develop ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
packages: write
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
24+
- name: Build Docker image
25+
uses: docker/build-push-action@v5
26+
with:
27+
context: .
28+
file: ./Dockerfile
29+
push: false
30+
tags: python-mapnik:latest
31+
cache-from: type=gha,scope=buildkit-python-mapnik
32+
cache-to: type=gha,mode=max,scope=buildkit-python-mapnik
33+
load: true
34+
35+
- name: Run tests in Docker container
36+
run: |
37+
docker run --rm -v ${{ github.workspace }}/test:/test python-mapnik:latest \
38+
sh -c "uv pip install pytest pytest-cov && uv run pytest /test/python_tests -v"

.github/workflows/release.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
workflow_dispatch:
8+
inputs:
9+
tag:
10+
description: 'Tag to release (e.g., v4.2.0)'
11+
required: true
12+
type: string
13+
14+
jobs:
15+
test:
16+
uses: ./.github/workflows/test.yml
17+
18+
build:
19+
needs: test
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: write
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: '3.12'
32+
33+
- name: Extract version from tag
34+
id: version
35+
run: |
36+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
37+
VERSION=${{ inputs.tag }}
38+
else
39+
VERSION=${GITHUB_REF#refs/tags/}
40+
fi
41+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
42+
echo "version_number=${VERSION#v}" >> $GITHUB_OUTPUT
43+
44+
- name: Add Debian sid repository
45+
run: |
46+
sudo bash -c 'echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list.d/sid.list'
47+
sudo bash -c "echo 'Package: *\nPin: release a=sid\nPin-Priority: 100' > /etc/apt/preferences.d/sid"
48+
49+
- name: Install system dependencies
50+
run: |
51+
sudo apt-get update
52+
sudo apt-get install -y build-essential pkg-config libbz2-dev
53+
sudo apt-get install -y -t sid libmapnik-dev
54+
55+
- name: Install uv
56+
uses: astral-sh/setup-uv@v4
57+
58+
- name: Build wheel and sdist
59+
run: |
60+
uv build --wheel --sdist
61+
62+
- name: Upload build artifacts
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: dist
66+
path: dist/
67+
retention-days: 7
68+
69+
- name: Create GitHub Release
70+
uses: softprops/action-gh-release@v1
71+
if: github.event_name == 'push'
72+
with:
73+
tag_name: ${{ steps.version.outputs.version }}
74+
name: Release ${{ steps.version.outputs.version }}
75+
body: |
76+
## Python Mapnik ${{ steps.version.outputs.version_number }}
77+
78+
### Installation
79+
80+
Download the wheel file below and install:
81+
```bash
82+
pip install mapnik-${{ steps.version.outputs.version_number }}-*.whl
83+
```
84+
85+
Or install directly from GitHub:
86+
```bash
87+
pip install https://github.com/${{ github.repository }}/releases/download/${{ steps.version.outputs.version }}/mapnik-${{ steps.version.outputs.version_number }}-cp312-cp312-linux_x86_64.whl
88+
```
89+
90+
Or install from source:
91+
```bash
92+
pip install git+https://github.com/${{ github.repository }}.git@${{ steps.version.outputs.version }}
93+
```
94+
95+
### Requirements
96+
97+
- Python >= 3.8
98+
- Mapnik >= 4.0.0
99+
100+
### Changes
101+
102+
See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/${{ steps.version.outputs.version }}/CHANGELOG.md) for details.
103+
files: |
104+
dist/*.whl
105+
dist/*.tar.gz
106+
draft: false
107+
prerelease: false
108+
env:
109+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110+
111+
- name: Summary
112+
run: |
113+
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
114+
echo "" >> $GITHUB_STEP_SUMMARY
115+
echo "✅ Released version: **${{ steps.version.outputs.version }}**" >> $GITHUB_STEP_SUMMARY
116+
echo "" >> $GITHUB_STEP_SUMMARY
117+
echo "### Artifacts Built:" >> $GITHUB_STEP_SUMMARY
118+
ls -lh dist/ >> $GITHUB_STEP_SUMMARY
119+
echo "" >> $GITHUB_STEP_SUMMARY
120+
echo "### Distribution:" >> $GITHUB_STEP_SUMMARY
121+
echo "- GitHub Release: ✅" >> $GITHUB_STEP_SUMMARY

.github/workflows/test.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ main, master, develop ]
6+
pull_request:
7+
branches: [ main, master, develop ]
8+
workflow_dispatch:
9+
workflow_call:
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
checks: write
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.12'
26+
27+
- name: Cache APT packages
28+
uses: awalsh128/cache-apt-pkgs-action@latest
29+
with:
30+
packages: build-essential pkg-config libmapnik-dev fonts-noto-cjk libbz2-dev
31+
version: 1.0
32+
33+
- name: Add Debian sid repository
34+
run: |
35+
sudo bash -c 'echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list.d/sid.list'
36+
sudo bash -c "echo 'Package: *\nPin: release a=sid\nPin-Priority: 100' > /etc/apt/preferences.d/sid"
37+
38+
- name: Install system dependencies
39+
run: |
40+
sudo apt-get update
41+
sudo apt-get install -y build-essential pkg-config libbz2-dev
42+
sudo apt-get install -y -t sid libmapnik-dev fonts-noto-cjk
43+
44+
- name: Install uv
45+
uses: astral-sh/setup-uv@v4
46+
with:
47+
enable-cache: true
48+
cache-dependency-glob: "uv.lock"
49+
50+
- name: Install Python dependencies and build package
51+
run: |
52+
uv sync --frozen --verbose || uv sync --verbose
53+
54+
- name: Run tests with coverage
55+
run: |
56+
uv run pytest test/python_tests -v \
57+
--cov=mapnik \
58+
--cov-report=term \
59+
--cov-report=xml:coverage.xml \
60+
--cov-report=html:htmlcov \
61+
--junitxml=junit.xml
62+
63+
- name: Upload coverage reports
64+
uses: actions/upload-artifact@v4
65+
if: always()
66+
with:
67+
name: coverage-reports
68+
path: |
69+
coverage.xml
70+
htmlcov/
71+
junit.xml
72+
retention-days: 30
73+
74+
- name: Publish test results
75+
uses: EnricoMi/publish-unit-test-result-action@v2
76+
if: always()
77+
with:
78+
files: junit.xml
79+
check_name: Test Results
80+
comment_mode: off
81+
82+
- name: Upload coverage to Codecov
83+
uses: codecov/codecov-action@v4
84+
if: always()
85+
with:
86+
files: ./coverage.xml
87+
flags: unittests
88+
name: python-mapnik-coverage
89+
fail_ci_if_error: false

Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM python:3.14-rc-bookworm
2+
3+
# 添加 Debian sid 仓库以获取 Mapnik 4.2
4+
RUN echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list.d/sid.list && \
5+
echo 'Package: *\nPin: release a=sid\nPin-Priority: 100' > /etc/apt/preferences.d/sid
6+
7+
# 安装必要的工具
8+
RUN apt-get update && \
9+
apt-get install -y \
10+
build-essential \
11+
pkg-config
12+
13+
# 安装 Mapnik 4.2 和必要的开发工具
14+
RUN apt-get install -y -t sid \
15+
libmapnik-dev \
16+
fonts-noto-cjk
17+
18+
# 需要额外的依赖写在这里,避免缓存失效。上面的依赖安装起来时间很长
19+
RUN apt-get install -y \
20+
libbz2-dev \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
# 安装 uv
24+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
25+
26+
# 复制依赖文件
27+
COPY pyproject.toml .
28+
COPY uv.lock* ./
29+
30+
# 复制源代码文件(构建本地包所需)
31+
COPY src/ src/
32+
COPY setup.py .
33+
COPY build.py .
34+
COPY packaging/ packaging/
35+
36+
# 安装 Python 依赖(包括构建本地 python-mapnik)
37+
# 使用 --verbose 显示详细的编译日志
38+
RUN uv sync --frozen --no-dev --verbose || uv sync --no-dev --verbose

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "mapnik"
10-
version = "4.1.3.beta"
10+
version = "4.2.0"
1111
description = "Python bindings for Mapnik"
1212
license = "LGPL-2.1-or-later"
1313

uv.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)