forked from thirtythreeforty/neolink
-
-
Notifications
You must be signed in to change notification settings - Fork 50
427 lines (416 loc) · 16.2 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
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
name: CI
on:
push:
pull_request:
workflow_dispatch:
jobs:
pre_job:
# continue-on-error: true # Uncomment once integration is finished
runs-on: ubuntu-latest
# Map a step output to a job output
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }} && ! (startsWith(github.ref, 'refs/tags/') && github.event_name == 'push')
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v5
with:
# All of these options are optional, so you can remove them if you are happy with the defaults
concurrent_skipping: "same_content_newer"
skip_after_successful_duplicate: "false"
native:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
name: native
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, windows-2022, macos-12, macos-14] # macos-14+ is arm64
steps:
- uses: actions/checkout@v4
name: Checkout onto ${{ runner.os }}
- if: runner.os == 'Linux'
name: apt install linux deps
run: |
sudo apt update
sudo apt install -y aptitude
sudo aptitude install -y libgstrtspserver-1.0-dev libgstreamer1.0-dev libgtk2.0-dev protobuf-compiler libssl-dev
- if: runner.os == 'Windows'
name: Install Windows deps
run: |
# Gstreamer
choco install -y --no-progress gstreamer --version=1.24.2
choco install -y --no-progress gstreamer-devel --version=1.24.2
$env:GSTREAMER_1_0_ROOT_MSVC_X86_64=$env:SYSTEMDRIVE + '\gstreamer\1.0\msvc_x86_64\'
# Github runners work on both C or D drive and figuring out which was used is difficult
if (-not (Test-Path -Path "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64" -PathType Container)) {
$env:GSTREAMER_1_0_ROOT_MSVC_X86_64='D:\\gstreamer\1.0\msvc_x86_64\'
}
echo "GSTREAMER_1_0_ROOT_MSVC_X86_64=$env:GSTREAMER_1_0_ROOT_MSVC_X86_64"
# Proto buffers
choco install -y --no-progress protoc --version=24.2.0
# Open SSL
choco install -y --no-progress openssl --version=1.1.1.2100
$env:OPENSSL_DIR=$env:SYSTEMDRIVE + '\Program Files\OpenSSL-Win64\'
# Alternative openssl location (depends on version that gets installed by choco)
if (-not (Test-Path -Path "$env:OPENSSL_DIR" -PathType Container)) {
$env:OPENSSL_DIR=$env:SYSTEMDRIVE + '\Program Files\OpenSSL\'
}
# Github runners work on both C or D drive and figuring out which was used is difficult
if (-not (Test-Path -Path "$env:OPENSSL_DIR" -PathType Container)) {
$env:OPENSSL_DIR='D:\\Program Files\OpenSSL-Win64\'
}
# Or course we could be on alternative location and drive....
if (-not (Test-Path -Path "$env:OPENSSL_DIR" -PathType Container)) {
$env:OPENSSL_DIR='D:\\Program Files\OpenSSL\'
}
# Set github vars
Add-Content -Path $env:GITHUB_ENV -Value "GSTREAMER_1_0_ROOT_MSVC_X86_64=$env:GSTREAMER_1_0_ROOT_MSVC_X86_64"
Add-Content -Path $env:GITHUB_PATH -Value "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64\bin"
Add-Content -Path $env:GITHUB_PATH -Value "%GSTREAMER_1_0_ROOT_MSVC_X86_64%\bin"
Add-Content -Path $env:GITHUB_ENV -Value "OPENSSL_DIR=$env:OPENSSL_DIR"
# One last check on directories
dir "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64"
dir "$env:OPENSSL_DIR"
- if: runner.os == 'macOS'
name: Install macOS deps
run: |
curl -L 'https://gstreamer.freedesktop.org/data/pkg/osx/1.20.4/gstreamer-1.0-devel-1.20.4-universal.pkg' -o "$(pwd)/gstreamer-devel.pkg"
sudo installer -verbose -pkg "$(pwd)/gstreamer-devel.pkg" -target /
PKG_CONFIG_PATH="/Library/Frameworks/GStreamer.framework/Versions/1.0/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
PKG_CONFIG_GSTREAMER_1_0_PREFIX="/Library/Frameworks/GStreamer.framework/Versions/1.0"
echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}" >> "${GITHUB_ENV}"
echo "PKG_CONFIG_GSTREAMER_1_0_PREFIX=${PKG_CONFIG_GSTREAMER_1_0_PREFIX}" >> "${GITHUB_ENV}"
echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}"
brew install pkg-config protobuf [email protected]
echo "OPENSSL_INCLUDE_DIR=$(brew --prefix [email protected])/include/" >> "${GITHUB_ENV}"
echo "OPENSSL_LIB_DIR=$(brew --prefix [email protected])/lib/" >> "${GITHUB_ENV}"
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
if: runner.os != 'macOS' # Random missing crates on macOS, unclear why
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Build
shell: bash
run: |
echo "PATH=${PATH}"
echo "GSTREAMER_1_0_ROOT_MSVC_X86_64=${GSTREAMER_1_0_ROOT_MSVC_X86_64}"
echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}"
# pkg-config --variable pc_path pkg-config
export JEMALLOC_SYS_WITH_LG_PAGE=16
cargo build --release --all-features
- uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.os }}
path: "target/release/neolink*"
cross:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
name: cross
runs-on: ubuntu-latest
container: "node:current-bookworm-slim"
strategy:
fail-fast: false
matrix:
# Everyone has a slightly different screwball naming scheme;
# Rust uses the target triple, GCC generally targets a family
# with a specific prefix, and dpkg's arch does its own thing
include:
- arch: amd64
target: x86_64-unknown-linux-gnu
gcc: x86-64-linux-gnu
pkgconfig: x86_64-linux-gnu
- arch: armhf
target: armv7-unknown-linux-gnueabihf
gcc: arm-linux-gnueabihf
pkgconfig: arm-linux-gnueabihf
- arch: arm64
target: aarch64-unknown-linux-gnu
gcc: aarch64-linux-gnu
pkgconfig: aarch64-linux-gnu
- arch: i386
target: i686-unknown-linux-gnu
gcc: i686-linux-gnu
# on i686, the pkgconfig path doesn't match the prefix!
pkgconfig: i386-linux-gnu
steps:
- uses: actions/checkout@v4
- name: Install basic tools
run: |
apt-get update
apt-get install --assume-yes --no-install-recommends curl ca-certificates protobuf-compiler
- name: Install ${{ matrix.arch }} cross compiler and gstreamer
id: setup
run: |
dpkg --add-architecture ${{ matrix.arch }}
apt-get update
apt-get install --assume-yes --no-install-recommends \
build-essential \
gcc-${{ matrix.gcc }} \
g++-${{ matrix.gcc }} \
libgstrtspserver-1.0-dev:${{ matrix.arch }} \
libgstreamer1.0-dev:${{ matrix.arch }} \
libgtk2.0-dev:${{ matrix.arch }} \
libglib2.0-dev:${{ matrix.arch }} \
libssl-dev:${{ matrix.arch }}
- name: Install rustup
run: |
curl https://sh.rustup.rs -sSf | sh -s -- --no-modify-path --quiet -y
echo "${HOME}/.cargo/bin" >> "${GITHUB_PATH}"
- name: Install ${{ matrix.arch }} Rust toolchain
run: |
rustup target add ${TARGET}
env:
TARGET: ${{ matrix.target }}
- name: Build
run: |
cargo build --release --verbose --all-features --target=${TARGET}
env:
# Retarget pkg-config as described in https://www.freedesktop.org/wiki/Software/pkg-config/CrossCompileProposal/
PKG_CONFIG_ALLOW_CROSS: 1
PKG_CONFIG_LIBDIR: /usr/lib/${{ matrix.pkgconfig }}/pkgconfig
TARGET: ${{ matrix.target }}
JEMALLOC_SYS_WITH_LG_PAGE: 16
- uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.arch }}-bookworm
path: "target/${{ matrix.target }}/release/neolink*"
push_to_registry:
name: Build Docker image
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
runs-on: ubuntu-latest
needs:
- "cross"
steps:
- name: Check token is set
id: vars
shell: bash
run: |
unset HAS_SECRET
if [ -n $SECRET ]; then HAS_SECRET='true' ; fi
echo "HAS_SECRET_TOKEN=${HAS_SECRET}" >> $GITHUB_OUTPUT
env:
SECRET: "${{ secrets.DOCKER_TOKEN }}"
- name: Check out the repo
uses: actions/checkout@v4
if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }}
- name: Convert username to lower case for docker
id: string_user
uses: ASzc/change-string-case-action@v6
with:
string: ${{ github.repository_owner }}
- name: Convert repo to lower case for docker
id: string_repo
uses: ASzc/change-string-case-action@v6
with:
string: ${{ github.repository }}
- name: Set up QEMU
if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }}
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }}
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }}
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ vars.DOCKER_USERNAME || steps.string_user.outputs.lowercase }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set Docker name with owner (package name) depending on if DOCKER_USERNAME is set
if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }}
id: docker_repo
shell: bash
run: |
if [ -z $DOCKER_USERNAME ]; then
echo "DOCKER_NWO=${GITHUB_NWO}" >> $GITHUB_OUTPUT
else
IFS='/' read -ra NWO_SPLIT <<< "$GITHUB_NWO"
REPO_NAME=${NWO_SPLIT[1]}
echo "DOCKER_NWO=${DOCKER_USERNAME}/${REPO_NAME}" >> $GITHUB_OUTPUT
fi
env:
DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }}
GITHUB_NWO: ${{ steps.string_repo.outputs.lowercase }}
- name: Get tag name
if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }}
id: tags
shell: bash
run: |
tags=( )
gittag="$(git tag --points-at HEAD)"
branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ -n "${gittag}" ]]; then
tags=( "${tags[@]}" "${REPO_NAME}:${gittag}" )
fi
if [[ -n "${branch}" ]]; then
branch="$(echo "${branch}" | sed -E 's|[/]|-|g')"
tags=( "${tags[@]}" "${REPO_NAME}:${branch}" )
if [ "${branch}" == "master" ]; then
tags=( "${tags[@]}" "${tags},${REPO_NAME}:latest" )
fi
fi
function join_by {
local d=${1-} f=${2-}
if shift 2; then
printf %s "$f" "${@/#/$d}"
fi
}
tagstr="$(join_by "," "${tags[@]}")"
echo "TAGS=${tagstr}"
echo "TAGS=${tagstr}" >> "${GITHUB_OUTPUT}"
env:
REPO_NAME: ${{ steps.docker_repo.outputs.DOCKER_NWO }}
- name: Install latest rust
run: |
rustup toolchain install stable
- name: Install toml-cli
run: |
cargo install toml-cli
- name: Get project version
id: toml
run: |
NEOLINK_VERSION="$(toml get Cargo.toml package.version | sed 's|"||g')"
echo "version=${NEOLINK_VERSION}" >> $GITHUB_OUTPUT
- name: Prepare directory
run: |
mkdir linux
mkdir linux/arm
mkdir linux/arm64
- name: Download Linux x86_64
uses: actions/download-artifact@v4
with:
name: release-amd64-bookworm
path: linux/amd64
- name: Download Linux armv7
uses: actions/download-artifact@v4
with:
name: release-armhf-bookworm
path: linux/arm/v7
- name: Download Linux arm64
uses: actions/download-artifact@v4
with:
name: release-arm64-bookworm
path: linux/arm64
- name: Download Linux i386
uses: actions/download-artifact@v4
with:
name: release-i386-bookworm
path: linux/386
- name: Push to Docker Hub
if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }}
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/386
context: .
push: true
file: Dockerfile
tags: ${{ steps.tags.outputs.TAGS }}
build-args: VERSION=${{ steps.toml.outputs.version }}, REPO=${{ github.repository }}, OWNER=${{ vars.DOCKER_USERNAME || github.repository_owner }}
env:
DOCKER_BUILDKIT: 1
create_release:
name: Create Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push' # Ensure this only runs on a tag or expect issues
needs:
- "cross"
- "native"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install latest rust
run: |
rustup toolchain install stable
- name: Install toml-cli
run: |
cargo install toml-cli
- name: Get project version
id: toml
run: |
NEOLINK_VERSION="$(toml get Cargo.toml package.version | sed 's|"||g')"
echo "version=${NEOLINK_VERSION}" >> $GITHUB_OUTPUT
- name: Download Windows
uses: actions/download-artifact@v4
with:
name: release-windows-2022
path: neolink_windows
- name: Download Macos
uses: actions/download-artifact@v4
with:
name: release-macos-12
path: neolink_macos_intel
- name: Download Macos arm64
uses: actions/download-artifact@v4
with:
name: release-macos-14
path: neolink_macos_m1
- name: Download Linux x86_64
uses: actions/download-artifact@v4
with:
name: release-ubuntu-22.04
path: neolink_linux_x86_64_ubuntu
- name: Download Linux x86_64
uses: actions/download-artifact@v4
with:
name: release-amd64-bookworm
path: neolink_linux_x86_64_bookworm
- name: Download Linux armhf
uses: actions/download-artifact@v4
with:
name: release-armhf-bookworm
path: neolink_linux_armhf
- name: Download Linux arm64
uses: actions/download-artifact@v4
with:
name: release-arm64-bookworm
path: neolink_linux_arm64
- name: Download Linux i386
uses: actions/download-artifact@v4
with:
name: release-i386-bookworm
path: neolink_linux_i386
- name: Prepare releases
run: |
dirs=(
neolink_windows
neolink_macos_intel
neolink_macos_m1
neolink_linux_x86_64_ubuntu
neolink_linux_x86_64_bookworm
neolink_linux_armhf
neolink_linux_arm64
neolink_linux_i386
)
for d in "${dirs[@]}"; do
chmod +x "${d}/neolink"*
zip -r "${d}.zip" "${d}"
done
- name: release
uses: softprops/action-gh-release@v1
with:
name: Neolink ${{steps.toml.outputs.version}}
files: |
neolink_windows.zip
neolink_macos_intel.zip
neolink_macos_m1.zip
neolink_linux_x86_64_ubuntu.zip
neolink_linux_x86_64_bookworm.zip
neolink_linux_armhf.zip
neolink_linux_arm64.zip
neolink_linux_i386.zip
body: |
Neolink release ${{steps.toml.outputs.version}}
draft: true
prerelease: ${{ contains(github.ref_name, 'rc') }}