-
Notifications
You must be signed in to change notification settings - Fork 221
239 lines (231 loc) · 8.24 KB
/
publish.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
name: Build and publish
on: [push, pull_request]
jobs:
get_python_versions:
name: "Determine Python versions"
runs-on: ubuntu-latest
outputs:
min-python: ${{ steps.nep29.outputs.min-python }}
max-python: ${{ steps.nep29.outputs.max-python }}
steps:
- name: "calculate versions according to NEP29"
id: nep29
uses: mstimberg/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
build:
needs: [get_python_versions]
name: Build 🎡 on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ windows-latest, macOS-12, macOS-14 ]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.x
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install platformdirs
run: python -m pip install platformdirs
- name: Display cibuildwheel cache dir
id: cibuildwheel-cache
run: |
from platformdirs import user_cache_path
import os
with open(os.getenv('GITHUB_OUTPUT'), 'w') as f:
f.write(f"dir={str(user_cache_path(appname='cibuildwheel', appauthor='pypa'))}")
shell: python
- name: Cache cibuildwheel tools
uses: actions/cache@v4
with:
path: ${{ steps.cibuildwheel-cache.outputs.dir }}
key: ${{ runner.os }}-cibuildwheel
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_PROJECT_REQUIRES_PYTHON: ">=${{ needs.get_python_versions.outputs.min-python }}"
CIBW_ARCHS: auto64
# Do not build for PyPy
CIBW_SKIP: 'pp*'
CIBW_TEST_COMMAND: python {project}/dev/continuous-integration/run_simple_test.py
CIBW_TEST_REQUIRES: pytest
with:
output-dir: dist
- name: store distribution 📦
uses: actions/upload-artifact@v4
with:
name: packages-${{ matrix.os }}
path: dist
build-linux:
needs: [get_python_versions]
name: Build ${{ matrix.arch }} 🎡 and source 📦 on Linux
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch: [ auto64, aarch64 ]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.x
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Build source tarball
run: |
python -m pip install --upgrade pip build
python -m build --sdist --config-setting=--formats=gztar --config-setting=--with-cython --config-setting=--fail-on-error
if: ${{ matrix.arch == 'auto64' }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Install platformdirs
run: python -m pip install platformdirs
- name: Display cibuildwheel cache dir
id: cibuildwheel-cache
run: |
from platformdirs import user_cache_path
import os
with open(os.getenv('GITHUB_OUTPUT'), 'w') as f:
f.write(f"dir={str(user_cache_path(appname='cibuildwheel', appauthor='pypa'))}")
shell: python
- name: Cache cibuildwheel tools
uses: actions/cache@v4
with:
path: ${{ steps.cibuildwheel-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.arch }}-cibuildwheel
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_PROJECT_REQUIRES_PYTHON: ">=${{ needs.get_python_versions.outputs.min-python }}"
CIBW_ARCHS_LINUX: ${{ matrix.arch }}
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_SKIP: 'pp* *-musllinux_aarch64'
CIBW_TEST_COMMAND: python {project}/dev/continuous-integration/run_simple_test.py
CIBW_TEST_REQUIRES: pytest
with:
output-dir: dist
- name: store distribution 📦
uses: actions/upload-artifact@v4
with:
name: packages-linux-${{ matrix.arch }}
path: dist
deploy_dev:
name: Publish development 📦 to TestPyPI
runs-on: ubuntu-latest
if: github.repository == 'brian-team/brian2' && github.ref == 'refs/heads/master'
environment: development_release
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
needs:
- build
- build-linux
steps:
- name: load distribution 📦
uses: actions/download-artifact@v4
with:
pattern: packages-*
merge-multiple: true
path: dist/
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
deploy:
name: Publish release 📦 to PyPI
runs-on: ubuntu-latest
if: github.repository == 'brian-team/brian2' && startsWith(github.ref, 'refs/tags')
environment: release
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
needs:
- build
- build-linux
steps:
- name: load distribution 📦
uses: actions/download-artifact@v4
with:
pattern: packages-*
merge-multiple: true
path: dist/
- name: Publish distribution release 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
build-docker:
name: Build docker image
runs-on: ubuntu-latest
needs: build-linux
steps:
- name: Checkout repository
uses: actions/checkout@v4
# https://github.com/actions/checkout/
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
# https://github.com/docker/metadata-action
with:
images: |
briansimulator/brian
flavor: latest=true
tags: |
# type=semver,pattern={{raw}}
type=ref,event=tag
labels: |
org.opencontainers.image.title="Brian Docker Image"
org.opencontainers.image.description="Docker image for Brian - a free, open source simulator for spiking neural networks"
org.opencontainers.image.url=https://hub.docker.com/r/briansimulator/brian
org.opencontainers.image.source=https://github.com/brian-team/brian2
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# https://github.com/docker/setup-qemu-action
with:
platforms: 'amd64,arm64'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# https://github.com/docker/setup-buildx-action
- name: Login to DockerHub
if: ${{ github.repository == 'brian-team/brian2' && github.actor != 'dependabot[bot]'}}
uses: docker/login-action@v3
# https://github.com/docker/login-action
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: load Linux x86 distribution 📦
uses: actions/download-artifact@v4
with:
pattern: packages-linux-*
merge-multiple: true
path: packages
- run: |
mkdir dist
cp packages/Brian2*cp312-manylinux*_x86_64.whl dist
cp packages/Brian2*cp312-manylinux*_aarch64.whl dist
- name: Build (and potentially push) the Docker image
uses: docker/build-push-action@v6
# https://github.com/docker/build-push-action
with:
context: .
file: docker/Dockerfile
build-args: |
'BASE_IMAGE_TAG=3.12-bookworm'
platforms: 'amd64,arm64'
push: ${{ github.repository == 'brian-team/brian2' && startsWith(github.ref, 'refs/tags') && github.actor != 'dependabot[bot]'}}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Push docker image to dev repository
if: ${{ github.repository == 'brian-team/brian2' && github.event_name == 'push' && !startsWith(github.ref, 'refs/tags') && github.actor != 'dependabot[bot]'}}
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile
build-args: |
'BASE_IMAGE_TAG=3.12-bookworm'
platforms: 'amd64,arm64'
push: true
tags: briansimulator/brian-dev:dev-${{ github.ref_name }}
labels: ${{ steps.meta.outputs.labels }}