尝试集成CI/CD进行测试 #20
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: | |
| unit-tests: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: maven | |
| - name: Run Maven Tests | |
| run: | | |
| set -euo pipefail | |
| mvn -B -ntp clean test | |
| - name: Upload Surefire Reports | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: surefire-reports | |
| path: | | |
| **/target/surefire-reports/*.txt | |
| **/target/surefire-reports/*.xml | |
| go-client-check: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go_client/go.mod | |
| cache-dependency-path: go_client/go.sum | |
| - name: Verify Go Client Build | |
| working-directory: go_client | |
| run: | | |
| set -euo pipefail | |
| go mod download | |
| go test ./... | |
| go build -o /tmp/go-rpc-client main.go | |
| integration-test: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| needs: [unit-tests, go-client-check] | |
| 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@v5 | |
| with: | |
| python-version: '3.x' | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go_client/go.mod | |
| cache-dependency-path: go_client/go.sum | |
| - name: Install Python Dependencies | |
| run: | | |
| set -euo pipefail | |
| python -m pip install --upgrade pip | |
| pip install grpcio grpcio-tools protobuf | |
| - name: Build Jars For Integration Test | |
| run: | | |
| set -euo pipefail | |
| mvn -B -ntp -DskipTests clean package | |
| - name: Start RPC Provider (Java Server) | |
| run: | | |
| set -euo pipefail | |
| # Build classpath including project jars and dependencies | |
| CLASSPATH="rpc-provider/target/rpc-provider-1.0-SNAPSHOT.jar:rpc-transport-netty/target/rpc-transport-netty-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: | | |
| set -euo pipefail | |
| echo "Running Python Client..." | |
| python client.py | tee ../python-client.log | |
| grep -q "Message: Success" ../python-client.log | |
| - name: Run Go Client | |
| working-directory: go_client | |
| run: | | |
| set -euo pipefail | |
| echo "Running Go Client..." | |
| go run main.go | tee ../go-client.log | |
| grep -q "Message: Success" ../go-client.log | |
| - name: Upload CI Logs | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ci-logs | |
| path: | | |
| server.log | |
| python-client.log | |
| go-client.log |