Update ci.yml #27
This file contains hidden or 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: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| mc_versions: | |
| description: "Comma-separated Minecraft versions (e.g., 1.21.5,1.20.1)" | |
| required: false | |
| default: "1.21.5,1.20.1" | |
| server_types: | |
| description: "Comma-separated server types (e.g., fabric,paper,forge,vanilla)" | |
| required: false | |
| default: "fabric,paper,forge,vanilla" | |
| jobs: | |
| test-minecraft-servers: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| mc_version: ${{ fromJson(inputs.mc_versions || '["1.21.5","1.20.1"]') }} | |
| server_type: ${{ fromJson(inputs.server_types || '["fabric","paper","forge","vanilla"]') }} | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v3 | |
| - name: Install Dependencies | |
| run: | | |
| sudo apt update | |
| sudo apt install -y openjdk-21-jre-headless curl jq | |
| - name: Setup Minecraft Server | |
| id: setup | |
| run: | | |
| MC_VERSION="${{ matrix.mc_version }}" | |
| SERVER_TYPE="${{ matrix.server_type }}" | |
| INSTALL_DIR="$HOME/minecraft-server-$MC_VERSION-$SERVER_TYPE" | |
| echo "π Fetching server JAR URL for version $MC_VERSION and type $SERVER_TYPE..." | |
| API_RESPONSE=$(curl -s "https://mcutils.com/api/v1/jars?version=$MC_VERSION&type=$SERVER_TYPE") | |
| # Debug: Print the raw API response | |
| echo "API Response: $API_RESPONSE" | |
| # Validate JSON using jq | |
| if echo "$API_RESPONSE" | jq empty 2>/dev/null; then | |
| SERVER_JAR_URL=$(echo "$API_RESPONSE" | jq -r '.url') | |
| # Check if 'url' field exists and is not empty | |
| if [ -z "$SERVER_JAR_URL" ] || [ "$SERVER_JAR_URL" == "null" ]; then | |
| echo "β Error: 'url' field is missing or empty in the API response." | |
| echo "Debug Info: $API_RESPONSE" | |
| exit 1 | |
| fi | |
| else | |
| echo "β Error: Invalid JSON response from API." | |
| echo "Debug Info: $API_RESPONSE" | |
| exit 1 | |
| fi | |
| echo "β Found server JAR URL: $SERVER_JAR_URL" | |
| echo "π Creating server folder at $INSTALL_DIR..." | |
| mkdir -p "$INSTALL_DIR" | |
| cd "$INSTALL_DIR" | |
| echo "β¬οΈ Downloading server JAR..." | |
| curl -L -o "server.jar" "$SERVER_JAR_URL" | |
| echo "β Accepting Minecraft EULA..." | |
| echo "eula=true" > eula.txt | |
| echo "βοΈ Starting Minecraft server for version $MC_VERSION and type $SERVER_TYPE..." | |
| java -Xms1G -Xmx1G -jar server.jar nogui & | |
| SERVER_PID=$! | |
| echo "β³ Waiting for server to start..." | |
| sleep 30 | |
| if ps -p $SERVER_PID > /dev/null; then | |
| echo "β Server for version $MC_VERSION and type $SERVER_TYPE started successfully." | |
| kill $SERVER_PID | |
| wait $SERVER_PID || true | |
| else | |
| echo "β Error: Server for version $MC_VERSION and type $SERVER_TYPE failed to start." | |
| exit 1 | |
| fi | |
| - name: Clean Up Server Files | |
| run: | | |
| echo "π§Ή Cleaning up server files..." | |
| rm -rf "$HOME/minecraft-server-${{ matrix.mc_version }}-${{ matrix.server_type }}" |