Skip to content

Commit 52e3614

Browse files
committed
Building kits with GitHub Actions
1 parent 10b2f67 commit 52e3614

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

.github/workflows/kit.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
2+
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
3+
4+
# Based on:
5+
# https://github.com/joerick/cibuildwheel/blob/master/examples/github-deploy.yml
6+
7+
name: Build kits
8+
9+
on:
10+
push:
11+
branches: ["master"]
12+
pull_request:
13+
branches: ["master"]
14+
workflow_dispatch:
15+
16+
jobs:
17+
build_wheels:
18+
name: Build wheels on ${{ matrix.os }}
19+
runs-on: ${{ matrix.os }}
20+
strategy:
21+
matrix:
22+
os: [ubuntu-latest, windows-latest, macos-latest]
23+
fail-fast: false
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
28+
- uses: actions/setup-python@v2
29+
name: Install Python
30+
with:
31+
python-version: "3.7"
32+
33+
- name: Install cibuildwheel
34+
run: |
35+
python -m pip install cibuildwheel==1.7.0
36+
37+
- name: Install Visual C++ for Python 2.7
38+
if: runner.os == 'Windows'
39+
run: |
40+
choco install vcpython27 -f -y
41+
42+
- name: Build wheels
43+
env:
44+
# Don't build wheels for PyPy.
45+
CIBW_SKIP: pp*
46+
run: |
47+
python -m cibuildwheel --output-dir wheelhouse
48+
49+
- uses: actions/upload-artifact@v2
50+
with:
51+
path: ./wheelhouse/*.whl
52+
53+
build_sdist:
54+
name: Build source distribution
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v2
58+
59+
- uses: actions/setup-python@v2
60+
name: Install Python
61+
with:
62+
python-version: "3.7"
63+
64+
- name: Build sdist
65+
run: python setup.py sdist
66+
67+
- uses: actions/upload-artifact@v2
68+
with:
69+
path: dist/*.tar.gz

ci/download_gha_artifacts.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
2+
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
3+
4+
"""Use the GitHub API to download built artifacts."""
5+
6+
import os
7+
import os.path
8+
import zipfile
9+
10+
import requests
11+
12+
def download_url(url, filename):
13+
"""Download a file from `url` to `filename`."""
14+
response = requests.get(url, stream=True)
15+
if response.status_code == 200:
16+
with open(filename, "wb") as f:
17+
for chunk in response.iter_content(16*1024):
18+
f.write(chunk)
19+
20+
def unpack_zipfile(filename):
21+
"""Unpack a zipfile, using the names in the zip."""
22+
with open(filename, "rb") as fzip:
23+
z = zipfile.ZipFile(fzip)
24+
for name in z.namelist():
25+
print(f" extracting {name}")
26+
z.extract(name)
27+
28+
dest = "dist"
29+
repo_owner = "nedbat/coveragepy"
30+
temp_zip = "artifacts.zip"
31+
32+
if not os.path.exists(dest):
33+
os.makedirs(dest)
34+
os.chdir(dest)
35+
36+
r = requests.get(f"https://api.github.com/repos/{repo_owner}/actions/artifacts")
37+
latest = max(r.json()["artifacts"], key=lambda a: a["created_at"])
38+
download_url(latest["archive_download_url"], temp_zip)
39+
unpack_zipfile(temp_zip)
40+
os.remove(temp_zip)

0 commit comments

Comments
 (0)