Skip to content

Commit cacb3ba

Browse files
committed
Add release workflow
1 parent dd3c045 commit cacb3ba

File tree

9 files changed

+292
-21
lines changed

9 files changed

+292
-21
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -e -x
4+
5+
PY_MAJOR=${PYTHON_VERSION%%.*}
6+
PY_MINOR=${PYTHON_VERSION#*.}
7+
8+
ML_PYTHON_VERSION="cp${PY_MAJOR}${PY_MINOR}-cp${PY_MAJOR}${PY_MINOR}"
9+
if [ "${PY_MAJOR}" -lt "4" -a "${PY_MINOR}" -lt "8" ]; then
10+
ML_PYTHON_VERSION+="m"
11+
fi
12+
13+
# Compile wheels
14+
PYTHON="/opt/python/${ML_PYTHON_VERSION}/bin/python"
15+
PIP="/opt/python/${ML_PYTHON_VERSION}/bin/pip"
16+
"${PIP}" install --upgrade setuptools pip wheel~=0.31.1
17+
cd "${GITHUB_WORKSPACE}"
18+
make clean
19+
"${PYTHON}" setup.py bdist_wheel
20+
21+
# Bundle external shared libraries into the wheels.
22+
for whl in "${GITHUB_WORKSPACE}"/dist/*.whl; do
23+
auditwheel repair $whl -w "${GITHUB_WORKSPACE}"/dist/
24+
rm "${GITHUB_WORKSPACE}"/dist/*-linux_*.whl
25+
done

.github/workflows/release-trigger.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Trigger Release
2+
3+
on:
4+
pull_request_review:
5+
types: [submitted]
6+
7+
jobs:
8+
check-review:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Validate release PR
12+
uses: edgedb/action-release/validate-pr@master
13+
id: release
14+
continue-on-error: true
15+
with:
16+
github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
17+
version_file: httptools/_version.py
18+
version_line_pattern: |
19+
__version__\s*=\s*(?:['"])([[:PEP440:]])(?:['"])
20+
- name: Trigger release
21+
uses: edgedb/action-release/trigger@master
22+
if: steps.release.outputs.version != 0
23+
with:
24+
github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
25+
release_validation_check: "validate-release-request"

.github/workflows/release.yml

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
name: Release
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "master"
7+
- "ci"
8+
- "[0-9]+.[0-9x]+*"
9+
paths:
10+
- "httptools/_version.py"
11+
12+
jobs:
13+
validate-release-request:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Validate release PR
17+
uses: edgedb/action-release/validate-pr@master
18+
id: checkver
19+
with:
20+
github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
21+
version_file: httptools/_version.py
22+
version_line_pattern: |
23+
__version__\s*=\s*(?:['"])([[:PEP440:]])(?:['"])
24+
25+
- name: Stop if not approved
26+
if: steps.checkver.outputs.approved != 'true'
27+
run: |
28+
echo ::error::PR is not approved yet.
29+
exit 1
30+
31+
- name: Store release version for later use
32+
env:
33+
VERSION: ${{ steps.checkver.outputs.version }}
34+
run: |
35+
mkdir -p dist/
36+
echo "${VERSION}" > dist/VERSION
37+
38+
- uses: actions/upload-artifact@v1
39+
with:
40+
name: dist
41+
path: dist/
42+
43+
build-sdist:
44+
needs: validate-release-request
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- uses: actions/checkout@v1
49+
with:
50+
fetch-depth: 50
51+
submodules: true
52+
53+
- name: Set up Python 3.7
54+
uses: actions/setup-python@v1
55+
with:
56+
python-version: 3.7
57+
58+
- name: Build source distribution
59+
run: |
60+
pip install -U setuptools wheel pip
61+
python setup.py sdist
62+
63+
- uses: actions/upload-artifact@v1
64+
with:
65+
name: dist
66+
path: dist/
67+
68+
build-wheels:
69+
needs: validate-release-request
70+
runs-on: ${{ matrix.os }}
71+
strategy:
72+
matrix:
73+
python-version: [3.6, 3.7, 3.8]
74+
os: [ubuntu-16.04, macos-latest, windows-latest]
75+
76+
steps:
77+
- uses: actions/checkout@v1
78+
with:
79+
fetch-depth: 50
80+
submodules: true
81+
82+
- name: Set up Python ${{ matrix.python-version }}
83+
uses: actions/setup-python@v1
84+
with:
85+
python-version: ${{ matrix.python-version }}
86+
87+
- name: Install Python Deps
88+
run: |
89+
python -m pip install --upgrade setuptools pip wheel
90+
91+
- name: Build Wheels (linux)
92+
if: startsWith(matrix.os, 'ubuntu')
93+
uses: docker://quay.io/pypa/manylinux1_x86_64
94+
env:
95+
PYTHON_VERSION: ${{ matrix.python-version }}
96+
with:
97+
entrypoint: /github/workspace/.github/workflows/build-manylinux-wheels.sh
98+
99+
- name: Build Wheels (non-linux)
100+
if: "!startsWith(matrix.os, 'ubuntu')"
101+
run: |
102+
make clean
103+
python setup.py bdist_wheel
104+
105+
- name: Test Wheels
106+
if: |
107+
!startsWith(matrix.os, 'windows')
108+
&& !contains(github.event.pull_request.labels.*.name, 'skip wheel tests')
109+
run: |
110+
pip install --pre httptools -f "file:///${GITHUB_WORKSPACE}/dist"
111+
make -C "${GITHUB_WORKSPACE}" testinstalled
112+
113+
- uses: actions/upload-artifact@v1
114+
with:
115+
name: dist
116+
path: dist/
117+
118+
publish:
119+
needs: [build-sdist, build-wheels]
120+
runs-on: ubuntu-latest
121+
122+
steps:
123+
- uses: actions/checkout@v1
124+
with:
125+
fetch-depth: 5
126+
submodules: false
127+
128+
- uses: actions/download-artifact@v1
129+
with:
130+
name: dist
131+
path: dist/
132+
133+
- name: Extract Release Version
134+
id: relver
135+
run: |
136+
set -e
137+
echo ::set-output name=version::$(cat dist/VERSION)
138+
rm dist/VERSION
139+
140+
- name: Merge and tag the PR
141+
uses: edgedb/action-release/merge@master
142+
with:
143+
github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
144+
ssh_key: ${{ secrets.RELEASE_BOT_SSH_KEY }}
145+
gpg_key: ${{ secrets.RELEASE_BOT_GPG_KEY }}
146+
gpg_key_id: "5C468778062D87BF!"
147+
tag_name: v${{ steps.relver.outputs.version }}
148+
149+
- name: Publish Github Release
150+
uses: elprans/gh-action-create-release@master
151+
env:
152+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
153+
with:
154+
tag_name: v${{ steps.relver.outputs.version }}
155+
release_name: v${{ steps.relver.outputs.version }}
156+
target: ${{ github.event.pull_request.base.ref }}
157+
body: ${{ github.event.pull_request.body }}
158+
draft: true
159+
160+
- run: |
161+
ls -al dist/
162+
163+
- name: Upload to PyPI
164+
uses: pypa/gh-action-pypi-publish@master
165+
with:
166+
user: __token__
167+
password: ${{ secrets.PYPI_TOKEN }}
168+
# password: ${{ secrets.TEST_PYPI_TOKEN }}
169+
# repository_url: https://test.pypi.org/legacy/

.github/workflows/tests-reqs.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/tests.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,32 @@ jobs:
2323
with:
2424
fetch-depth: 50
2525
submodules: true
26+
27+
- name: Check if release PR.
28+
uses: edgedb/action-release/validate-pr@master
29+
continue-on-error: true
30+
id: release
31+
with:
32+
github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
33+
version_file: httptools/_version.py
34+
version_line_pattern: |
35+
__version__\s*=\s*(?:['"])([[:PEP440:]])(?:['"])
36+
2637
- name: Set up Python ${{ matrix.python-version }}
2738
uses: actions/setup-python@v1
39+
if: steps.release.outputs.version == 0
2840
with:
2941
python-version: ${{ matrix.python-version }}
42+
3043
- name: Install Deps
44+
if: steps.release.outputs.version == 0
3145
run: |
32-
pip install -U setuptools
33-
pip install -r .github/workflows/tests-reqs.txt
46+
pip install --upgrade setuptools pip wheel
47+
pip download --dest=/tmp/deps .[test]
48+
pip install -U --no-index --find-links=/tmp/deps /tmp/deps/*
49+
3450
- name: Test
35-
# wdf needs to be killed or vcvarsall.bat will pick it up
36-
# thinking it's the latest version of the Windows 10 SDK.
51+
if: steps.release.outputs.version == 0
3752
run: |
3853
python setup.py build_ext --inplace
3954
python setup.py test

Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
.PHONY: compile release test distclean
1+
.PHONY: compile release test distclean clean
2+
3+
4+
PYTHON ?= python3
5+
ROOT = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
26

37

48
compile:
@@ -12,8 +16,15 @@ release: compile test
1216
test:
1317
python3 setup.py test
1418

19+
clean:
20+
find $(ROOT)/httptools/parser -name '*.c' | xargs rm -f
21+
find $(ROOT)/httptools/parser -name '*.html' | xargs rm -f
1522

1623
distclean:
17-
git --git-dir="./vendor/http-parser/.git" clean -dfx
18-
find ./httptools/parser -name '*.c' | xargs rm -f
19-
find ./httptools/parser -name '*.html' | xargs rm -f
24+
git --git-dir="$(ROOT)/vendor/http-parser/.git" clean -dfx
25+
find $(ROOT)/httptools/parser -name '*.c' | xargs rm -f
26+
find $(ROOT)/httptools/parser -name '*.html' | xargs rm -f
27+
28+
29+
testinstalled:
30+
cd /tmp && $(PYTHON) $(ROOT)/tests/__init__.py

httptools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .parser import parser
22
from .parser import * # NOQA
33

4+
from ._version import __version__ # NOQA
45

56
__all__ = parser.__all__ # NOQA
6-
__version__ = '0.0.13'

httptools/_version.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file MUST NOT contain anything but the __version__ assignment.
2+
#
3+
# When making a release, change the value of __version__
4+
# to an appropriate value, and open a pull request against
5+
# the correct branch (master if making a new feature release).
6+
# The commit message MUST contain a properly formatted release
7+
# log, and the commit must be signed.
8+
#
9+
# The release automation will: build and test the packages for the
10+
# supported platforms, publish the packages on PyPI, merge the PR
11+
# to the target branch, create a Git tag pointing to the commit.
12+
13+
__version__ = '0.0.13'

setup.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import os.path
21
import sys
32

4-
from setuptools import setup, Extension
5-
from setuptools.command.build_ext import build_ext as build_ext
6-
7-
83
vi = sys.version_info
94
if vi < (3, 5):
105
raise RuntimeError('httptools require Python 3.5 or greater')
6+
else:
7+
import os.path
8+
import pathlib
9+
10+
from setuptools import setup, Extension
11+
from setuptools.command.build_ext import build_ext as build_ext
12+
1113

1214
CFLAGS = ['-O2']
13-
ROOT = os.path.dirname(__file__)
15+
16+
ROOT = pathlib.Path(__file__).parent
17+
18+
CYTHON_DEPENDENCY = 'Cython==0.29.14'
1419

1520

1621
class httptools_build_ext(build_ext):
@@ -123,15 +128,23 @@ def build_extensions(self):
123128
long_description = f.read()
124129

125130

126-
with open(os.path.join(ROOT, 'httptools', '__init__.py')) as f:
131+
with open(os.path.join(ROOT, 'httptools', '_version.py')) as f:
127132
for line in f:
128133
if line.startswith('__version__ ='):
129134
_, _, version = line.partition('=')
130135
VERSION = version.strip(" \n'\"")
131136
break
132137
else:
133138
raise RuntimeError(
134-
'unable to read the version from httptools/__init__.py')
139+
'unable to read the version from httptools/_version.py')
140+
141+
142+
setup_requires = []
143+
144+
if (not (ROOT / 'httptools' / 'parser' / 'parser.c').exists() or
145+
'--cython-always' in sys.argv):
146+
# No Cython output, require Cython to build.
147+
setup_requires.append(CYTHON_DEPENDENCY)
135148

136149

137150
setup(
@@ -150,7 +163,8 @@ def build_extensions(self):
150163
'Environment :: Web Environment',
151164
'Development Status :: 5 - Production/Stable',
152165
],
153-
platforms=['POSIX'],
166+
platforms=['macOS', 'POSIX', 'Windows'],
167+
zip_safe=False,
154168
author='Yury Selivanov',
155169
author_email='[email protected]',
156170
license='MIT',
@@ -167,7 +181,7 @@ def build_extensions(self):
167181
extra_compile_args=CFLAGS,
168182
),
169183
],
170-
provides=['httptools'],
171184
include_package_data=True,
172-
test_suite='tests.suite'
185+
test_suite='tests.suite',
186+
setup_requires=setup_requires,
173187
)

0 commit comments

Comments
 (0)