-
Notifications
You must be signed in to change notification settings - Fork 1
313 lines (254 loc) · 12.3 KB
/
Copy pathci.yml
File metadata and controls
313 lines (254 loc) · 12.3 KB
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
name: Build Wheels
on:
workflow_dispatch:
inputs:
build_for:
description: 'Target OS'
required: true
default: 'all'
options:
- 'linux'
- 'windows'
- 'macos'
- 'all'
jobs:
build:
runs-on: ${{ matrix.os }}
env:
SKIP: '0'
permissions:
contents: write # Ensure GitHub Actions can push changes
strategy:
matrix:
os: [ubuntu-20.04, windows-latest, macos-13, macos-latest]
python-version: ['3.10', '3.11', '3.12', '3.13']
architecture: [x86_64, arm64] # Add architecture matrix
steps:
- name: Check architecture
if: |
(runner.os != 'macOS' && matrix.architecture == 'arm64') ||
(matrix.os == 'windows-latest' && matrix.architecture == 'arm64') ||
(matrix.os == 'macos-13' && matrix.architecture == 'arm64') ||
(matrix.os == 'macos-latest' && matrix.architecture != 'arm64')
run: |
echo "Architecture is ARM but OS is not macOS. Skipping build."
echo "SKIP=1" >> $GITHUB_ENV
- name: Checkout code
if: env.SKIP == 0 && env.SKIP == 0
uses: actions/checkout@v2
- name: Clone DAGGER
if: env.SKIP == 0 && env.SKIP == 0
run: |
git clone https://github.com/bgailleton/DAGGER.git
cd DAGGER
git checkout main
# Install dependencies per OS
- name: Install build dependencies on Linux
if: runner.os == 'Linux' && env.SKIP == 0
run: |
sudo apt-get update
sudo apt-get install build-essential -y
sudo apt-get install -y gcc-8 g++-8 # Ensure GCC 8 is installed for C++17 support
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 60
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 60
- name: Install build dependencies on macOS
if: runner.os == 'macOS' && env.SKIP == 0
run: |
brew install gcc
- name: Install build dependencies on Windows
if: runner.os == 'Windows' && env.SKIP == 0
run: |
choco install visualstudio2022buildtools -y
# Set up Miniforge per OS
- name: Set up Miniforge on Linux
if: runner.os == 'Linux' && env.SKIP == 0
run: |
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh" -O miniforge.sh
bash miniforge.sh -b -p $HOME/miniforge
- name: Set up Miniforge on macOS
if: runner.os == 'macOS' && env.SKIP == 0
run: |
# Dealing with case where for macos-12 conda is somehow already there
rm -rf /usr/local/bin/conda
rm -rf $HOME/miniforge
ARCH=${{ matrix.architecture }}
if [ "$ARCH" = "x86_64" ]; then
echo "Installing Miniforge for Intel (x86_64)"
curl -L "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-x86_64.sh" -o miniforge.sh
elif [ "$ARCH" = "arm64" ]; then
echo "Installing Miniforge for ARM (arm64)"
curl -L "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh" -o miniforge.sh
else
echo "Unsupported architecture: $ARCH"
fi
bash miniforge.sh -b -p $HOME/miniforge
source $HOME/miniforge/bin/activate
# Set up Miniforge on Windows
- name: Set up Miniforge on Windows
if: runner.os == 'Windows' && env.SKIP == 0
run: |
curl -L -o miniforge.exe "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Windows-x86_64.exe"
Start-Process -FilePath "miniforge.exe" -ArgumentList '/InstallationType=JustMe', '/AddToPath=1', '/RegisterPython=0', '/S', "/D=$env:USERPROFILE\miniforge3" -NoNewWindow -Wait
# Install the correct Python environment based on matrix
- name: Install Python environment with Miniforge on Linux
if: runner.os == 'Linux' && env.SKIP == 0
run: |
source $HOME/miniforge/bin/activate && mamba create -n build_env python=${{ matrix.python-version }} -y
source $HOME/miniforge/bin/activate && mamba run -n build_env mamba install -c conda-forge xtensor-python -y
- name: Install Python environment with Miniforge on macOS
if: runner.os == 'macOS' && env.SKIP == 0
run: |
source $HOME/miniforge/bin/activate && mamba create -n build_env python=${{ matrix.python-version }} -y
source $HOME/miniforge/bin/activate && mamba run -n build_env mamba install -c conda-forge xtensor-python -y
# Install the correct Python environment based on matrix
- name: Install Python environment with Miniforge on Windows
if: runner.os == 'Windows' && env.SKIP == 0
run: |
set "CONDA=%UserProfile%\miniforge3" # Set the correct path for Miniforge
cmd /c "%CONDA%\Scripts\activate.bat && conda create -n build_env python=${{ matrix.python-version }} -y"
# cmd /c "%CONDA%\Scripts\activate.bat && conda run -n build_env conda install -c conda-forge xtensor-python -y"
# Install pip build tools (build, wheel) and create wheels
- name: Install pip build tools on Linux
if: runner.os == 'Linux' && env.SKIP == 0
run: |
source $HOME/miniforge/bin/activate && mamba run -n build_env pip install build wheel
- name: Install pip build tools on macOS
if: runner.os == 'macOS' && env.SKIP == 0
run: |
source $HOME/miniforge/bin/activate && mamba run -n build_env pip install build wheel
# Install pip build tools on Windows
- name: Install pip build tools on Windows
if: runner.os == 'Windows' && env.SKIP == 0
run: |
cmd /c "%CONDA%\Scripts\activate.bat && conda run -n build_env pip install build wheel"
# Build wheels for DAGGER
- name: Build DAGGER Wheels on Linux
if: runner.os == 'Linux' && env.SKIP == 0
run: |
source $HOME/miniforge/bin/activate && mamba run -n build_env pip wheel ./DAGGER/wrappers/python -w wheelhouse/dagger --no-deps
- name: Build DAGGER Wheels on macOS
if: runner.os == 'macOS' && env.SKIP == 0
run: |
source $HOME/miniforge/bin/activate && mamba run -n build_env pip wheel ./DAGGER/wrappers/python -w wheelhouse/dagger --no-deps
- name: Build DAGGER Wheels on Windows
if: runner.os == 'Windows' && env.SKIP == 0
run: |
# Set the correct path for Miniforge and xtensor include
$env:CONDA = "$env:USERPROFILE\miniforge3"
$env:XTENSOR_INCLUDE_PATH = "$env:CONDA\envs\build_env_dagger\Library\include"
$env:INCLUDE = "$env:XTENSOR_INCLUDE_PATH;$env:INCLUDE"
# Ensure the environment is created
cmd /c "%CONDA%\Scripts\activate.bat && conda create -n build_env_dagger python=${{ matrix.python-version }} -y"
# Install xtensor-python to the environment
cmd /c "%CONDA%\Scripts\activate.bat && conda run -n build_env_dagger conda install -c conda-forge xtensor-python -y"
# Finally, run the build process
cmd /c "%CONDA%\Scripts\activate.bat && conda run -n build_env_dagger pip wheel ./DAGGER/wrappers/python -w wheelhouse/dagger --no-deps"
# Build wheels for scabbard, ONLY ONCE so arbitrary choosing one run (i.e. one python version and one OS)
- name: Build scabbard Wheel
if: runner.os == 'Linux' && matrix.python-version == '3.12' && env.SKIP == 0
run: |
source $HOME/miniforge/bin/activate && mamba run -n build_env pip wheel . -w wheelhouse/scabbard --no-deps
# Commit and push the built wheels
- name: Commit wheels to repository
if: env.SKIP == 0
run: |
if [ "${{ runner.os }}" == "Linux" ] || [ "${{ runner.os }}" == "macOS" ]; then
mv wheelhouse/dagger/*.whl wheels/dagger/
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Stage local changes
git add wheels/**/*.whl
# Stash changes to prevent rebase conflicts
git stash
# Pull latest changes and rebase
git fetch origin
git rebase origin/main || git rebase --abort
# Apply stashed changes
git stash pop || echo "No local changes to apply"
# Add and commit changes again
git add wheels/**/*.whl
git commit -m "Add built wheels to repository [skip ci]"
# Try to push with error handling
RETRIES=20
for i in $(seq 1 $RETRIES); do
git push origin refs/heads/main && break || {
echo "Push failed, retrying $i/$RETRIES..."
git fetch origin
git rebase origin/main || git rebase --abort
sleep 5
}
done
if [ $i -eq $RETRIES ]; then
echo "Push failed after $RETRIES attempts, aborting."
exit 1
fi
elif [ "${{ runner.os }}" == "Windows" ]; then
# Write PowerShell script to a file
echo "New-Item -ItemType Directory -Path wheels\dagger -Force;" >> script.ps1
echo "# Move files" >> script.ps1
echo "Move-Item -Path wheelhouse\dagger\*.whl -Destination wheels\dagger;" >> script.ps1
echo "git config --global user.name 'github-actions[bot]';" >> script.ps1
echo "git config --global user.email 'github-actions[bot]@users.noreply.github.com';" >> script.ps1
echo "# Stage local changes" >> script.ps1
echo "git add wheels/**/*.whl;" >> script.ps1
echo "# Stash changes" >> script.ps1
echo "git stash;" >> script.ps1
echo "# Pull latest changes and rebase" >> script.ps1
echo "git fetch origin;" >> script.ps1
echo "if (!(git rebase origin/main)) { git rebase --abort; }" >> script.ps1
echo "# Apply stashed changes" >> script.ps1
echo "if (!(git stash pop)) { Write-Host 'No local changes to apply'; }" >> script.ps1
echo "# Add and commit changes" >> script.ps1
echo "git add wheels/**/*.whl;" >> script.ps1
echo "git commit -m 'Add built wheels to repository [skip ci]';" >> script.ps1
echo "# Retry logic" >> script.ps1
echo "\$RETRIES = 20;" >> script.ps1
echo "\$i = 1;" >> script.ps1
echo "while (\$i -le \$RETRIES) {" >> script.ps1
echo " if (git push origin refs/heads/main) { break; }" >> script.ps1
echo " else {" >> script.ps1
echo " Write-Host 'Push failed, retrying \$i/\$RETRIES...';" >> script.ps1
echo " git fetch origin;" >> script.ps1
echo " if (!(git rebase origin/main)) { git rebase --abort; }" >> script.ps1
echo " Start-Sleep -Seconds 5;" >> script.ps1
echo " \$i = \$i + 1;" >> script.ps1
echo " }" >> script.ps1
echo "}" >> script.ps1
echo "if (\$i -eq \$RETRIES) { Write-Host 'Push failed after \$RETRIES attempts, aborting.'; exit 1; }" >> script.ps1
# Execute the PowerShell script
powershell -File script.ps1
fi
shell: bash
# Commit and push the built wheels for scabbard (done once)
- name: Commit scabbard wheel to repository
if: runner.os == 'Linux' && matrix.python-version == '3.12' && env.SKIP == 0
run: |
mv wheelhouse/scabbard/*.whl wheels/scabbard/
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Stage local changes
git add wheels/scabbard/*.whl
# Stash changes to prevent rebase conflicts
git stash
# Pull latest changes and rebase
git fetch origin
git rebase origin/main || git rebase --abort
# Apply stashed changes
git stash pop || echo "No local changes to apply"
# Add and commit changes again
git add wheels/scabbard/*.whl
git commit -m "Add scabbard wheel to repository [skip ci]"
# Try to push with error handling
RETRIES=20
for i in $(seq 1 $RETRIES); do
git push origin refs/heads/main && break || {
echo "Push failed, retrying $i/$RETRIES..."
git fetch origin
git rebase origin/main || git rebase --abort
sleep 5
}
done
if [ $i -eq $RETRIES ]; then
echo "Push failed after $RETRIES attempts, aborting."
exit 1
fi