-
Notifications
You must be signed in to change notification settings - Fork 4
325 lines (272 loc) · 10.3 KB
/
Copy pathrelease.yml
File metadata and controls
325 lines (272 loc) · 10.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
314
315
316
317
318
319
320
321
322
323
324
325
name: Build and release
on:
push:
branches:
- main
tags:
- 'v*.*.*'
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Linux x86_64
os: ubuntu-22.04
package: linux-x86_64
mads_asset: "*Linux-x86_64.tar.gz"
- name: Linux aarch64
os: ubuntu-22.04-arm
package: linux-aarch64
mads_asset: "*Linux-aarch64.tar.gz"
- name: macOS Universal
os: macos-15
package: macos-universal
mads_asset: "*Darwin-universal.sh"
cmake_osx_architectures: "arm64;x86_64"
- name: Windows x86_64
os: windows-2022
package: windows-x86_64
mads_asset: "*Windows-AMD64.exe"
steps:
- name: Check out sources
uses: actions/checkout@v6
- name: Install Linux build dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y \
clang \
cmake \
extra-cmake-modules \
ninja-build \
pkg-config
- name: Set up MSVC
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64
- name: Install MADS on Linux
if: runner.os == 'Linux'
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/mads-release" "$RUNNER_TEMP/mads"
curl -fsSL \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "User-Agent: mads-fmu-ci" \
"https://api.github.com/repos/pbosetti/MADS/releases/latest" \
-o "$RUNNER_TEMP/mads-release/latest.json"
asset_url="$(
python3 - "$RUNNER_TEMP/mads-release/latest.json" "${{ matrix.mads_asset }}" <<'PY'
import fnmatch
import json
import sys
with open(sys.argv[1], encoding="utf-8") as handle:
release = json.load(handle)
for asset in release["assets"]:
if fnmatch.fnmatch(asset["name"], sys.argv[2]):
print(asset["url"])
break
else:
raise SystemExit(f"No MADS release asset matches {sys.argv[2]}")
PY
)"
curl -fL \
-H "Accept: application/octet-stream" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "User-Agent: mads-fmu-ci" \
"$asset_url" \
-o "$RUNNER_TEMP/mads-release/mads.tar.gz"
archive="$RUNNER_TEMP/mads-release/mads.tar.gz"
tar -xzf "$archive" -C "$RUNNER_TEMP/mads"
agent_header="$(find "$RUNNER_TEMP/mads" -type f -path '*/include/agent.hpp' -print -quit)"
if [ -z "$agent_header" ]; then
echo "Could not find MADS headers after extracting $archive" >&2
exit 1
fi
mads_root="${agent_header%/include/agent.hpp}"
test -f "$mads_root/lib/libMadsCore.so"
echo "MADS_ROOT=$mads_root" >> "$GITHUB_ENV"
echo "$mads_root/bin" >> "$GITHUB_PATH"
- name: Install MADS on macOS
if: runner.os == 'macOS'
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/mads-release" "$RUNNER_TEMP/mads"
curl -fsSL \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "User-Agent: mads-fmu-ci" \
"https://api.github.com/repos/pbosetti/MADS/releases/latest" \
-o "$RUNNER_TEMP/mads-release/latest.json"
asset_url="$(
python3 - "$RUNNER_TEMP/mads-release/latest.json" "${{ matrix.mads_asset }}" <<'PY'
import fnmatch
import json
import sys
with open(sys.argv[1], encoding="utf-8") as handle:
release = json.load(handle)
for asset in release["assets"]:
if fnmatch.fnmatch(asset["name"], sys.argv[2]):
print(asset["url"])
break
else:
raise SystemExit(f"No MADS release asset matches {sys.argv[2]}")
PY
)"
installer="$RUNNER_TEMP/mads-release/mads.sh"
curl -fL \
-H "Accept: application/octet-stream" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "User-Agent: mads-fmu-ci" \
"$asset_url" \
-o "$installer"
sh "$installer" --skip-license --prefix="$RUNNER_TEMP/mads" --exclude-subdir
agent_header="$(find "$RUNNER_TEMP/mads" -type f -path '*/include/agent.hpp' -print -quit)"
if [ -z "$agent_header" ]; then
echo "Could not find MADS headers after running $installer" >&2
exit 1
fi
mads_root="${agent_header%/include/agent.hpp}"
test -f "$mads_root/lib/libMadsCore.dylib"
echo "MADS_ROOT=$mads_root" >> "$GITHUB_ENV"
echo "$mads_root/bin" >> "$GITHUB_PATH"
- name: Install MADS on Windows
if: runner.os == 'Windows'
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
New-Item -ItemType Directory -Force "$env:RUNNER_TEMP\mads-release", "$env:RUNNER_TEMP\mads" | Out-Null
$headers = @{
Authorization = "Bearer $env:GH_TOKEN"
Accept = "application/vnd.github+json"
"X-GitHub-Api-Version" = "2022-11-28"
"User-Agent" = "mads-fmu-ci"
}
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/pbosetti/MADS/releases/latest" -Headers $headers
$asset = $release.assets |
Where-Object { $_.name -like "${{ matrix.mads_asset }}" } |
Select-Object -First 1
if (-not $asset) {
throw "No MADS release asset matches ${{ matrix.mads_asset }}"
}
$installer = "$env:RUNNER_TEMP\mads-release\mads.exe"
$downloadHeaders = @{
Authorization = "Bearer $env:GH_TOKEN"
Accept = "application/octet-stream"
"X-GitHub-Api-Version" = "2022-11-28"
"User-Agent" = "mads-fmu-ci"
}
Invoke-WebRequest -Uri $asset.url -Headers $downloadHeaders -OutFile $installer
$installRoot = "$env:RUNNER_TEMP\mads"
$process = Start-Process `
-FilePath $installer `
-ArgumentList "/VERYSILENT", "/SUPPRESSMSGBOXES", "/NORESTART", "/SP-", "/CURRENTUSER", "/DIR=$installRoot" `
-Wait `
-PassThru
if ($process.ExitCode -ne 0) {
throw "MADS installer failed with exit code $($process.ExitCode)"
}
$agentHeader = Get-ChildItem $installRoot -Recurse -Filter agent.hpp |
Where-Object { $_.FullName -match '\\include\\agent\.hpp$' } |
Select-Object -First 1
if (-not $agentHeader) {
throw "Could not find MADS headers after running $installer"
}
$madsRoot = Split-Path (Split-Path $agentHeader.FullName -Parent) -Parent
$madsImportLibrary = Join-Path $madsRoot "lib\MadsCore.lib"
if (-not (Test-Path $madsImportLibrary)) {
throw "Could not find $madsImportLibrary"
}
"MADS_ROOT=$madsRoot" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"$madsRoot\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Configure
if: runner.os != 'Windows'
env:
CC: clang
CXX: clang++
CMAKE_OSX_ARCHITECTURES: ${{ matrix.cmake_osx_architectures }}
run: |
extra_args=()
if [ -n "${CMAKE_OSX_ARCHITECTURES:-}" ]; then
extra_args+=("-DCMAKE_OSX_ARCHITECTURES=$CMAKE_OSX_ARCHITECTURES")
fi
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$PWD/package" \
-DMADS_ROOT="$MADS_ROOT" \
-DMADS_BUILD_FMU=ON \
-DMADS_INSTALL_AGENT=ON \
"${extra_args[@]}"
- name: Configure
if: runner.os == 'Windows'
shell: pwsh
run: |
cmake -S . -B build -G Ninja `
-DCMAKE_BUILD_TYPE=Release `
"-DCMAKE_INSTALL_PREFIX=$env:GITHUB_WORKSPACE\package" `
"-DMADS_ROOT=$env:MADS_ROOT" `
"-DMADS_BUILD_FMU=ON" `
"-DMADS_INSTALL_AGENT=ON"
- name: Build
run: cmake --build build --config Release --parallel
- name: Package
run: cmake --build build --config Release --target package --parallel
- name: Upload package
uses: actions/upload-artifact@v7
with:
name: mads-fmu-${{ matrix.package }}
path: build/*.zip
if-no-files-found: error
release:
name: Create GitHub release
# if: startsWith(github.ref, 'refs/tags/')
needs: build
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- name: Download packages
uses: actions/download-artifact@v7
with:
pattern: mads-fmu-*
path: dist
merge-multiple: true
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
if [ "$GITHUB_REF_TYPE" = "tag" ]; then
release_tag="$GITHUB_REF_NAME"
release_title="$GITHUB_REF_NAME"
extra_args=(--verify-tag)
else
safe_ref="$(printf '%s' "$GITHUB_REF_NAME" | tr -c '[:alnum:]._-' '-')"
short_sha="${GITHUB_SHA::7}"
release_tag="${safe_ref}-${short_sha}"
release_title="${GITHUB_REF_NAME} ${short_sha}"
extra_args=(--target "$GITHUB_SHA")
fi
gh release create "$release_tag" dist/*.zip \
--repo "$GITHUB_REPOSITORY" \
--title "$release_title" \
--generate-notes \
"${extra_args[@]}"