尝试集成CI/CD进行测试 #2
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: Java CI with Maven, Nacos, and Python | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| integration-test: | |
| runs-on: ubuntu-latest | |
| services: | |
| nacos: | |
| image: nacos/nacos-server:v2.2.3 | |
| env: | |
| MODE: standalone | |
| AUTH_ENABLE: false | |
| ports: | |
| - 8848:8848 | |
| # Wait for Nacos to be fully ready | |
| options: >- | |
| --name nacos-server | |
| --health-cmd "curl -f http://localhost:8848/nacos/v1/console/health/readiness" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 10 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: maven | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.x' | |
| - name: Install Python Dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install grpcio grpcio-tools protobuf | |
| - name: Build with Maven | |
| run: mvn clean install -DskipTests | |
| - name: Start RPC Provider (Java Server) | |
| run: | | |
| # Build classpath including project jars and dependencies | |
| CLASSPATH="rpc-provider/target/rpc-provider-1.0-SNAPSHOT.jar:rpc-core/target/rpc-core-1.0-SNAPSHOT.jar:rpc-common/target/rpc-common-1.0-SNAPSHOT.jar:rpc-api/target/rpc-api-1.0-SNAPSHOT.jar:$(mvn -q dependency:build-classpath -Dmdep.outputFile=/dev/stdout -pl rpc-provider -am)" | |
| echo "Starting Java Server..." | |
| # Run in background with nohup | |
| nohup java -cp "$CLASSPATH" com.xiaoyu.rpc.provider.ProviderApp > server.log 2>&1 & | |
| # Wait for server port 8080 to be available | |
| echo "Waiting for Java Server to start on port 8080..." | |
| timeout 60s bash -c 'until echo > /dev/tcp/localhost/8080; do sleep 1; done' | |
| echo "Java Server is running!" | |
| # Optional: Print initial logs | |
| head -n 20 server.log | |
| - name: Run Python Client | |
| working-directory: python_client | |
| run: | | |
| echo "Running Python Client..." | |
| python client.py |