-
Notifications
You must be signed in to change notification settings - Fork 0
329 lines (273 loc) · 9.49 KB
/
main.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
#
# SPDX-License-Identifier: MPL-2.0
name: Build and Test C++ and Python
# Controls when the workflow will run
on:
# run pipeline on push event of main branch
push:
branches:
- main
# run pipeline on pull request
pull_request:
# run pipeline on merge queue
merge_group:
# run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
create_release:
type: boolean
description: Create a (pre-)release when CI passes
default: true
required: true
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
acquire-python-version-build-sdist:
name: Build sdist and set version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Set PyPI Version
run: |
pip install requests build
python set_pypi_version.py
- name: Build SDist
run: python -m build --sdist --outdir wheelhouse .
- name: Keep version file
uses: actions/upload-artifact@v4
with:
name: version
path: PYPI_VERSION
- name: Keep SDist
uses: actions/upload-artifact@v4
with:
name: wheelhouse
path: ./wheelhouse/*.tar.gz
build-cpp-test-linux:
runs-on: ubuntu-latest
strategy:
matrix:
build-option: [ debug, release ]
compiler: [gcc, clang]
include:
- compiler: gcc
- compiler: clang
env:
CMAKE_PREFIX_PATH: /home/linuxbrew/.linuxbrew
PRESET: ci-${{ matrix.compiler }}-${{ matrix.build-option }}
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Initialize and update submodules
run: |
git submodule update --init --recursive
- name: Install packages
run: |
sudo apt-get update
sudo apt-get install -y ninja-build gcc-12 g++-12 clang-15
sudo ln -s /usr/bin/clang-15 /usr/local/bin/clang
sudo ln -s /usr/bin/clang++-15 /usr/local/bin/clang++
sudo ln -s /usr/bin/gcc-12 /usr/local/bin/gcc
sudo ln -s /usr/bin/g++-12 /usr/local/bin/g++
- name: Enable brew
run: |
echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
- name: Install C++ dependencies
run: |
brew install boost eigen nlohmann-json msgpack-cxx doctest
- name: Build and test
run: ./build.sh -p ${{ env.PRESET }} -i
build-cpp-test-windows:
runs-on: windows-latest
strategy:
matrix:
build-option: [ debug, release ]
compiler: [msvc, clang-cl]
env:
PRESET: ${{ matrix.compiler }}-${{ matrix.build-option }}
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Activate conda
uses: conda-incubator/setup-miniconda@v3 # install miniforge instead
with:
miniforge-version: latest
- name: List conda
run: |
conda info
conda list
- name: Install conda environment
run: |
conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge libboost-headers eigen nlohmann_json msgpack-cxx doctest
- name: Build and test
run: |
$vsPath = &(Join-Path ${env:ProgramFiles(x86)} '\Microsoft Visual Studio\Installer\vswhere.exe') -property installationpath
Import-Module (Join-Path $vsPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll')
Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -host_arch=x64'
# Resolve dirty PATH environment
# TODO(mgovers): Remove after https://github.com/actions/runner-images/issues/10001 is resolved
$env:PATH = ($env:PATH -split ';' | Where-Object { $_ -ne 'C:\Program Files\LLVM\bin' }) -join ';'
# generate cmake cache
cmake --preset ${{ env.PRESET }} -DCMAKE_PREFIX_PATH=C:\conda_envs\cpp_pkgs\Library; if(!$?) { Exit $LASTEXITCODE }
# build
cmake --build --preset ${{ env.PRESET }} --verbose -j 1; if(!$?) { Exit $LASTEXITCODE }
# test
ctest --preset ${{ env.PRESET }} --output-on-failure; if(!$?) { Exit $LASTEXITCODE }
# install
cmake --build --preset ${{ env.PRESET }} --verbose -j 1 --target install; if(!$?) { Exit $LASTEXITCODE }
build-cpp-test-macos:
runs-on: macos-14
strategy:
matrix:
build-option: [ debug, release ]
env:
CMAKE_PREFIX_PATH: /usr/local
PRESET: ci-clang-${{ matrix.build-option }}
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Set up XCode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- name: Install cpp dependencies
run: |
brew install ninja boost eigen nlohmann-json msgpack-cxx doctest
- name: Build and test
run: ./build.sh -p ${{ env.PRESET }} -i
build-and-test-python:
strategy:
matrix:
platform: [ linux-x64, linux-aarch64, macos, windows ]
include:
- platform: linux-x64
os: ubuntu-latest
cibw_build: "*_x86_64"
- platform: linux-aarch64
os: ubuntu-latest
cibw_build: "*_aarch64"
- platform: macos
os: macos-14
cibw_build: "*"
- platform: windows
os: windows-latest
cibw_build: "*"
runs-on: ${{ matrix.os }}
needs: [acquire-python-version-build-sdist]
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: actions/download-artifact@v4
with:
name: version
path: .
- name: Set up QEMU
if: matrix.os == 'ubuntu-latest'
uses: docker/setup-qemu-action@v3
- name: Set up XCode
if: matrix.os == 'macos-14'
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- name: Build wheels
uses: pypa/[email protected]
# GitHub Actions specific build parameters
env:
# pass GitHub runner info into Linux container
CIBW_ENVIRONMENT_PASS_LINUX: GITHUB_SHA GITHUB_REF GITHUB_RUN_NUMBER
CIBW_BUILD: ${{ matrix.cibw_build }}
- name: Keep wheel files
uses: actions/upload-artifact@v4
with:
name: wheelhouse-${{ matrix.platform }}
path: ./wheelhouse/*.whl
build-and-test-conda:
name: Build and test in Conda
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
os: ["ubuntu", "windows"] # We do not test conda for MacOS
defaults:
run:
shell: bash -el {0}
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: conda-incubator/setup-miniconda@v3
with:
miniforge-version: latest # use miniforge instead of miniconda
activate-environment: conda-pgm-env
environment-file: .github/conda_pgm_env.yml
auto-activate-base: false
- name: List conda
run: |
conda info
conda list
- name: Build
run: python -m pip install . -vv --no-build-isolation --no-deps
- name: Test
run: pytest
publish-wheels:
needs: [build-cpp-test-linux, build-cpp-test-windows, build-cpp-test-macos, build-and-test-python, build-and-test-conda]
# always run publish job but fail at the first step if previous jobs have been failed
if: always()
runs-on: ubuntu-latest
permissions:
contents: write
env:
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASS }}
steps:
- name: Fail fast
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: |
echo "Previous jobs have failures!"
exit 1
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.10'
architecture: x64
- uses: actions/download-artifact@v4
- uses: actions/download-artifact@v4
with:
name: version
path: .
- name: Combine wheelhouses
run: mv wheelhouse-*/* wheelhouse
- name: List assets
run: ls ./wheelhouse/ -al
- name: Get tag
id: tag
run: echo "tag=v$(cat PYPI_VERSION)" >> $GITHUB_OUTPUT
- name: Display tag
run: echo "${{ steps.tag.outputs.tag }}"
- name: Upload wheels
if: (github.event_name == 'push') || ((github.event_name == 'workflow_dispatch') && (github.event.inputs.create_release == 'true'))
run: |
pip install twine
echo "Publish to PyPI..."
twine upload --verbose wheelhouse/*
- name: Release
uses: softprops/action-gh-release@v2
if: (github.event_name == 'push') || ((github.event_name == 'workflow_dispatch') && (github.event.inputs.create_release == 'true'))
with:
files: |
./wheelhouse/*
tag_name: ${{ steps.tag.outputs.tag }}
prerelease: ${{ github.ref != 'refs/heads/main'}}
generate_release_notes: true
target_commitish: ${{ github.sha }}