Skip to content

Commit 43c7918

Browse files
Merge pull request #72 from Chia-Network/clean-gha
Build, test, and upload wheels on Github Actions
2 parents 5d920b9 + 4155a2a commit 43c7918

File tree

4 files changed

+135
-7
lines changed

4 files changed

+135
-7
lines changed

.github/workflows/build-wheels.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: Build wheels
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build_wheels:
7+
name: Build wheel on ${{ matrix.os }}
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
os: [macos-latest, ubuntu-latest, windows-latest]
13+
14+
steps:
15+
- name: Cancel previous runs on the same branch
16+
if: ${{ github.ref != 'refs/heads/master' }}
17+
uses: styfle/[email protected]
18+
with:
19+
access_token: ${{ github.token }}
20+
21+
- name: Checkout code
22+
uses: actions/checkout@v2
23+
with:
24+
submodules: 'recursive'
25+
26+
- uses: actions/setup-python@v2
27+
name: Install Python
28+
with:
29+
python-version: '3.9'
30+
31+
- name: Prepare python
32+
run: |
33+
python -m pip install --upgrade pip
34+
35+
- name: Set up QEMU
36+
if: startsWith(matrix.os, 'ubuntu')
37+
uses: docker/setup-qemu-action@v1
38+
with:
39+
platforms: 'arm64'
40+
41+
- name: Build source distribution with Ubuntu
42+
if: startsWith(matrix.os, 'ubuntu')
43+
run: |
44+
pip install build
45+
python -m build --sdist --outdir dist .
46+
47+
- name: Build ${{ matrix.os }} wheels and test
48+
uses: joerick/[email protected]
49+
with:
50+
output-dir: dist
51+
env:
52+
# build just supported python versions at December 2021
53+
CIBW_BUILD: 'cp36-* cp37-* cp38-* cp39-* cp310-*'
54+
# Skip 32-bit builds
55+
CIBW_SKIP: '*-win32 *_i686'
56+
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2010
57+
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014
58+
CIBW_MUSLLINUX_X86_64_IMAGE: musllinux_1_1
59+
# Only build on x86 and arm64 for linux
60+
CIBW_ARCHS_LINUX: auto aarch64
61+
CIBW_BEFORE_ALL_LINUX: >
62+
python -m pip install --upgrade pip
63+
# CIBW_ARCHS_MACOS: x86_64 arm64 universal2
64+
# Building two wheels for MacOS and skipping Universal
65+
CIBW_ARCHS_MACOS: x86_64 arm64
66+
# Skip testing Apple Silicon until there are GH runners
67+
CIBW_TEST_SKIP: '*_arm64 *_universal2:arm64'
68+
CIBW_BEFORE_ALL_MACOS: >
69+
python -m pip install --upgrade pip
70+
CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=10.14
71+
CIBW_BUILD_VERBOSITY_MACOS: 0
72+
CIBW_BEFORE_ALL_WINDOWS: >
73+
python -m pip install --upgrade pip
74+
CIBW_TEST_COMMAND: >
75+
python -m unittest discover -v -s {package}
76+
77+
- name: Upload artifacts
78+
uses: actions/upload-artifact@v2
79+
with:
80+
name: wheels
81+
path: ./dist
82+
83+
- name: Test for secrets access
84+
id: check_secrets
85+
# If a third party makes a pull request
86+
# this allows automated steps below to be skipped
87+
# and leave a clean PR CI run
88+
shell: bash
89+
run: |
90+
unset HAS_SECRET
91+
if [ -n "$SECRET" ]; then HAS_SECRET='true' ; fi
92+
echo ::set-output name=HAS_SECRET::${HAS_SECRET}
93+
env:
94+
SECRET: "${{ secrets.test_pypi_password }}"
95+
96+
- name: Install twine
97+
run: pip install twine
98+
99+
- name: Publish distribution to PyPI
100+
if: >
101+
startsWith(github.event.ref, 'refs/tags') &&
102+
steps.check_secrets.outputs.HAS_SECRET
103+
env:
104+
# If the PR/Push has secret access
105+
# and PYPI_PASSWORD is in GH Secrets for this repo
106+
# and this is a tag, publish to PyPI
107+
TWINE_USERNAME: __token__
108+
TWINE_NON_INTERACTIVE: 1
109+
TWINE_PASSWORD: ${{ secrets.pypi_password }}
110+
run: twine upload --non-interactive --skip-existing --verbose 'dist/*'
111+
112+
- name: Publish distribution to Test PyPI
113+
if: steps.check_secrets.outputs.HAS_SECRET
114+
env:
115+
# If the PR/Push has secret access
116+
# and TEST_PYPI_PASSWORD is in GH Secrets for this repo
117+
# then publish each build to test PyPI
118+
TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/
119+
TWINE_USERNAME: __token__
120+
TWINE_NON_INTERACTIVE: 1
121+
TWINE_PASSWORD: ${{ secrets.test_pypi_password }}
122+
run: twine upload --non-interactive --skip-existing --verbose 'dist/*'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
build
22
sdist
33
dist
4+
venv
45

56
.idea
67
.settings

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@
6161

6262

6363
COPT = {
64-
'msvc': [ '/Ox', '/DVERSION=\"\\\"%s\\\"\"' % PKG_VERSION_STR, ],
65-
'mingw32': [ '-O2', '-DVERSION="%s"' % PKG_VERSION_STR, ],
66-
'unix': [ '-O2', '-DVERSION="%s"' % PKG_VERSION_STR, ],
67-
'clang': [ '-O2', '-DVERSION="%s"' % PKG_VERSION_STR, ],
68-
'gcc': [ '-O2', '-DVERSION="%s"' % PKG_VERSION_STR, ]
64+
'msvc': [ '/Ox', '/DVERSION=%s' % PKG_VERSION_STR, ],
65+
'mingw32': [ '-O2', '-DVERSION=%s' % PKG_VERSION_STR, ],
66+
'unix': [ '-O2', '-DVERSION=%s' % PKG_VERSION_STR, ],
67+
'clang': [ '-O2', '-DVERSION=%s' % PKG_VERSION_STR, ],
68+
'gcc': [ '-O2', '-DVERSION=%s' % PKG_VERSION_STR, ]
6969
}
7070

7171
if not SUP_EXTERNAL:

src/python-zstd.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232

3333
/* Since 3.8 it is mandatory to use proper type for # formats */
3434
#define PY_SSIZE_T_CLEAN
35+
36+
/* Simplify passing strings to the various compilers*/
37+
#define str(x) #x
38+
#define xstr(x) str(x)
39+
3540
#include <Python.h>
3641
#include "pythoncapi_compat.h" // Py_SET_SIZE() for Python 3.8 and older
3742

@@ -182,9 +187,9 @@ static PyObject *py_zstd_uncompress(PyObject* self, PyObject *args)
182187
static PyObject *py_zstd_module_version(PyObject* self, PyObject *args)
183188
{
184189
#if PY_MAJOR_VERSION >= 3
185-
return PyUnicode_FromFormat("%s", VERSION);
190+
return PyUnicode_FromFormat("%s", xstr(VERSION));
186191
#else
187-
return PyString_FromFormat("%s", VERSION);
192+
return PyString_FromFormat("%s", xstr(VERSION));
188193
#endif
189194
}
190195

0 commit comments

Comments
 (0)