Merge pull request #27 from renvins/feat/cpu-stats #129
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 Build and Infrastructure Check | |
| # Controls when the workflow will run | |
| on: | |
| push: | |
| branches: [master] # Or your default branch (e.g., master) | |
| pull_request: | |
| branches: [master] # Or your default branch | |
| jobs: | |
| # Job to build the plugin and test Docker infrastructure | |
| build-and-test-infra: | |
| runs-on: ubuntu-latest # Use a standard Linux runner with Docker pre-installed | |
| steps: | |
| # 1. Checkout your repository code | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| # 2. Set up JDK (Adjust version as needed for your project) | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' # Or 'adopt', 'zulu', etc. | |
| # 3. Give permission to gradle to execute commands | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| # Setup Gradle - This action handles caching and executing gradle tasks | |
| # It automatically finds and uses ./gradlew | |
| - name: Setup Gradle and Build Plugin Jar | |
| uses: gradle/actions/setup-gradle@v4 # Use v4 or latest stable version | |
| # Build both Bukkit and Velocity JARs | |
| - name: Build JAR files | |
| run: ./gradlew shadowJar | |
| - name: Build Fabric JAR | |
| run: ./gradlew fabric:build | |
| # Upload Bukkit JAR as an artifact | |
| - name: Upload Bukkit JAR Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: serverpulse-bukkit-jar | |
| path: bukkit/build/libs/*.jar | |
| retention-days: 14 # Keep artifacts for 14 days | |
| if-no-files-found: error # Fail the workflow if no JARs are found | |
| # Upload Velocity JAR as an artifact | |
| - name: Upload Velocity JAR Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: serverpulse-velocity-jar | |
| path: velocity/build/libs/*.jar | |
| retention-days: 14 # Keep artifacts for 14 days | |
| if-no-files-found: error # Fail the workflow if no JARs are found | |
| # Upload Fabric JAR as an artifact | |
| - name: Upload Fabric JAR Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: serverpulse-fabric-jar | |
| path: fabric/build/libs/serverpulse-*.jar | |
| retention-days: 14 # Keep artifacts for 14 days | |
| if-no-files-found: error # Fail the workflow if no JARs are found | |
| # Upload BungeeCord JAR as an artifact | |
| - name: Upload BungeeCord JAR Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: serverpulse-bungeecord-jar | |
| path: bungeecord/build/libs/serverpulse-*.jar | |
| retention-days: 14 | |
| if-no-files-found: error # Fail the workflow if no JARs are found | |
| # --- Infrastructure Testing --- | |
| # 4. Install jq (needed for parsing InfluxDB health check JSON) | |
| - name: Install jq | |
| run: sudo apt-get update && sudo apt-get install -y jq | |
| # 5. Start Docker Compose services in detached mode | |
| - name: Start Docker Infrastructure | |
| run: docker compose -f infra/docker-compose.yml up -d | |
| # 6. Wait for services to be healthy | |
| # This is crucial. Services take time to initialize. | |
| - name: Wait for InfluxDB Health | |
| run: | | |
| echo "Waiting for InfluxDB..." | |
| # Timeout after 90 seconds. Ping /health endpoint. Check status is "pass". | |
| timeout 90s bash -c ' \ | |
| until curl -sf http://localhost:8086/health | jq -e ".status == \"pass\""; do \ | |
| echo "InfluxDB not ready yet..."; \ | |
| sleep 5; \ | |
| done \ | |
| ' | |
| echo "InfluxDB is ready." | |
| - name: Wait for Grafana Health | |
| run: | | |
| echo "Waiting for Grafana..." | |
| # Timeout after 60 seconds. Ping /api/health endpoint. Exit code 0 means success. | |
| timeout 60s bash -c ' \ | |
| until curl -sf http://localhost:3000/api/health; do \ | |
| echo "Grafana not ready yet..."; \ | |
| sleep 5; \ | |
| done \ | |
| ' | |
| echo "Grafana is ready." | |
| # 7. Stop and remove Docker Compose services | |
| # The 'if: always()' ensures this runs even if previous steps failed, cleaning up the runner. | |
| - name: Stop Docker Infrastructure | |
| if: always() | |
| run: | | |
| echo "Stopping Docker containers..." | |
| docker compose -f infra/docker-compose.yml down -v # -v removes volumes too |