diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2020-11-28 08:59:54 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2020-11-28 19:48:31 -0500 |
commit | 52e361421322414c5a30dc490805195bfb402ea7 (patch) | |
tree | c500f35999278a823ef4e016e424ad6fe4bb226d | |
parent | 10b2f67dc55d2886adf2286f320e13223a23fbed (diff) | |
download | python-coveragepy-git-52e361421322414c5a30dc490805195bfb402ea7.tar.gz |
Building kits with GitHub Actions
-rw-r--r-- | .github/workflows/kit.yml | 69 | ||||
-rw-r--r-- | ci/download_gha_artifacts.py | 40 |
2 files changed, 109 insertions, 0 deletions
diff --git a/.github/workflows/kit.yml b/.github/workflows/kit.yml new file mode 100644 index 00000000..167199cd --- /dev/null +++ b/.github/workflows/kit.yml @@ -0,0 +1,69 @@ +# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt + +# Based on: +# https://github.com/joerick/cibuildwheel/blob/master/examples/github-deploy.yml + +name: Build kits + +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] + workflow_dispatch: + +jobs: + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + fail-fast: false + + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-python@v2 + name: Install Python + with: + python-version: "3.7" + + - name: Install cibuildwheel + run: | + python -m pip install cibuildwheel==1.7.0 + + - name: Install Visual C++ for Python 2.7 + if: runner.os == 'Windows' + run: | + choco install vcpython27 -f -y + + - name: Build wheels + env: + # Don't build wheels for PyPy. + CIBW_SKIP: pp* + run: | + python -m cibuildwheel --output-dir wheelhouse + + - uses: actions/upload-artifact@v2 + with: + path: ./wheelhouse/*.whl + + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-python@v2 + name: Install Python + with: + python-version: "3.7" + + - name: Build sdist + run: python setup.py sdist + + - uses: actions/upload-artifact@v2 + with: + path: dist/*.tar.gz diff --git a/ci/download_gha_artifacts.py b/ci/download_gha_artifacts.py new file mode 100644 index 00000000..9580dced --- /dev/null +++ b/ci/download_gha_artifacts.py @@ -0,0 +1,40 @@ +# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt + +"""Use the GitHub API to download built artifacts.""" + +import os +import os.path +import zipfile + +import requests + +def download_url(url, filename): + """Download a file from `url` to `filename`.""" + response = requests.get(url, stream=True) + if response.status_code == 200: + with open(filename, "wb") as f: + for chunk in response.iter_content(16*1024): + f.write(chunk) + +def unpack_zipfile(filename): + """Unpack a zipfile, using the names in the zip.""" + with open(filename, "rb") as fzip: + z = zipfile.ZipFile(fzip) + for name in z.namelist(): + print(f" extracting {name}") + z.extract(name) + +dest = "dist" +repo_owner = "nedbat/coveragepy" +temp_zip = "artifacts.zip" + +if not os.path.exists(dest): + os.makedirs(dest) +os.chdir(dest) + +r = requests.get(f"https://api.github.com/repos/{repo_owner}/actions/artifacts") +latest = max(r.json()["artifacts"], key=lambda a: a["created_at"]) +download_url(latest["archive_download_url"], temp_zip) +unpack_zipfile(temp_zip) +os.remove(temp_zip) |