-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
301 lines (286 loc) · 8.76 KB
/
Copy pathJenkinsfile
File metadata and controls
301 lines (286 loc) · 8.76 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
def PLATFORM_MATRIX = [
[
name: "linux",
label: "linux && x64",
triplet: "x64-linux",
packageSuffix: "linux-x64",
packageExt: "tar.gz",
isWindows: false,
isMac: false
],
[
name: "macos",
label: "macos && arm64",
triplet: "arm64-osx",
packageSuffix: "macos-arm64",
packageExt: "tar.gz",
isWindows: false,
isMac: true
],
[
name: "windows",
label: "windows && x64",
triplet: "x64-windows-static",
packageSuffix: "windows-x64",
packageExt: "zip",
isWindows: true,
isMac: false
]
]
def runUnixBuild(Map cfg) {
if (!cfg.isMac) {
sh """#!/usr/bin/env bash
set -euo pipefail
sudo apt-get update
sudo apt-get install -y build-essential pkg-config nasm yasm libx11-dev libxext-dev libxtst-dev libxi-dev
"""
}
if (cfg.isMac) {
sh """#!/usr/bin/env bash
set -euo pipefail
brew install nasm yasm
"""
}
sh """#!/usr/bin/env bash
set -euo pipefail
node --version
npm --version
cd frontend
npm ci
npm run build
"""
if (cfg.isMac) {
sh """#!/usr/bin/env bash
set -euo pipefail
node -e '
const fs = require("fs");
const file = "vcpkg.json";
const json = JSON.parse(fs.readFileSync(file, "utf8"));
if (Array.isArray(json.dependencies)) {
for (const dep of json.dependencies) {
if (dep && typeof dep === "object" && dep.name === "ffmpeg" && Array.isArray(dep.features)) {
dep.features = dep.features.filter((feature) => feature !== "x265");
}
}
}
fs.writeFileSync(file, JSON.stringify(json, null, 2) + "\\n");
'
cat vcpkg.json
"""
}
sh """#!/usr/bin/env bash
set -euo pipefail
mkdir -p "\$VCPKG_DOWNLOADS" .vcpkg-binary-cache
if [[ ! -d "\$VCPKG_ROOT/.git" ]]; then
git clone https://github.com/microsoft/vcpkg.git "\$VCPKG_ROOT"
fi
"\$VCPKG_ROOT/bootstrap-vcpkg.sh" -disableMetrics
"\$VCPKG_ROOT/vcpkg" install --triplet "${cfg.triplet}"
"""
sh """#!/usr/bin/env bash
set -euo pipefail
HCONFIG="vcpkg_installed/${cfg.triplet}/include/hv/hconfig.h"
if [[ ! -f "\$HCONFIG" ]]; then
echo "hconfig.h not found: \$HCONFIG"
exit 1
fi
if ! grep -Eq '^[[:space:]]*#define[[:space:]]+WITH_OPENSSL[[:space:]]+1([[:space:]]|\$)' "\$HCONFIG"; then
echo "WITH_OPENSSL is not enabled in \$HCONFIG"
echo "---- \$HCONFIG ----"
sed -n '1,200p' "\$HCONFIG"
exit 1
fi
echo "Verified WITH_OPENSSL=1 in \$HCONFIG"
"""
sh """#!/usr/bin/env bash
set -euo pipefail
cmake -S . -B "\$BUILD_DIR" \\
-DCMAKE_BUILD_TYPE=Release \\
-DFERRYMAN_BUILD_FRONTEND=OFF \\
-DCMAKE_TOOLCHAIN_FILE="\$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" \\
-DVCPKG_TARGET_TRIPLET="${cfg.triplet}"
cmake --build "\$BUILD_DIR" --parallel
"""
sh """#!/usr/bin/env bash
set -euo pipefail
BIN_PATH="\$BUILD_DIR/Ferryman"
if [[ ! -f "\$BIN_PATH" ]]; then
BIN_PATH="\$BUILD_DIR/Release/Ferryman"
fi
if [[ ! -f "\$BIN_PATH" ]]; then
echo "Ferryman binary not found."
exit 1
fi
PKG_ROOT="package/ferryman-${cfg.packageSuffix}"
mkdir -p "\$PKG_ROOT"
cp "\$BIN_PATH" "\$PKG_ROOT/"
package_docs=(README.md LICENSE)
for doc in README_CN.md README_EN.md; do
if [[ -f "\$doc" ]]; then
package_docs+=("\$doc")
fi
done
cp "\${package_docs[@]}" "\$PKG_ROOT/"
tar -czf "ferryman-${cfg.packageSuffix}.tar.gz" -C package "ferryman-${cfg.packageSuffix}"
if [[ "${cfg.isMac}" == "false" ]]; then
PROXY_BIN_PATH="\$BUILD_DIR/FerrymanProxy"
if [[ ! -f "\$PROXY_BIN_PATH" ]]; then
PROXY_BIN_PATH="\$BUILD_DIR/Release/FerrymanProxy"
fi
if [[ ! -f "\$PROXY_BIN_PATH" ]]; then
echo "FerrymanProxy binary not found."
exit 1
fi
PROXY_PKG_ROOT="package/ferryman-proxy-${cfg.packageSuffix}"
mkdir -p "\$PROXY_PKG_ROOT"
cp "\$PROXY_BIN_PATH" "\$PROXY_PKG_ROOT/"
cp "\${package_docs[@]}" scripts/ferryman-proxy.service scripts/deploy_ferryman_proxy.sh "\$PROXY_PKG_ROOT/"
tar -czf "ferryman-proxy-${cfg.packageSuffix}.tar.gz" -C package "ferryman-proxy-${cfg.packageSuffix}"
fi
"""
}
def runWindowsBuild(Map cfg) {
powershell '''
$ErrorActionPreference = "Stop"
choco install nasm -y
'''
powershell '''
$ErrorActionPreference = "Stop"
node --version
npm --version
Push-Location frontend
npm ci
npm run build
Pop-Location
'''
powershell '''
$ErrorActionPreference = "Stop"
New-Item -ItemType Directory -Path "$env:VCPKG_DOWNLOADS" -Force | Out-Null
New-Item -ItemType Directory -Path ".vcpkg-binary-cache" -Force | Out-Null
if (-not (Test-Path "$env:VCPKG_ROOT\\.git")) {
git clone https://github.com/microsoft/vcpkg.git "$env:VCPKG_ROOT"
}
& "$env:VCPKG_ROOT\\bootstrap-vcpkg.bat" -disableMetrics
& "$env:VCPKG_ROOT\\vcpkg.exe" install --triplet "$env:VCPKG_TRIPLET"
'''
powershell '''
$ErrorActionPreference = "Stop"
$hconfig = "vcpkg_installed/$env:VCPKG_TRIPLET/include/hv/hconfig.h"
if (-not (Test-Path $hconfig)) {
throw "hconfig.h not found: $hconfig"
}
$content = Get-Content $hconfig -Raw
if ($content -notmatch "(?m)^\\s*#define\\s+WITH_OPENSSL\\s+1(\\s|$)") {
Write-Host "WITH_OPENSSL is not enabled in $hconfig"
Write-Host "---- $hconfig ----"
Get-Content $hconfig
throw "libhv OpenSSL backend verification failed"
}
Write-Host "Verified WITH_OPENSSL=1 in $hconfig"
'''
powershell '''
$ErrorActionPreference = "Stop"
cmake -S . -B "$env:BUILD_DIR" `
-A x64 `
-DCMAKE_BUILD_TYPE=Release `
-DFERRYMAN_BUILD_FRONTEND=OFF `
-DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" `
-DVCPKG_TARGET_TRIPLET="$env:VCPKG_TRIPLET"
cmake --build "$env:BUILD_DIR" --config Release --parallel
'''
powershell '''
$ErrorActionPreference = "Stop"
$binCandidates = @(
"$env:BUILD_DIR/Ferryman.exe",
"$env:BUILD_DIR/Release/Ferryman.exe"
)
$binPath = $binCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $binPath) {
throw "Ferryman.exe not found."
}
$pkgRoot = "package/ferryman-$env:PACKAGE_SUFFIX"
New-Item -ItemType Directory -Path $pkgRoot -Force | Out-Null
Copy-Item $binPath "$pkgRoot/Ferryman.exe" -Force
$packageDocs = @("README.md", "README_CN.md", "README_EN.md", "LICENSE") | Where-Object { Test-Path $_ }
Copy-Item $packageDocs $pkgRoot -Force
$zipPath = "ferryman-$env:PACKAGE_SUFFIX.zip"
if (Test-Path $zipPath) {
Remove-Item $zipPath -Force
}
Compress-Archive -Path "$pkgRoot/*" -DestinationPath $zipPath
'''
}
pipeline {
agent none
options {
timestamps()
disableConcurrentBuilds()
}
stages {
stage("Build Matrix") {
steps {
script {
def branches = [:]
for (cfg in PLATFORM_MATRIX) {
def localCfg = cfg
branches["${localCfg.name} / ${localCfg.triplet}"] = {
node(localCfg.label) {
ws("${env.WORKSPACE}@${localCfg.name}") {
deleteDir()
checkout scm
def root = pwd()
withEnv([
"BUILD_DIR=build",
"VCPKG_ROOT=${root}/vcpkg",
"VCPKG_TRIPLET=${localCfg.triplet}",
"PACKAGE_SUFFIX=${localCfg.packageSuffix}",
"VCPKG_FEATURE_FLAGS=manifests,binarycaching",
"VCPKG_BINARY_SOURCES=clear;files,${root}/.vcpkg-binary-cache,readwrite",
"VCPKG_DOWNLOADS=${root}/.vcpkg-downloads",
"VCPKG_DEFAULT_BINARY_CACHE=${root}/.vcpkg-binary-cache"
]) {
try {
if (localCfg.isWindows) {
runWindowsBuild(localCfg)
} else {
runUnixBuild(localCfg)
}
} catch (err) {
if (localCfg.isMac) {
sh """#!/usr/bin/env bash
set +e
echo "==== vcpkg x265 logs ===="
ls -la "\$VCPKG_ROOT/buildtrees/x265" || true
for f in \\
"\$VCPKG_ROOT/buildtrees/x265/config-arm64-osx-dbg-CMakeCache.txt.log" \\
"\$VCPKG_ROOT/buildtrees/x265/config-arm64-osx-rel-CMakeCache.txt.log" \\
"\$VCPKG_ROOT/buildtrees/x265/config-arm64-osx-dbg-CMakeConfigureLog.yaml.log" \\
"\$VCPKG_ROOT/buildtrees/x265/config-arm64-osx-rel-CMakeConfigureLog.yaml.log" \\
"\$VCPKG_ROOT/buildtrees/x265/config-arm64-osx-out.log"; do
if [[ -f "\$f" ]]; then
echo "---- \$f ----"
cat "\$f"
fi
done
"""
}
throw err
} finally {
def artifactsPattern = "ferryman-${localCfg.packageSuffix}.${localCfg.packageExt}"
if (!localCfg.isWindows && !localCfg.isMac) {
artifactsPattern += ",ferryman-proxy-${localCfg.packageSuffix}.tar.gz,scripts/deploy_ferryman_proxy.sh"
}
archiveArtifacts artifacts: artifactsPattern, fingerprint: true, onlyIfSuccessful: true
}
}
}
}
}
}
branches.failFast = false
parallel branches
}
}
}
}
}