From 61960975a41da6fada34734973091f30eef3e70c Mon Sep 17 00:00:00 2001 From: Blocka Wan Date: Sun, 11 Feb 2024 07:01:37 +0800 Subject: [PATCH] turn unit test to reusable workflow --- .github/workflows/linting.yml | 171 ------------------------------- .github/workflows/unit-test.yml | 175 ++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+), 171 deletions(-) create mode 100644 .github/workflows/unit-test.yml diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 223cab34e..b84f2f477 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -2,8 +2,6 @@ name: Linting on: # yamllint disable-line rule:truthy pull_request: - push: - branches: [main] run-name: Pull request - ${{ github.event.pull_request.number }} jobs: @@ -60,172 +58,3 @@ jobs: uses: docker/build-push-action@v5 with: push: false - - unit-test-amd64: - name: Docker - Test (amd64) - 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@v5 - with: - load: true - tags: ${{ github.run_id }} - platforms: linux/amd64 - - - name: Run server - run: | - docker run -d \ - --name palworld-server \ - -p 8211:8211/udp \ - -p 27015:27015/udp \ - -p 25575:25575/tcp \ - -v ./palworld:/palworld/ \ - -e PUID=1000 \ - -e PGID=1000 \ - -e PORT=8211 \ - -e PLAYERS=16 \ - -e MULTITHREADING=true \ - -e RCON_ENABLED=true \ - -e RCON_PORT=25575 \ - -e TZ=UTC \ - -e ADMIN_PASSWORD="adminPasswordHere" \ - -e SERVER_PASSWORD="worldofpals" \ - -e COMMUNITY=false \ - -e SERVER_NAME="World of Pals" \ - -e SERVER_DESCRIPTION="palworld-server-docker by Thijs van Loef" \ - --restart unless-stopped \ - --stop-timeout 30 \ - ${{ github.run_id }} - - - name: Wait for server to start - run: | - TIMEOUT_SECONDS=120 - START_TIME=$(date +%s) - - while ! docker logs palworld-server 2>&1 | grep -q "Setting breakpad minidump AppID"; 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." - exit 1 # or handle the failure accordingly - fi - - echo "Waiting for server to start..." - sleep 5 - done - - - name: Test if server is up and running - run: | - sleep 5 - if ! docker exec palworld-server rcon-cli Info | grep -q "Welcome to Pal Server"; then - echo "Server may not have started successfully." - exit 1 - fi - - - name: Test if port 8211, 27015 and 25575 are listening - run: | - nc -z -u -v 127.0.0.1 8211 || exit 1 - nc -z -u -v 127.0.0.1 27015 || exit 1 - nc -z -v 127.0.0.1 25575 || exit 1 - - - name: Test the backup command functions - run: | - docker exec palworld-server backup - if [ ! -f ./palworld/backups/palworld-save-*.tar.gz ]; then - echo "Backup file not found. Backup command may have failed." - exit 1 - fi - - unit-test-arm64: - name: Docker - Test (arm64) - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build and export to Docker - uses: docker/build-push-action@v5 - with: - file: ./Dockerfile.arm64 - load: true - tags: ${{ github.run_id }} - platforms: linux/arm64 - - - name: Run server - run: | - docker run -d \ - --name palworld-server \ - --platform linux/arm64 \ - -p 8211:8211/udp \ - -p 27015:27015/udp \ - -p 25575:25575/tcp \ - -v ./palworld:/palworld/ \ - -e PUID=1000 \ - -e PGID=1000 \ - -e PORT=8211 \ - -e PLAYERS=16 \ - -e MULTITHREADING=true \ - -e RCON_ENABLED=true \ - -e RCON_PORT=25575 \ - -e TZ=UTC \ - -e ADMIN_PASSWORD="adminPasswordHere" \ - -e SERVER_PASSWORD="worldofpals" \ - -e COMMUNITY=false \ - -e SERVER_NAME="World of Pals" \ - -e SERVER_DESCRIPTION="palworld-server-docker by Thijs van Loef" \ - --restart unless-stopped \ - --stop-timeout 30 \ - ${{ github.run_id }} - - - name: Wait for server to start - run: | - TIMEOUT_SECONDS=360 - START_TIME=$(date +%s) - - while ! docker logs palworld-server 2>&1 | grep -q "Setting breakpad minidump AppID"; 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." - exit 1 # or handle the failure accordingly - fi - - echo "Waiting for server to start..." - sleep 5 - done - - - name: Test if server is up and running - run: | - sleep 5 - if ! docker exec palworld-server rcon-cli Info | grep -q "Welcome to Pal Server"; then - echo "Server may not have started successfully." - exit 1 - fi - - - name: Test if port 8211, 27015 and 25575 are listening - run: | - nc -z -u -v 127.0.0.1 8211 || exit 1 - nc -z -u -v 127.0.0.1 27015 || exit 1 - nc -z -v 127.0.0.1 25575 || exit 1 - - - name: Test the backup command functions - run: | - docker exec palworld-server backup - if [ ! -f ./palworld/backups/palworld-save-*.tar.gz ]; then - echo "Backup file not found. Backup command may have failed." - exit 1 - fi diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml new file mode 100644 index 000000000..4b995173f --- /dev/null +++ b/.github/workflows/unit-test.yml @@ -0,0 +1,175 @@ +--- +name: Unit-test +on: # yamllint disable-line rule:truthy + pull_request: + workflow_call: + +jobs: + unit-test-amd64: + name: Docker - Test (amd64) + 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@v5 + with: + load: true + tags: ${{ github.run_id }} + platforms: linux/amd64 + + - name: Run server + run: | + docker run -d \ + --name palworld-server \ + -p 8211:8211/udp \ + -p 27015:27015/udp \ + -p 25575:25575/tcp \ + -v ./palworld:/palworld/ \ + -e PUID=1000 \ + -e PGID=1000 \ + -e PORT=8211 \ + -e PLAYERS=16 \ + -e MULTITHREADING=true \ + -e RCON_ENABLED=true \ + -e RCON_PORT=25575 \ + -e TZ=UTC \ + -e ADMIN_PASSWORD="adminPasswordHere" \ + -e SERVER_PASSWORD="worldofpals" \ + -e COMMUNITY=false \ + -e SERVER_NAME="World of Pals" \ + -e SERVER_DESCRIPTION="palworld-server-docker by Thijs van Loef" \ + --restart unless-stopped \ + --stop-timeout 30 \ + ${{ github.run_id }} + + - name: Wait for server to start + run: | + TIMEOUT_SECONDS=120 + START_TIME=$(date +%s) + + while ! docker logs palworld-server 2>&1 | grep -q "Setting breakpad minidump AppID"; 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." + exit 1 # or handle the failure accordingly + fi + + echo "Waiting for server to start..." + sleep 5 + done + + - name: Test if server is up and running + run: | + sleep 5 + if ! docker exec palworld-server rcon-cli Info | grep -q "Welcome to Pal Server"; then + echo "Server may not have started successfully." + exit 1 + fi + + - name: Test if port 8211, 27015 and 25575 are listening + run: | + nc -z -u -v 127.0.0.1 8211 || exit 1 + nc -z -u -v 127.0.0.1 27015 || exit 1 + nc -z -v 127.0.0.1 25575 || exit 1 + + - name: Test the backup command functions + run: | + docker exec palworld-server backup + if [ ! -f ./palworld/backups/palworld-save-*.tar.gz ]; then + echo "Backup file not found. Backup command may have failed." + exit 1 + fi + + unit-test-arm64: + name: Docker - Test (arm64) + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and export to Docker + uses: docker/build-push-action@v5 + with: + file: ./Dockerfile.arm64 + load: true + tags: ${{ github.run_id }} + platforms: linux/arm64 + + - name: Run server + run: | + docker run -d \ + --name palworld-server \ + --platform linux/arm64 \ + -p 8211:8211/udp \ + -p 27015:27015/udp \ + -p 25575:25575/tcp \ + -v ./palworld:/palworld/ \ + -e PUID=1000 \ + -e PGID=1000 \ + -e PORT=8211 \ + -e PLAYERS=16 \ + -e MULTITHREADING=true \ + -e RCON_ENABLED=true \ + -e RCON_PORT=25575 \ + -e TZ=UTC \ + -e ADMIN_PASSWORD="adminPasswordHere" \ + -e SERVER_PASSWORD="worldofpals" \ + -e COMMUNITY=false \ + -e SERVER_NAME="World of Pals" \ + -e SERVER_DESCRIPTION="palworld-server-docker by Thijs van Loef" \ + --restart unless-stopped \ + --stop-timeout 30 \ + ${{ github.run_id }} + + - name: Wait for server to start + run: | + TIMEOUT_SECONDS=360 + START_TIME=$(date +%s) + + while ! docker logs palworld-server 2>&1 | grep -q "Setting breakpad minidump AppID"; 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." + exit 1 # or handle the failure accordingly + fi + + echo "Waiting for server to start..." + sleep 5 + done + + - name: Test if server is up and running + run: | + sleep 10 + if ! docker exec palworld-server rcon-cli Info | grep -q "Welcome to Pal Server"; then + echo "Server may not have started successfully." + exit 1 + fi + + - name: Test if port 8211, 27015 and 25575 are listening + run: | + nc -z -u -v 127.0.0.1 8211 || exit 1 + nc -z -u -v 127.0.0.1 27015 || exit 1 + nc -z -v 127.0.0.1 25575 || exit 1 + + - name: Test the backup command functions + run: | + docker exec palworld-server backup + if [ ! -f ./palworld/backups/palworld-save-*.tar.gz ]; then + echo "Backup file not found. Backup command may have failed." + exit 1 + fi