-
Notifications
You must be signed in to change notification settings - Fork 0
272 lines (267 loc) · 12.8 KB
/
build.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
name: Build for Ubuntu-x64 and Windows-x64
on:
workflow_dispatch:
inputs:
create_release:
description: "Should a release be created?"
required: true
default: "false"
type: choice
options:
- "true"
- "false"
push:
permissions:
contents: write
jobs:
build:
name: Build Binaries
runs-on: ${{ matrix.os }}
strategy:
matrix:
# Note: We use the latest version of Ubuntu 24.04 in order to get a more recent version of Octave (we get 8.4 currently)
# We better should use a version >6.4, otherwise the Octave-mex-support seems to be missing some functions.
os: [ubuntu-24.04, ubuntu-22.04, windows-latest] # Windows and Linux builds
outputs:
linuxx64_ubuntu24_matlab_artifact: ${{ steps.prepare_linux_artifact.outputs.linuxx64_ubuntu24_matlab_build }}
linuxx64_ubuntu24_octave_artifact: ${{ steps.prepare_linux_artifact.outputs.linuxx64_ubuntu24_octave_build }}
linuxx64_ubuntu22_matlab_artifact: ${{ steps.prepare_linux_artifact.outputs.linuxx64_ubuntu22_matlab_build }}
linuxx64_ubuntu22_octave_artifact: ${{ steps.prepare_linux_artifact.outputs.linuxx64_ubuntu22_octave_build }}
windowsx64_matlab_artifact: ${{ steps.prepare_windows_matlab_artifact.outputs.windowsx64_matlab_build }}
windowsx64_octave_artifact: ${{ steps.prepare_windows_octave_artifact.outputs.windowsx64_octave_build }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v2
- name: run build (Linux)
if: runner.os == 'Linux'
shell: bash
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release -j
- name: run build (Windows)
if: runner.os == 'Windows'
shell: bash
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release -j
- name: Prepare MATLAB unit tests
shell: bash
run: |
# if on Windows, then this is the mex-file we need to copy to the tests/MATLAB folder
if [ -f "build/MEXlibCZI/Release/MEXlibCZI.mexw64" ]; then
cp "build/MEXlibCZI/Release/MEXlibCZI.mexw64" tests/MATLAB/
fi
if [ -f "build/MEXlibCZI/MEXlibCZI.mexa64" ]; then
cp "build/MEXlibCZI/MEXlibCZI.mexa64" tests/MATLAB/
fi
- name: Run MATLAB unit tests
uses: matlab-actions/run-command@v2
with:
command: cd tests/MATLAB; results = runtests, assertSuccess(results);
- name: Prepare MATLAB artifact (Linux Ubuntu24)
id: prepare_linux_matlab_artifact
if: matrix.os == 'ubuntu-24.04'
shell: bash
run: |
mkdir -p artifacts
name="MATLAB-MEXlibCZI-linux-ubuntu24_x64-$(git describe --always)"
mkdir -p artifacts/${name}
cp build/MEXlibCZI/MEXlibCZI.mexa64 artifacts/${name}/
echo "artifactName=${name}" >> "$GITHUB_ENV"
echo "artifactPath=artifacts/${name}" >> "$GITHUB_ENV"
echo "linuxx64_ubuntu24_matlab_build=${name}" >> "$GITHUB_OUTPUT"
- name: Prepare MATLAB artifact (Linux Ubuntu22)
id: prepare_linux_matlab_artifact
if: matrix.os == 'ubuntu-22.04'
shell: bash
run: |
mkdir -p artifacts
name="MATLAB-MEXlibCZI-linux-ubuntu22_x64-$(git describe --always)"
mkdir -p artifacts/${name}
cp build/MEXlibCZI/MEXlibCZI.mexa64 artifacts/${name}/
echo "artifactName=${name}" >> "$GITHUB_ENV"
echo "artifactPath=artifacts/${name}" >> "$GITHUB_ENV"
echo "linuxx64_ubuntu22_matlab_build=${name}" >> "$GITHUB_OUTPUT"
- name: install Octave (Windows)
if: runner.os == 'Windows'
shell: bash
run: |
choco install octave --no-progress
# I am not sure how to find the octave-cli-executable now, so we search for the link in the start menu
search_dir="/c/ProgramData/Microsoft/Windows/Start Menu/Programs"
octave_link=$(find "$search_dir" -type f -name "Octave*CLI*.lnk" 2>/dev/null)
octave_link_windows_path=$(cygpath -w "$octave_link")
echo "octave_link=$octave_link"
echo "octave_link_windows_path=$octave_link_windows_path"
echo "OCTAVECLI_LINK=$octave_link_windows_path" >> "$GITHUB_ENV"
- name: install Octave (Linux)
if: runner.os == 'Linux'
shell: bash
run: |
# the name of the "dev package" has changed as of Ubuntu 24.04
# Extract Ubuntu version from /etc/os-release
ubuntu_version=$(grep VERSION_ID /etc/os-release | cut -d '"' -f 2)
# Compare the version to 24.04 using dpkg --compare-versions
if dpkg --compare-versions "$ubuntu_version" ge "24.04"; then
octave_dev_package="octave-dev"
else
octave_dev_package="liboctave-dev"
fi
sudo apt-get install -y -qq -o=Dpkg::Progress-Fancy="0" octave $octave_dev_package
- name: build Octave mex-file (Windows)
if: runner.os == 'Windows'
shell: cmd
run: |
REM We compile the mex file for Octave within Octave itself, this seems the easiest way. The
REM downside is that installing octave takes a long time.
REM Note that we are using cmd.exe here, because it can "execute" the .lnk file.
"%OCTAVECLI_LINK%" --version
REM echo "cd %GITHUB_WORKSPACE%/OctaveMex , mkoctfile --mex octavelibczi.c"
set GITHUB_WORKSPACE_FORWARD_SLASHES=%GITHUB_WORKSPACE:\=/%
"%OCTAVECLI_LINK%" --eval "cd %GITHUB_WORKSPACE_FORWARD_SLASHES%/OctaveMex , mkoctfile --mex octavelibczi.c"
REM now, copy the libmexlibczi.dll to this folder
copy /B build\libmexlibczi\Release\libmexlibczi.dll %GITHUB_WORKSPACE%\OctaveMex
echo "*** directory listing of %GITHUB_WORKSPACE%\OctaveMex ***"
dir %GITHUB_WORKSPACE%\OctaveMex
- name: build Octave mex-file (Linux)
if: runner.os == 'Linux'
shell: bash
run: |
cd OctaveMex
# Get the version of Octave
octave_version=$(octave --version | head -n 1 | awk '{print $NF}')
echo "Detected Octave version: $octave_version"
# Define the version to compare against - for versions <= 6.4.0, we want to define "OCTAVEMEX_NO_GET_TYPED" in order to not use functions not available in older versions
max_version="6.4.0"
# Compare versions
if [[ "$(printf '%s\n' "$octave_version" "$max_version" | sort -V | head -n 1)" == "$octave_version" ]]; then
echo "Octave version is less than or equal to $max_version"
octave --eval "mkoctfile --mex octavelibczi.c -D OCTAVEMEX_NO_GET_TYPED"
else
echo "Octave version is greater than $max_version"
octave --eval "mkoctfile --mex octavelibczi.c"
fi
cp ../build/libmexlibczi/libmexlibczi.so . # now, copy the libmexlibczi.so to this folder
- name: Octave Unit-Tests (Linux)
if: runner.os == 'Linux'
shell: bash
run: |
cd tests/octave
# Note: Unfortunately, if using 'test' in functional form, there is no way to get the "test-result output" in the console it seems.
# c.f. https://docs.octave.org/interpreter/Test-Functions.html
octave --eval "addpath('../../OctaveMex'),if test('test_basic_operation.m'), exit(0); else, exit(1); end"
octave --eval "addpath('../../OctaveMex'),if test('test_write.m'), exit(0); else, exit(1); end"
- name: Octave Unit-Tests (Windows)
if: runner.os == 'Windows'
shell: cmd
run: |
cd tests/octave
set GITHUB_WORKSPACE_FORWARD_SLASHES=%GITHUB_WORKSPACE:\=/%
"%OCTAVECLI_LINK%" --eval "cd %GITHUB_WORKSPACE_FORWARD_SLASHES%/tests/octave,addpath('../../OctaveMex'),if test('test_basic_operation.m'), exit(0); else, exit(1); end"
"%OCTAVECLI_LINK%" --eval "cd %GITHUB_WORKSPACE_FORWARD_SLASHES%/tests/octave,addpath('../../OctaveMex'),if test('test_write.m'), exit(0); else, exit(1); end"
- name: Prepare MATLAB-mex artifact (Windows)
id: prepare_windows_matlab_artifact
if: runner.os == 'Windows'
shell: bash
run: |
mkdir -p artifacts
name="MATLAB-MEXlibCZI-windows-x64-$(git describe --always)"
mkdir -p "artifacts/${name}"
cp "build/MEXlibCZI/Release/MEXlibCZI.mexw64" "artifacts/${name}/"
echo "artifactName=${name}" >> "$GITHUB_ENV"
echo "artifactPath=artifacts/${name}" >> "$GITHUB_ENV"
echo "windowsx64_matlab_build=${name}" >> "$GITHUB_OUTPUT"
- name: Upload MATLAB-mex artifacts
uses: actions/upload-artifact@v4
with:
path: ${{ env.artifactPath }}/
name: ${{ env.artifactName }}
- name: Prepare Octave-mex artifact (Windows)
id: prepare_windows_octave_artifact
if: runner.os == 'Windows'
shell: bash
run: |
mkdir -p artifacts
name="Octave-MEXlibCZI-windows-x64-$(git describe --always)"
mkdir -p "artifacts/${name}"
cp $(cygpath "${GITHUB_WORKSPACE}")/OctaveMex/libmexlibczi.dll "artifacts/${name}/"
cp $(cygpath "${GITHUB_WORKSPACE}")/OctaveMex/octavelibczi.mex "artifacts/${name}/"
echo "artifactName=${name}" >> "$GITHUB_ENV"
echo "artifactPath=artifacts/${name}" >> "$GITHUB_ENV"
echo "windowsx64_octave_build=${name}" >> "$GITHUB_OUTPUT"
- name: Prepare Octave-mex artifact (Linux Ubuntu24)
id: prepare_linux_octave_artifact
if: matrix.os == 'ubuntu-24.04'
shell: bash
run: |
mkdir -p artifacts
name="Octave-MEXlibCZI-linux-ubuntu24_x64-$(git describe --always)"
mkdir -p "artifacts/${name}"
cp "${GITHUB_WORKSPACE}/OctaveMex/libmexlibczi.so" "artifacts/${name}/"
cp "${GITHUB_WORKSPACE}/OctaveMex/octavelibczi.mex" "artifacts/${name}/"
echo "artifactName=${name}" >> "$GITHUB_ENV"
echo "artifactPath=artifacts/${name}" >> "$GITHUB_ENV"
echo "linuxx64_ubuntu24_octave_build=${name}" >> "$GITHUB_OUTPUT"
- name: Prepare Octave-mex artifact (Linux Ubuntu22)
id: prepare_linux_octave_artifact
if: matrix.os == 'ubuntu-24.04'
shell: bash
run: |
mkdir -p artifacts
name="Octave-MEXlibCZI-linux-ubuntu22_x64-$(git describe --always)"
mkdir -p "artifacts/${name}"
cp "${GITHUB_WORKSPACE}/OctaveMex/libmexlibczi.so" "artifacts/${name}/"
cp "${GITHUB_WORKSPACE}/OctaveMex/octavelibczi.mex" "artifacts/${name}/"
echo "artifactName=${name}" >> "$GITHUB_ENV"
echo "artifactPath=artifacts/${name}" >> "$GITHUB_ENV"
echo "linuxx64_ubuntu22_octave_build=${name}" >> "$GITHUB_OUTPUT"
- name: Upload Octave-mex artifacts
uses: actions/upload-artifact@v4
with:
path: ${{ env.artifactPath }}/
name: ${{ env.artifactName }}
release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: build
if: inputs.create_release == 'true' # Only run if release is selected
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Download All Artifacts
if: needs.build.outputs.linuxx64_ubuntu24_matlab_artifact != '' || needs.build.outputs.linuxx64_ubuntu22_matlab_artifact != '' || needs.build.outputs.windowsx64_matlab_artifact != '' || needs.build.outputs.linuxx64_ubuntu24_octave_artifact != '' || needs.build.outputs.linuxx64_ubuntu22_octave_artifact != '' || needs.build.outputs.windowsx64_octave_artifact != ''
uses: actions/download-artifact@v4
with:
path: ./artifacts # download to a specific folder
- name: Script to prepare release
shell: bash
run: |
cd scripts
mexlibczi_version="$(bash get_version.sh)"
cd ..
git_version=$(git describe --always)
echo "releaseName=version ${mexlibczi_version} (${git_version})" >> "$GITHUB_ENV"
echo "tagName=v${mexlibczi_version}" >> "$GITHUB_ENV"
ls -l ./artifacts
cd ./artifacts
# Loop through all directories in the current directory
for dir in */; do
# Remove the trailing slash from the directory name
folder_name="$(basename "$dir")"
# Create a zip archive with the same name as the folder
7z a -tzip "${folder_name}.zip" "$folder_name"
done
- name: Release
uses: softprops/action-gh-release@v2
with:
name: ${{ env.releaseName }}
tag_name: ${{ env.tagName }}
files: |
./artifacts/*.zip
prerelease: true