Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e10d91e

Browse files
committedSep 13, 2023
chore(ci): migrate cicd to hatch
With Hatch as the new build system, the previous GitHub actions no longer work to lint, test, and publish the package. This commit makes use of pypa/cibuildwheel to build the package for multiple platforms, and then publishes the package to PyPI using the existing secrets. Signed-off-by: JP-Ellis <josh@jpellis.me>
1 parent e33a2b9 commit e10d91e

File tree

5 files changed

+253
-105
lines changed

5 files changed

+253
-105
lines changed
 

‎.cirrus.yml

+21-24
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,48 @@
1-
BUILD_TEST_TASK_TEMPLATE: &BUILD_TEST_TASK_TEMPLATE
1+
TEST_TEMPLATE: &TEST_TEMPLATE
22
arch_check_script:
33
- uname -am
44
test_script:
55
- python --version
6-
- python -m pip install --upgrade pip
7-
- python -m pip install -r requirements_dev.txt
8-
- python -m flake8
9-
- python -m pydocstyle pact
10-
- python -m tox -e test
11-
# - make examples
6+
# TODO: Fix lints before enabling
7+
- echo hatch run lint
8+
# TODO: Implement the examples to work in hatch
9+
- echo hatch run example
10+
- hatch run test
1211

13-
linux_arm64_task:
12+
linux_arm64_task:
1413
env:
14+
PATH: ${HOME}/.local/bin:${PATH}
1515
matrix:
16-
# - IMAGE: python:3.6-slim # This works locally, with cirrus run, but fails in CI
17-
- IMAGE: python:3.7-slim
1816
- IMAGE: python:3.8-slim
1917
- IMAGE: python:3.9-slim
2018
- IMAGE: python:3.10-slim
19+
- IMAGE: python:3.11-slim
2120
arm_container:
2221
image: $IMAGE
2322
install_script:
24-
- apt update --yes && apt install --yes gcc make
25-
<< : *BUILD_TEST_TASK_TEMPLATE
26-
23+
- apt update --yes
24+
- apt install --yes gcc make
25+
- python -m pip install --upgrade pip pipx
26+
- pipx install hatch
27+
<<: *TEST_TEMPLATE
2728

2829
macosx_arm64_task:
2930
macos_instance:
3031
image: ghcr.io/cirruslabs/macos-ventura-base:latest
3132
env:
32-
PATH: ${HOME}/.pyenv/shims:${PATH}
33+
PATH: ${HOME}/.local/bin:${HOME}/.pyenv/shims:${PATH}
3334
matrix:
34-
- PYTHON: 3.6
35-
- PYTHON: 3.7
3635
- PYTHON: 3.8
3736
- PYTHON: 3.9
3837
- PYTHON: 3.10
38+
- PYTHON: 3.11
3939
install_script:
40-
# Per the pyenv homebrew recommendations.
41-
# https://github.com/pyenv/pyenv/wiki#suggested-build-environment
42-
# - xcode-select --install # Unnecessary on Cirrus
43-
- brew update
44-
# - brew install openssl readline sqlite3 xz zlib
40+
- brew update
4541
- brew install pyenv
4642
- pyenv install ${PYTHON}
4743
- pyenv global ${PYTHON}
4844
- pyenv rehash
49-
## To install rosetta
50-
# - softwareupdate --install-rosetta --agree-to-license
51-
<< : *BUILD_TEST_TASK_TEMPLATE
45+
- python -m pip install --upgrade pip pipx
46+
- pipx install hatch
47+
- pyenv rehash
48+
<<: *TEST_TEMPLATE

‎.github/workflows/build.yml

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
name: build
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
branches:
8+
- master
9+
pull_request:
10+
branches:
11+
- master
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.head_ref }}
15+
cancel-in-progress: true
16+
17+
env:
18+
STABLE_PYTHON_VERSION: "3.11"
19+
CIBW_BUILD_FRONTEND: build
20+
CIBW_TEST_COMMAND: >
21+
python -c
22+
"from pact import EachLike;
23+
assert EachLike(1).generate() == {'json_class': 'Pact::ArrayLike', 'contents': 1, 'min': 1}
24+
"
25+
26+
jobs:
27+
build-x86_64:
28+
name: Build wheels on ${{ matrix.os }} (x86, 64-bit)
29+
runs-on: ${{ matrix.os }}
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
include:
34+
- os: ubuntu-latest
35+
archs: x86_64
36+
- os: macos-latest
37+
archs: x86_64
38+
- os: windows-latest
39+
archs: AMD64
40+
41+
steps:
42+
- uses: actions/checkout@v4
43+
with:
44+
# Fetch all tags
45+
fetch-depth: 0
46+
47+
- name: Create wheels
48+
uses: pypa/cibuildwheel@v2.15.0
49+
env:
50+
CIBW_ARCHS: ${{ matrix.archs }}
51+
52+
- name: Upload wheels
53+
uses: actions/upload-artifact@v3
54+
with:
55+
name: wheels
56+
path: ./wheelhouse/*.whl
57+
if-no-files-found: error
58+
59+
build-x86:
60+
name: Build wheels on ${{ matrix.os }} (x86, 32-bit)
61+
runs-on: ${{ matrix.os }}
62+
strategy:
63+
fail-fast: false
64+
matrix:
65+
include:
66+
- os: windows-latest
67+
archs: x86
68+
69+
steps:
70+
- uses: actions/checkout@v4
71+
with:
72+
# Fetch all tags
73+
fetch-depth: 0
74+
75+
- name: Create wheels
76+
uses: pypa/cibuildwheel@v2.15.0
77+
env:
78+
CIBW_ARCHS: ${{ matrix.archs }}
79+
80+
- name: Upload wheels
81+
uses: actions/upload-artifact@v3
82+
with:
83+
name: wheels
84+
path: ./wheelhouse/*.whl
85+
if-no-files-found: error
86+
87+
build-arm64:
88+
name: Build wheels on ${{ matrix.os }} (arm64)
89+
runs-on: ${{ matrix.os }}
90+
# As this requires emulation, it's not worth running on PRs
91+
# if: >-
92+
# github.event_name == 'push' &&
93+
# startsWith(github.event.ref, 'refs/tags')
94+
strategy:
95+
fail-fast: false
96+
matrix:
97+
include:
98+
- os: ubuntu-latest
99+
archs: aarch64
100+
build: '*manylinux*'
101+
- os: macos-latest
102+
archs: arm64
103+
build: '*'
104+
105+
steps:
106+
- uses: actions/checkout@v4
107+
with:
108+
# Fetch all tags
109+
fetch-depth: 0
110+
111+
- name: Set up QEMU
112+
if: matrix.os == 'ubuntu-latest'
113+
uses: docker/setup-qemu-action@v3
114+
with:
115+
platforms: arm64
116+
117+
- name: Create wheels
118+
uses: pypa/cibuildwheel@v2.15.0
119+
env:
120+
CIBW_ARCHS: ${{ matrix.archs }}
121+
CIBW_BUILD: ${{ matrix.build }}
122+
123+
- name: Upload wheels
124+
uses: actions/upload-artifact@v3
125+
with:
126+
name: wheels
127+
path: ./wheelhouse/*.whl
128+
if-no-files-found: error
129+
130+
check:
131+
name: Check wheels
132+
needs:
133+
- build-x86_64
134+
- build-x86
135+
- build-arm64
136+
runs-on: ubuntu-latest
137+
138+
steps:
139+
- uses: actions/checkout@v4
140+
- name: Setup Python
141+
uses: actions/setup-python@v4
142+
with:
143+
python-version: ${{ env.STABLE_PYTHON_VERSION }}
144+
145+
- uses: actions/download-artifact@v3
146+
with:
147+
name: wheels
148+
path: wheelhouse
149+
150+
- run: |
151+
pipx run twine check --strict wheelhouse/*
152+
153+
publish:
154+
name: Publish wheels
155+
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
156+
needs: [check]
157+
runs-on: ubuntu-latest
158+
159+
steps:
160+
- uses: actions/download-artifact@v3
161+
with:
162+
name: artifacts
163+
path: wheelhouse
164+
165+
- name: Push build artifacts to PyPI
166+
uses: pypa/gh-action-pypi-publish@v1.8.10
167+
with:
168+
skip_existing: true
169+
user: ${{ secrets.PYPI_USERNAME }}
170+
password: ${{ secrets.PYPI_PASSWORD }}
171+
packages-dir: wheelhouse

‎.github/workflows/build_and_test.yml

-54
This file was deleted.

‎.github/workflows/package_and_push_to_pypi.yml

-27
This file was deleted.

‎.github/workflows/test.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
env:
16+
STABLE_PYTHON_VERSION: "3.11"
17+
18+
jobs:
19+
run:
20+
name: >-
21+
Python ${{ matrix.python-version }}
22+
on ${{ matrix.os }}
23+
24+
runs-on: ${{ matrix.os }}
25+
continue-on-error: ${{ matrix.experimental }}
26+
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
os: [ubuntu-latest, windows-latest, macos-latest]
31+
python-version: ["3.8", "3.9", "3.10", "3.11"]
32+
experimental: [false]
33+
include:
34+
- # Run tests against the next Python version, but no need for the full list of OSes.
35+
os: ubuntu-latest
36+
python-version: "3.12-dev"
37+
experimental: true
38+
39+
steps:
40+
- uses: actions/checkout@v4
41+
42+
- name: Set up Python ${{ matrix.python-version }}
43+
uses: actions/setup-python@v4
44+
with:
45+
python-version: ${{ matrix.python-version }}
46+
47+
- name: Install Hatch
48+
run: pip install --upgrade hatch
49+
50+
- # TODO: Fix lints before enabling this
51+
name: Lint
52+
if: matrix.python-version == env.STABLE_PYTHON_VERSION && runner.os == 'Linux'
53+
run: echo hatch run lint
54+
55+
- # TODO: Implement the examples to work in hatch
56+
name: Examples
57+
if: matrix.python-version == env.STABLE_PYTHON_VERSION && runner.os == 'Linux'
58+
run: echo hatch run example
59+
60+
- name: Run tests and track code coverage
61+
run: hatch run test

0 commit comments

Comments
 (0)
Please sign in to comment.