-
Notifications
You must be signed in to change notification settings - Fork 47
80 lines (68 loc) · 2.5 KB
/
unit-test.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
---
name: Unit-test
on:
push:
branches:
- develop # Run tests on commit to the develop branch
- master # Run tests on commit to the master branch
pull_request: # Run tests on all pull requests
workflow_call: # Allow this workflow to be called by other workflows
concurrency:
group: '${{ github.workflow }} @ ${{ github.ref }}'
cancel-in-progress: true
jobs:
unit-test-amd64:
name: Docker - Test Linux-amd64 image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and export to Docker
uses: docker/build-push-action@v6
with:
file: ./Dockerfile
load: true
tags: ${{ github.run_id }}
platforms: linux/amd64
- name: Run server
run: |
docker run -d \
--name the-forest-dedicated-server \
-p 8766:8766/udp \
-p 27015:27015/udp \
-p 27016:27016/udp \
-v ./game:/theforest/ \
--env SERVER_STEAM_ACCOUNT_TOKEN=${{ secrets.SERVER_STEAM_ACCOUNT_TOKEN }} \
--restart unless-stopped \
--stop-timeout 30 \
${{ github.run_id }}
- name: Wait for server to start
run: |
TIMEOUT_SECONDS=240
START_TIME=$(date +%s)
# Set the timezone to Germany (Central European Time)
export TZ=Europe/Berlin
while ! docker logs the-forest-dedicated-server 2>&1 | grep -q "Game autosave started"; do
CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
if [ $ELAPSED_TIME -gt $TIMEOUT_SECONDS ]; then
echo "Timeout reached. Server failed to start within $TIMEOUT_SECONDS seconds."
printf "\e[0;32m%s\e[0m\n" "*****Container LOGS*****"
docker logs the-forest-dedicated-server
exit 1
fi
echo "$(date '+%H:%M:%S') - Waiting for server to start..."
sleep 5
done
- name: Test if port 8766, 27015 and 27016 are listening
run: |
nc -z -u -v 127.0.0.1 8766 || exit 2
nc -z -u -v 127.0.0.1 27015 || exit 3
nc -z -u -v 127.0.0.1 27016 || exit 4
- name: Stop server
if: always()
run: |
docker stop the-forest-dedicated-server
docker rm the-forest-dedicated-server