Skip to content

Commit c76b85a

Browse files
committed
Extract macOS RTSP test action
1 parent 962b361 commit c76b85a

3 files changed

Lines changed: 94 additions & 51 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Test RTSP capture on macOS
2+
description: Run the OpenCvSharp RTSP integration test against a temporary MediaMTX server
3+
4+
inputs:
5+
mediamtx-version:
6+
description: MediaMTX release version
7+
required: true
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- name: Run RTSP integration test
13+
shell: bash
14+
run: bash "${{ github.action_path }}/test-rtsp.sh" "${{ inputs.mediamtx-version }}"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
readonly mediamtx_version="$1"
5+
readonly archive_name="mediamtx_v${mediamtx_version}_darwin_arm64.tar.gz"
6+
readonly download_base="https://github.com/bluenviron/mediamtx/releases/download/v${mediamtx_version}"
7+
readonly server_dir="${RUNNER_TEMP}/mediamtx"
8+
readonly archive_path="${RUNNER_TEMP}/${archive_name}"
9+
readonly checksums_path="${RUNNER_TEMP}/mediamtx-checksums.sha256"
10+
readonly log_path="${RUNNER_TEMP}/mediamtx.log"
11+
server_pid=""
12+
13+
cleanup() {
14+
local status=$?
15+
trap - EXIT
16+
17+
if [[ "${status}" -ne 0 && -f "${log_path}" ]]; then
18+
cat "${log_path}"
19+
fi
20+
if [[ -n "${server_pid}" ]] && kill -0 "${server_pid}" 2>/dev/null; then
21+
kill "${server_pid}" 2>/dev/null || true
22+
wait "${server_pid}" 2>/dev/null || true
23+
fi
24+
25+
exit "${status}"
26+
}
27+
trap cleanup EXIT
28+
29+
curl -fL --retry 5 "${download_base}/${archive_name}" -o "${archive_path}"
30+
curl -fL --retry 5 "${download_base}/checksums.sha256" -o "${checksums_path}"
31+
32+
expected_checksum="$(grep -E "[ *]${archive_name}$" "${checksums_path}" | awk '{print $1}')"
33+
if [[ -z "${expected_checksum}" ]]; then
34+
echo "Checksum not found for ${archive_name}"
35+
exit 1
36+
fi
37+
38+
actual_checksum="$(shasum -a 256 "${archive_path}" | awk '{print $1}')"
39+
if [[ "${actual_checksum}" != "${expected_checksum}" ]]; then
40+
echo "Checksum mismatch for ${archive_name}: expected ${expected_checksum}, got ${actual_checksum}"
41+
exit 1
42+
fi
43+
44+
mkdir -p "${server_dir}"
45+
tar -xzf "${archive_path}" -C "${server_dir}"
46+
"${server_dir}/mediamtx" "${GITHUB_WORKSPACE}/test/rtsp/mediamtx.yml" >"${log_path}" 2>&1 &
47+
server_pid=$!
48+
49+
ready=false
50+
for attempt in $(seq 1 30); do
51+
if ! kill -0 "${server_pid}" 2>/dev/null; then
52+
echo "MediaMTX exited before the stream became available"
53+
exit 1
54+
fi
55+
if grep -q "stream is available" "${log_path}"; then
56+
ready=true
57+
break
58+
fi
59+
sleep 1
60+
done
61+
62+
if [[ "${ready}" != true ]]; then
63+
echo "Timed out waiting for MediaMTX"
64+
exit 1
65+
fi
66+
67+
export OPENCVSHARP_TEST_RTSP_URL="rtsp://127.0.0.1:8554/test"
68+
export DYLD_LIBRARY_PATH="/usr/local/lib:${GITHUB_WORKSPACE}/test/OpenCvSharp.Tests${DYLD_LIBRARY_PATH:+:${DYLD_LIBRARY_PATH}}"
69+
dotnet test "${GITHUB_WORKSPACE}/test/OpenCvSharp.Tests/OpenCvSharp.Tests.csproj" \
70+
-c Release \
71+
-f net10.0 \
72+
--runtime osx-arm64 \
73+
--no-build \
74+
--no-restore \
75+
--filter "FullyQualifiedName=OpenCvSharp.Tests.VideoIO.VideoCaptureTest.ReadRtspStreamWithFFmpeg" \
76+
< /dev/null

.github/workflows/macos.yml

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -335,51 +335,6 @@ jobs:
335335
with:
336336
dotnet-version: '10.0.x'
337337

338-
- name: Start local RTSP test server
339-
run: |
340-
version="${MEDIAMTX_VERSION}"
341-
archive_name="mediamtx_v${version}_darwin_arm64.tar.gz"
342-
download_base="https://github.com/bluenviron/mediamtx/releases/download/v${version}"
343-
server_dir="${RUNNER_TEMP}/mediamtx"
344-
archive_path="${RUNNER_TEMP}/${archive_name}"
345-
checksums_path="${RUNNER_TEMP}/mediamtx-checksums.sha256"
346-
347-
curl -fL --retry 5 "${download_base}/${archive_name}" -o "${archive_path}"
348-
curl -fL --retry 5 "${download_base}/checksums.sha256" -o "${checksums_path}"
349-
350-
expected_checksum=$(grep -E "[ *]${archive_name}$" "${checksums_path}" | awk '{print $1}')
351-
if [ -z "${expected_checksum}" ]; then
352-
echo "Checksum not found for ${archive_name}"
353-
exit 1
354-
fi
355-
actual_checksum=$(shasum -a 256 "${archive_path}" | awk '{print $1}')
356-
if [ "${actual_checksum}" != "${expected_checksum}" ]; then
357-
echo "Checksum mismatch for ${archive_name}: expected ${expected_checksum}, got ${actual_checksum}"
358-
exit 1
359-
fi
360-
361-
mkdir -p "${server_dir}"
362-
tar -xzf "${archive_path}" -C "${server_dir}"
363-
"${server_dir}/mediamtx" "${GITHUB_WORKSPACE}/test/rtsp/mediamtx.yml" \
364-
>"${RUNNER_TEMP}/mediamtx.log" 2>&1 &
365-
server_pid=$!
366-
367-
for attempt in $(seq 1 30); do
368-
if ! kill -0 "${server_pid}" 2>/dev/null; then
369-
cat "${RUNNER_TEMP}/mediamtx.log"
370-
exit 1
371-
fi
372-
if grep -q "stream is available" "${RUNNER_TEMP}/mediamtx.log"; then
373-
echo "OPENCVSHARP_TEST_RTSP_URL=rtsp://127.0.0.1:8554/test" >> "${GITHUB_ENV}"
374-
echo "OPENCVSHARP_RTSP_SERVER_PID=${server_pid}" >> "${GITHUB_ENV}"
375-
exit 0
376-
fi
377-
sleep 1
378-
done
379-
380-
cat "${RUNNER_TEMP}/mediamtx.log"
381-
exit 1
382-
383338
- name: Test
384339
run: |
385340
cd ${GITHUB_WORKSPACE}/test/OpenCvSharp.Tests
@@ -396,12 +351,10 @@ jobs:
396351
--logger "trx;LogFileName=test-results.trx" \
397352
--blame-crash --blame-crash-dump-type full < /dev/null
398353
399-
- name: Stop local RTSP test server
400-
if: always()
401-
run: |
402-
if [ -n "${OPENCVSHARP_RTSP_SERVER_PID:-}" ]; then
403-
kill "${OPENCVSHARP_RTSP_SERVER_PID}" 2>/dev/null || true
404-
fi
354+
- name: Test RTSP capture
355+
uses: ./.github/actions/test-rtsp-macos
356+
with:
357+
mediamtx-version: ${{ env.MEDIAMTX_VERSION }}
405358

406359
- name: Test Avalonia extensions
407360
run: |

0 commit comments

Comments
 (0)