added cleanup in unit-test #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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 | |
docker rmi ${{ github.run_id }} |