1+ name : PR Validation
2+
3+ on :
4+ pull_request :
5+ branches : [ main ]
6+
7+ jobs :
8+ test :
9+ name : Run Tests
10+ runs-on : ubuntu-latest
11+
12+ steps :
13+ - name : Checkout code
14+ uses : actions/checkout@v4
15+
16+ - name : Set up Go
17+ uses : actions/setup-go@v5
18+ with :
19+ go-version : ' 1.24'
20+
21+ - name : Run tests
22+ run : |
23+ echo "Running Go tests..."
24+ go test -v -json ./... > test-results.json
25+
26+ - name : Report test results
27+ uses : dorny/test-reporter@v1
28+ if : always()
29+ with :
30+ name : Go Tests
31+ path : test-results.json
32+ reporter : golang-json
33+ fail-on-error : true
34+
35+ integration-test :
36+ name : Integration Test (${{ matrix.resolution }})
37+ runs-on : ubuntu-latest
38+ needs : test
39+ if : needs.test.result == 'success'
40+
41+ strategy :
42+ matrix :
43+ resolution : [720p, 1080p, 2k]
44+ include :
45+ - resolution : 720p
46+ expected_height : 720
47+ expected_width : 1280
48+ - resolution : 1080p
49+ expected_height : 1080
50+ expected_width : 1920
51+ - resolution : 2k
52+ expected_height : 1440
53+ expected_width : 2560
54+
55+ services :
56+ rtmp-server :
57+ image : tiangolo/nginx-rtmp
58+ ports :
59+ - 1935:1935
60+
61+ steps :
62+ - name : Checkout code
63+ uses : actions/checkout@v4
64+
65+ - name : Set up Docker Buildx
66+ uses : docker/setup-buildx-action@v3
67+
68+ - name : Build Docker image
69+ uses : docker/build-push-action@v5
70+ with :
71+ context : .
72+ push : false
73+ tags : stream-webpage:test
74+ load : true
75+
76+ - name : Start stream-webpage container
77+ run : |
78+ docker run -d \
79+ --name stream-webpage \
80+ --network host \
81+ -e FRAMERATE=60 \
82+ -e LOG_FORMAT=json \
83+ -e LOG_LEVEL=debug \
84+ -e PORT=8080 \
85+ -e RESOLUTION=${{ matrix.resolution }} \
86+ -e RTMP_URL=rtmp://localhost:1935/live/stream \
87+ -e WEBPAGE_URL="https://www.youtube.com/embed/xuCn8ux2gbs?autoplay=1&loop=1&playlist=xuCn8ux2gbs" \
88+ stream-webpage:test
89+
90+ - name : Setup FFmpeg
91+ uses : FedericoCarboni/setup-ffmpeg@v3
92+
93+ - name : Wait for services to start
94+ run : |
95+ echo "Waiting for services to start..."
96+ sleep 30
97+
98+ - name : Test RTMP stream
99+ run : |
100+ echo "Testing RTMP stream..."
101+
102+ # Test if RTMP server is accessible and stream is available
103+ timeout 30 bash -c '
104+ while ! nc -z localhost 1935; do
105+ echo "Waiting for RTMP server..."
106+ sleep 2
107+ done
108+ echo "RTMP server is ready"
109+ '
110+
111+ # Use ffprobe to check stream properties
112+ echo "Checking stream properties with ffprobe..."
113+ timeout 30 ffprobe -v quiet -print_format json -show_streams rtmp://localhost:1935/live/stream > stream_info.json 2>/dev/null || {
114+ echo "Stream not available yet, checking container logs..."
115+ docker logs $(docker ps -q --filter ancestor=stream-webpage:test)
116+ docker logs $(docker ps -q --filter ancestor=tiangolo/nginx-rtmp)
117+ exit 1
118+ }
119+
120+ # Check if stream matches expected resolution
121+ height=$(cat stream_info.json | jq -r '.streams[0].height // empty')
122+ width=$(cat stream_info.json | jq -r '.streams[0].width // empty')
123+
124+ echo "Stream resolution: ${width}x${height}"
125+ echo "Expected resolution: ${{ matrix.expected_width }}x${{ matrix.expected_height }}"
126+
127+ if [ "$height" = "${{ matrix.expected_height }}" ] && [ "$width" = "${{ matrix.expected_width }}" ]; then
128+ echo "✅ Stream is ${{ matrix.resolution }} as expected"
129+ else
130+ echo "❌ Stream is not ${{ matrix.resolution }}. Expected ${{ matrix.expected_width }}x${{ matrix.expected_height }}, got ${width}x${height}"
131+ cat stream_info.json | jq '.'
132+ exit 1
133+ fi
134+
135+ echo "✅ Integration test completed successfully"
136+
137+ - name : Cleanup
138+ if : always()
139+ run : |
140+ echo "Stopping stream-webpage container..."
141+ docker stop stream-webpage || true
142+ docker rm stream-webpage || true
0 commit comments