-
Notifications
You must be signed in to change notification settings - Fork 2
153 lines (136 loc) · 4.37 KB
/
test_and_deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
name: "CI & CD"
on:
workflow_dispatch:
pull_request:
release:
types:
- published
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
CIBW_BUILD: cp310-* cp311-* cp312-*
CIBW_TEST_EXTRAS: test
CIBW_TEST_COMMAND: pytest {project}
CIBW_DEPENDENCY_VERSIONS: "pinned"
# Once GHA and cibuildwheel are updated this can be removed
# mussllinux takes 6+ hrs to build and test so ignore it
CIBW_TEST_SKIP: "*musllinux*"
jobs:
lint:
name: Check code style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install ruff
run: pip install ruff
- name: Check code formatting
run: ruff format --diff
- name: Lint code base
run: ruff check
- name: Check for trailing whitespace and newlines at the file ends
run: ruff check --preview --select W291,W292,W391
generate-wheels-matrix:
name: "Generate wheels matrix"
runs-on: "ubuntu-latest"
outputs:
include: ${{ steps.set-matrix.outputs.include }}
steps:
- uses: actions/checkout@v4
- name: Install cibuildwheel
# MAKE SURE THIS STAYS IN SYNC WITH THE LOWER GHA cibuildwheel
run: pipx install cibuildwheel==2.19.1
- id: set-matrix
run: |
MATRIX=$(
{
cibuildwheel --print-build-identifiers --platform linux \
| jq -nRc '{"dist": inputs, "os": "ubuntu-latest"}' \
&& cibuildwheel --print-build-identifiers --platform macos \
| jq -nRc '
if (inputs | contains("x86_64")) then
{"dist": inputs, "os": "macos-13"}
else
{"dist": inputs, "os": "macos-latest"}
end
' \
&& cibuildwheel --print-build-identifiers --platform windows \
| jq -nRc '{"dist": inputs, "os": "windows-latest"}'
} | jq -sc
)
echo "include=$MATRIX" | tee -a $GITHUB_OUTPUT
env:
CIBW_ARCHS_LINUX: "x86_64"
CIBW_ARCHS_MACOS: "x86_64 arm64"
CIBW_ARCHS_WINDOWS: "x86 AMD64"
# Skip musllinux because it takes too long to compile on GHA
# since it is emulated. (6+ hours)
# *note* most of the build time is actually numpy for musllinux
CIBW_SKIP: "*musllinux* *-manylinux_i686 *-musllinux_i686 *-win32 pp*"
test-and-build:
name: "Build & Test"
needs: "generate-wheels-matrix"
strategy:
matrix:
include: ${{ fromJson(needs.generate-wheels-matrix.outputs.include) }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
# QEMU enables building/testing for non-native architectures (ie arm64)
# at the cost of speed
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Build & (optionally) test wheels
# MAKE SURE THIS STAYS IN SYNC WITH THE UPPER pipx call to cibuildwheel
uses: pypa/cibuildwheel@v2.19.1
with:
only: ${{ matrix.dist }}
- uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.dist }}
path: ./wheelhouse/*.whl
make-sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build source distribution
run: pipx run build --sdist
- uses: actions/upload-artifact@v4
with:
name: release-sdist
path: dist//*.tar.gz
upload-package:
name: Upload package to GitHub Releases & PyPI
permissions:
contents: write
needs:
- lint
- test-and-build
- make-sdist
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
pattern: release-*
merge-multiple: true
path: dist
- name: List distributions to be uploaded
run: ls dist
- name: Upload to GitHub Releases
uses: softprops/action-gh-release@v2.0.5
if: github.event_name == 'release' && github.event.action == 'published'
with:
files: dist//*
- name: Upload to PyPI
uses: pypa/gh-action-pypi-publish@v1.9.0
if: github.event_name == 'release' && github.event.action == 'published'
with:
password: ${{ secrets.PYPI_TOKEN }}