Debian Codegraph @

.github/workflows/publish.yml

raw
1 name: Build and publish
2 on: [push, pull_request]
3
4 permissions:
5 contents: read
6
7 jobs:
8 get_python_versions:
9 name: "Determine Python versions"
10 runs-on: ubuntu-latest
11 permissions: {}
12 outputs:
13 min-python: ${{ steps.nep29.outputs.min-python }}
14 max-python: ${{ steps.nep29.outputs.max-python }}
15 steps:
16 - name: "calculate versions according to SPEC-0"
17 id: nep29
18 uses: mstimberg/github-calc-nep29@a73481e4e8488a5fa0b3be70a385cc5206a261ba # v0.7
19 with:
20 token: ${{ secrets.GITHUB_TOKEN }}
21 # Match SPEC-0
22 deprecate-python-after: 36
23 min-python-releases: 0
24
25 build:
26 needs: [get_python_versions]
27 name: Build 🎡 on ${{ matrix.os }}
28 runs-on: ${{ matrix.os }}
29 strategy:
30 fail-fast: false
31 matrix:
32 os: [ windows-latest, macos-15-intel, macos-latest ]
33 steps:
34 - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
35 with:
36 fetch-depth: 0
37 persist-credentials: false
38 - name: Fetch tags
39 run: git fetch --tags --force origin
40 - name: Set up Python 3.x
41 uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
42 with:
43 python-version: '3.x'
44 - name: Install platformdirs
45 run: python -m pip install platformdirs
46 - name: Display cibuildwheel cache dir
47 id: cibuildwheel-cache
48 run: |
49 from platformdirs import user_cache_path
50 import os
51
52 with open(os.getenv('GITHUB_OUTPUT'), 'w') as f:
53 f.write(f"dir={str(user_cache_path(appname='cibuildwheel', appauthor='pypa'))}")
54 shell: python
55 - name: Cache cibuildwheel tools
56 uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
57 with:
58 path: ${{ steps.cibuildwheel-cache.outputs.dir }}
59 key: ${{ runner.os }}-cibuildwheel
60 - name: Build wheels
61 uses: pypa/cibuildwheel@9c00cb4f6b517705a3794b22395aedc36257242c # v3.2.1
62 env:
63 CIBW_PROJECT_REQUIRES_PYTHON: ">=${{ needs.get_python_versions.outputs.min-python }}"
64 CIBW_ARCHS: auto64
65 CIBW_TEST_COMMAND: python {project}/dev/continuous-integration/run_simple_test.py
66 CIBW_TEST_REQUIRES: pytest
67 with:
68 output-dir: dist
69 - name: store distribution 📦
70 uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
71 with:
72 name: packages-${{ matrix.os }}
73 path: dist
74
75 build-linux:
76 needs: [get_python_versions]
77 name: Build 🎡 and source 📦 on ${{ matrix.config.image }}
78 runs-on: ${{ matrix.config.image }}
79 strategy:
80 fail-fast: false
81 matrix:
82 config: [{arch: auto64, image: ubuntu-24.04},
83 {arch: aarch64, image: ubuntu-24.04-arm}]
84 steps:
85 - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
86 with:
87 fetch-depth: 0
88 persist-credentials: false
89 - name: Fetch tags
90 run: git fetch --tags --force origin
91 - name: Set up Python 3.x
92 uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
93 with:
94 python-version: '3.x'
95 - name: Build source tarball
96 run: |
97 python -m pip install --upgrade pip build
98 python -m build --sdist --config-setting=--formats=gztar --config-setting=--with-cython --config-setting=--fail-on-error
99 if: matrix.config.arch == 'auto64'
100 - name: Install platformdirs
101 run: python -m pip install platformdirs
102 - name: Display cibuildwheel cache dir
103 id: cibuildwheel-cache
104 run: |
105 from platformdirs import user_cache_path
106 import os
107
108 with open(os.getenv('GITHUB_OUTPUT'), 'w') as f:
109 f.write(f"dir={str(user_cache_path(appname='cibuildwheel', appauthor='pypa'))}")
110 shell: python
111 - name: Cache cibuildwheel tools
112 uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
113 with:
114 path: ${{ steps.cibuildwheel-cache.outputs.dir }}
115 key: ${{ matrix.config.image }}-${{ matrix.config.arch }}-cibuildwheel
116 - name: Build wheels
117 uses: pypa/cibuildwheel@9c00cb4f6b517705a3794b22395aedc36257242c # v3.2.1
118 env:
119 CIBW_PROJECT_REQUIRES_PYTHON: ">=${{ needs.get_python_versions.outputs.min-python }}"
120 CIBW_ARCHS_LINUX: ${{ matrix.config.arch }}
121 CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
122 CIBW_SKIP: '*-musllinux_aarch64'
123 CIBW_TEST_COMMAND: python {project}/dev/continuous-integration/run_simple_test.py
124 CIBW_TEST_REQUIRES: pytest
125 with:
126 output-dir: dist
127 - name: store distribution 📦
128 uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
129 with:
130 name: packages-linux-${{ matrix.config.arch }}
131 path: dist
132
133 deploy_dev:
134 name: Publish development 📦 to TestPyPI
135 runs-on: ubuntu-latest
136 if: github.event_name == 'push' && github.repository == 'brian-team/brian2' && github.ref == 'refs/heads/master'
137 environment: development_release
138 permissions:
139 id-token: write # IMPORTANT: mandatory for trusted publishing
140 needs:
141 - build
142 - build-linux
143 steps:
144 - name: load distribution 📦
145 uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
146 with:
147 pattern: packages-*
148 merge-multiple: true
149 path: dist/
150 - name: Publish distribution 📦 to Test PyPI
151 uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
152 with:
153 repository-url: https://test.pypi.org/legacy/
154 verbose: true
155 print-hash: true
156
157 deploy:
158 name: Publish release 📦 to PyPI
159 runs-on: ubuntu-latest
160 if: github.event_name == 'push' && github.repository == 'brian-team/brian2' && startsWith(github.ref, 'refs/tags')
161 environment: release
162 permissions:
163 id-token: write # IMPORTANT: mandatory for trusted publishing
164 needs:
165 - build
166 - build-linux
167 steps:
168 - name: load distribution 📦
169 uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
170 with:
171 pattern: packages-*
172 merge-multiple: true
173 path: dist/
174 - name: Publish distribution release 📦 to PyPI
175 uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
176
177 build-docker:
178 name: Build docker image
179 runs-on: ubuntu-latest
180 needs: build-linux
181 permissions:
182 packages: write
183 # Skip everything for PR authors that do not have permission to access secrets
184 if: ${{ github.event_name == 'push' || (github.event.pull_request.author_association == 'COLLABORATOR' || github.event.pull_request.author_association == 'OWNER') }}
185 steps:
186 - name: Checkout repository
187 uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
188 with:
189 persist-credentials: false
190 # https://github.com/actions/checkout/
191 - name: Docker meta
192 id: meta
193 uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
194 # https://github.com/docker/metadata-action
195 with:
196 images: |
197 briansimulator/brian
198 ghcr.io/brian-team/brian
199 flavor: latest=true
200 tags: |
201 type=ref,event=tag
202 labels: |
203 org.opencontainers.image.title="Brian Docker Image"
204 org.opencontainers.image.description="Docker image for Brian - a free, open source simulator for spiking neural networks"
205 org.opencontainers.image.url=https://hub.docker.com/r/briansimulator/brian
206 org.opencontainers.image.source=https://github.com/brian-team/brian2
207 - name: Set up QEMU
208 uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
209 # https://github.com/docker/setup-qemu-action
210 with:
211 platforms: 'amd64,arm64'
212 - name: Set up Docker Buildx
213 uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
214 with:
215 cache-binary: false
216 # https://github.com/docker/setup-buildx-action
217 - name: Login to DockerHub
218 if: ${{ github.event_name == 'push' && github.repository == 'brian-team/brian2' && github.actor != 'dependabot[bot]'}}
219 uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
220 # https://github.com/docker/login-action
221 with:
222 username: ${{ secrets.DOCKERHUB_USERNAME }}
223 password: ${{ secrets.DOCKERHUB_TOKEN }}
224 - name: Login to GitHub Container Registry
225 if: ${{ github.event_name == 'push' && github.repository == 'brian-team/brian2' && github.actor != 'dependabot[bot]'}}
226 uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
227 with:
228 registry: ghcr.io
229 username: ${{ github.repository_owner }}
230 password: ${{ secrets.GITHUB_TOKEN }}
231 - name: load Linux x86 distribution 📦
232 uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
233 with:
234 pattern: packages-linux-*
235 merge-multiple: true
236 path: packages
237 - run: |
238 mkdir dist
239 cp packages/[Bb]rian2*cp312-manylinux*_x86_64.whl dist
240 cp packages/[Bb]rian2*cp312-manylinux*_aarch64.whl dist
241 - name: Build (and potentially push) the Docker image
242 uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
243 # https://github.com/docker/build-push-action
244 with:
245 context: .
246 file: docker/Dockerfile
247 build-args: |
248 'BASE_IMAGE_TAG=3.12-bookworm'
249 cache-from: type=gha
250 cache-to: type=gha,mode=max
251 platforms: 'amd64,arm64'
252 push: ${{ github.repository == 'brian-team/brian2' && startsWith(github.ref, 'refs/tags') && github.actor != 'dependabot[bot]'}}
253 tags: ${{ steps.meta.outputs.tags }}
254 labels: ${{ steps.meta.outputs.labels }}
255 - name: Push docker image to dev repository
256 if: ${{ github.repository == 'brian-team/brian2' && github.event_name == 'push' && !startsWith(github.ref, 'refs/tags') && github.actor != 'dependabot[bot]'}}
257 uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
258 with:
259 context: .
260 file: docker/Dockerfile
261 build-args: |
262 'BASE_IMAGE_TAG=3.12-bookworm'
263 platforms: 'amd64,arm64'
264 push: true
265 tags: |
266 briansimulator/brian-dev:dev-${{ github.ref_name }}
267 ghcr.io/brian-team/brian-dev:dev-${{ github.ref_name }}
268 labels: ${{ steps.meta.outputs.labels }}