Skip to content

Commit 4b82ec1

Browse files
committed
add Github actions for lint, test, and release
1 parent 4401c19 commit 4b82ec1

File tree

11 files changed

+540
-86
lines changed

11 files changed

+540
-86
lines changed

.github/workflows/release.yml

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
name: release
2+
on:
3+
release:
4+
types: [published]
5+
tags:
6+
- v*
7+
push:
8+
branches:
9+
- master
10+
pull_request:
11+
branches:
12+
- master
13+
14+
env:
15+
LIBZIM_RELEASE: libzim_linux-x86_64-6.1.1
16+
LIBZIM_LIBRARY_PATH: lib/x86_64-linux-gnu/libzim.so.6.1.1
17+
LIBZIM_INCLUDE_PATH: include/zim
18+
CYTHON_VERSION: 0.29.6
19+
20+
jobs:
21+
release:
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
matrix:
25+
os: [ubuntu-latest]
26+
# TODO: expand this to cross-platform builds (see V2 approach below)
27+
# os: [ubuntu-latest, windows-latest, macos-latest]
28+
python-version: [3.6, 3.7, 3.8]
29+
30+
steps:
31+
- uses: actions/checkout@v2
32+
33+
- name: Set up Python ${{ matrix.python-version }}
34+
uses: actions/setup-python@v1
35+
with:
36+
python-version: ${{ matrix.python-version }}
37+
architecture: x64
38+
39+
- name: Cache libzim dylib
40+
uses: actions/cache@master
41+
id: cache-libzim
42+
with:
43+
path: libzim_linux
44+
key: $LIBZIM_RELEASE-libzim-cache
45+
46+
- name: Install libzim dylib & headers in system
47+
if: steps.cache-libzim.outputs.cache-hit != 'true'
48+
run: |
49+
wget -q https://download.openzim.org/release/libzim/$LIBZIM_RELEASE.tar.gz
50+
tar --gunzip --extract --file=$LIBZIM_RELEASE.tar.gz
51+
mv $LIBZIM_RELEASE libzim_linux
52+
53+
- name: Sync libzim dylib & headers in system
54+
run: |
55+
sudo rsync -a $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_LIBRARY_PATH /usr/lib/libzim.so
56+
sudo rsync -a $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_INCLUDE_PATH/ /usr/include/zim/
57+
58+
- name: Copy libzim release for building
59+
run: |
60+
rsync -a $GITHUB_WORKSPACE/libzim_linux/ $GITHUB_WORKSPACE/$LIBZIM_RELEASE/
61+
62+
- name: Build cython, sdist, and bdist_wheels
63+
run: |
64+
pip install --upgrade cython==$CYTHON_VERSION setuptools pip cibuildwheel
65+
python3 setup.py build_ext --inplace
66+
python3 setup.py sdist bdist_wheel
67+
python -m cibuildwheel --output-dir wheelhouse
68+
69+
- uses: actions/upload-artifact@v1
70+
with:
71+
name: wheels
72+
path: ./wheelhouse
73+
74+
- name: Push release to PyPI
75+
uses: pypa/gh-action-pypi-publish@master
76+
with:
77+
user: __token__
78+
password: ${{ secrets.PYPI_API_TOKEN }}
79+
repository_url: https://test.pypi.org/legacy/
80+
81+
### TODO V2: The more modern wheel-based cross-platform binary distribution approach
82+
83+
# manylinux-release-wheel:
84+
# name: Build release wheels for manylinux2010
85+
# runs-on: ubuntu-18.04
86+
# steps:
87+
# - uses: actions/checkout@v2
88+
# - uses: actions/setup-python@v1
89+
# with:
90+
# python-version: 3.6
91+
# - name: Build manylinux2010 wheels
92+
# run: |
93+
# docker run -e manylinux2010 tools/ci_build/builds/release_linux.sh
94+
# python3 -m pip install -U auditwheel
95+
# for f in artifacts/*.whl; do
96+
# auditwheel repair --plat manylinux2010_x86_64 $f
97+
# done
98+
# ls -al wheelhouse/
99+
100+
# - uses: actions/upload-artifact@v1
101+
# with:
102+
# name: ${{ runner.os }}-wheels
103+
# path: wheelhouse
104+
105+
# macos-release-wheel:
106+
# name: Build release wheels for macOS
107+
# runs-on: macos-latest
108+
# strategy:
109+
# matrix:
110+
# python-version: ['3.6', '3.7', '3.8']
111+
# steps:
112+
# - uses: actions/checkout@v2
113+
# - uses: actions/setup-python@v1
114+
# with:
115+
# python-version: ${{ matrix.python-version }}
116+
# - name: Build macOS wheels
117+
# if: github.event_name == 'release'
118+
# run: |
119+
# python3 --version
120+
# python3 -m pip install cython wheel setuptools
121+
# bazel build \
122+
# -c opt \
123+
# --copt -mmacosx-version-min=10.13 \
124+
# --linkopt -mmacosx-version-min=10.13 \
125+
# --noshow_progress \
126+
# --noshow_loading_progress \
127+
# --verbose_failures \
128+
# --test_output=errors \
129+
# build_pip_pkg
130+
# bazel-bin/build_pip_pkg artifacts
131+
# for f in artifacts/*.whl; do
132+
# delocate-wheel -w wheelhouse $f
133+
# done
134+
# - uses: actions/upload-artifact@v1
135+
# with:
136+
# name: ${{ runner.os }}-wheels
137+
# path: wheelhouse
138+
139+
# windows-release-wheel:
140+
# name: Build release wheels for Windows
141+
# runs-on: windows-latest
142+
# strategy:
143+
# matrix:
144+
# python-version: ['3.6', '3.7', '3.8']
145+
# steps:
146+
# - uses: actions/checkout@v2
147+
# - uses: actions/setup-python@v1
148+
# with:
149+
# python-version: ${{ matrix.python-version }}
150+
# - name: Build Windows wheels
151+
# shell: bash
152+
# if: github.event_name == 'release'
153+
# run: |
154+
# python -m pip install cython wheel setuptools
155+
# # TODO build here
156+
# - uses: actions/upload-artifact@v1
157+
# with:
158+
# name: ${{ runner.os }}-wheels
159+
# path: artifacts
160+
161+
# upload-wheels:
162+
# name: Publish wheels to PyPi
163+
# needs: [manylinux-release-wheel, macos-release-wheel, windows-release-wheel]
164+
# runs-on: ubuntu-18.04
165+
# steps:
166+
# - uses: actions/download-artifact@v1
167+
# with:
168+
# name: Linux-wheels
169+
# path: Linux-wheels
170+
# - uses: actions/download-artifact@v1
171+
# with:
172+
# name: macOS-wheels
173+
# path: macOS-wheels
174+
# - uses: actions/download-artifact@v1
175+
# with:
176+
# name: Windows-wheels
177+
# path: Windows-wheels
178+
# - run: |
179+
# set -e -x
180+
# mkdir -p dist
181+
# cp Linux-wheels/*.whl dist/
182+
# cp macOS-wheels/*.whl dist/
183+
# cp Windows-wheels/*.whl dist/
184+
# ls -la dist/
185+
# sha256sum dist/*.whl
186+
187+
# - uses: pypa/gh-action-pypi-publish@master
188+
# if: github.event_name == 'release'
189+
# with:
190+
# user: __token__
191+
# password: ${{ secrets.pypi_token }}

.github/workflows/test.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: test
2+
on: [push, pull_request]
3+
4+
env:
5+
LIBZIM_RELEASE: libzim_linux-x86_64-6.1.1
6+
LIBZIM_LIBRARY_PATH: lib/x86_64-linux-gnu/libzim.so.6.1.1
7+
LIBZIM_INCLUDE_PATH: include/zim
8+
CYTHON_VERSION: 0.29.6
9+
MAX_LINE_LENGTH: 110
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Set up Python ${{ matrix.python }}
18+
uses: actions/setup-python@v1
19+
with:
20+
python-version: 3.6
21+
architecture: x64
22+
23+
- name: Autoformat with black
24+
run: |
25+
pip install black
26+
black . --exclude=setup.py
27+
28+
- name: Lint with flake8
29+
run: |
30+
pip install flake8
31+
# stop the build if there are Python syntax errors or undefined names
32+
flake8 . --count --select=E9,F63,F7,F82 --exclude=setup.py --show-source --statistics
33+
# exit-zero treats all errors as warnings, this can be made stricter later
34+
flake8 . --count --exit-zero --exclude=setup.py --max-line-length=$MAX_LINE_LENGTH --statistics
35+
36+
test:
37+
runs-on: ${{ matrix.os }}
38+
strategy:
39+
matrix:
40+
os: [ubuntu-latest]
41+
# TODO: expand this once macos and windows libzim releases become available
42+
# os: [ubuntu-latest, windows-latest, macos-latest]
43+
# alternatively we can compile libzim in docker and use the container as an action
44+
python: [3.6, 3.7, 3.8]
45+
steps:
46+
- uses: actions/checkout@v2
47+
48+
- name: Set up Python ${{ matrix.python }}
49+
uses: actions/setup-python@v1
50+
with:
51+
python-version: ${{ matrix.python }}
52+
architecture: x64
53+
54+
- name: Cache libzim dylib
55+
uses: actions/cache@master
56+
id: cache-libzim
57+
with:
58+
path: libzim_linux
59+
key: $LIBZIM_RELEASE-libzim-cache
60+
61+
- name: Download libzim dylib & headers in system
62+
if: steps.cache-libzim.outputs.cache-hit != 'true'
63+
run: |
64+
wget -q https://download.openzim.org/release/libzim/$LIBZIM_RELEASE.tar.gz
65+
tar --gunzip --extract --file=$LIBZIM_RELEASE.tar.gz
66+
mv $LIBZIM_RELEASE libzim_linux
67+
68+
- name: Sync libzim dylib & headers in system
69+
run: |
70+
sudo rsync -a $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_LIBRARY_PATH /usr/lib/libzim.so
71+
sudo rsync -a $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_INCLUDE_PATH/ /usr/include/zim/
72+
73+
- name: Build cython, sdist, and bdist_wheel
74+
run: |
75+
pip install --upgrade cython==$CYTHON_VERSION setuptools pip wheel
76+
python3 setup.py build_ext --build-lib=cython_build
77+
python3 setup.py sdist bdist_wheel
78+
79+
- name: Test built package with pytest
80+
run: |
81+
export LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH
82+
sudo ldconfig
83+
pip install pytest
84+
pip install -e .
85+
pytest .

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.DS_Store
2+
.venv
3+
.venv-docker
4+
.mypy_cache
5+
__pycache__
6+
*.pyc
7+
.tox
8+
9+
build/
10+
dist/
11+
libzim.egg-info/
12+
libzim_linux-x86_64-6.1.1/

MANIFEST.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include LICENSE
2+
include README.md
3+
recursive-include libzim_linux-x86_64-6.1.1 *

Pipfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
pytest = "*"
8+
tox = "*"
9+
cython = "==0.29.6"
10+
e1839a8 = {editable = true, path = "."}
11+
12+
[packages]
13+
14+
[requires]
15+
python_version = "3.7"
File renamed without changes.

pyproject.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[build-system]
2+
requires = [ "setuptools >= 35.0.2", "wheel >= 0.29.0", "twine", "cython == 0.29.6" ]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.tox]
6+
legacy_tox_ini = """
7+
[tox]
8+
envlist = py36,py37
9+
10+
[testenv]
11+
platform = linux|darwin
12+
deps =
13+
pytest >= 3.0.0, <4
14+
cython
15+
commands = pytest
16+
"""
17+
18+
[tool.black]
19+
line-length = 110
20+
target-version = ['py36', 'py37', 'py38']

rebuild.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

run_tests.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)