series d-p #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: Test gRPC-java on Arm64 | ||
|
Check failure on line 1 in .github/workflows/test-grpc-java.yml
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| - smoke_tests | ||
| paths: | ||
| - 'content/opensource_packages/gRPC-java.md' | ||
| - '.github/workflows/test-gRPC-java.yml' | ||
| jobs: | ||
| test-gRPC-java: | ||
| runs-on: ubuntu-24.04-arm | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| - name: Set test metadata | ||
| id: metadata | ||
| run: | | ||
| echo "timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT | ||
| echo "package_slug=gRPC-java" >> $GITHUB_OUTPUT | ||
| echo "dashboard_link=/opensource_packages/gRPC-java" >> $GITHUB_OUTPUT | ||
| # ============================================================ | ||
| # CUSTOMIZE THIS: Install your package | ||
| # ============================================================ | ||
| - name: Install gRPC-java | ||
| id: install | ||
| run: | | ||
| echo "Installing gRPC-java..." | ||
| # Install using apt-get | ||
| sudo apt-get update | ||
| if sudo apt-get install -y protobuf-compiler-grpc-java-plugin protobuf-compiler default-jdk; then | ||
| echo "gRPC-java plugin installed successfully" | ||
| echo "install_status=success" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "gRPC-java plugin installation failed" | ||
| echo "install_status=failed" >> $GITHUB_OUTPUT | ||
| exit 1 | ||
| fi | ||
| # ============================================================ | ||
| # CUSTOMIZE THIS: Get the package version | ||
| # ============================================================ | ||
| - name: Get gRPC-java version | ||
| id: version | ||
| run: | | ||
| # Get version from dpkg | ||
| VERSION=$(dpkg -s protobuf-compiler-grpc-java-plugin | grep Version | awk '{print $2}' || echo "unknown") | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
| echo "Detected gRPC-java version: $VERSION" | ||
| # ============================================================ | ||
| # ADD YOUR TESTS BELOW | ||
| # Each test should: | ||
| # 1. Have a unique id (test1, test2, etc.) | ||
| # 2. Track start/end time for duration | ||
| # 3. Set status=passed or status=failed | ||
| # 4. Exit 1 on failure | ||
| # ============================================================ | ||
| - name: Test 1 - Check plugin binary exists | ||
| id: test1 | ||
| run: | | ||
| START_TIME=$(date +%s) | ||
| if [ -f "/usr/bin/protoc-gen-grpc-java" ]; then | ||
| echo "✓ protoc-gen-grpc-java found" | ||
| echo "status=passed" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "✗ protoc-gen-grpc-java not found" | ||
| echo "status=failed" >> $GITHUB_OUTPUT | ||
| exit 1 | ||
| fi | ||
| END_TIME=$(date +%s) | ||
| echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT | ||
| - name: Test 2 - Check protoc version | ||
| id: test2 | ||
| run: | | ||
| START_TIME=$(date +%s) | ||
| if protoc --version; then | ||
| echo "✓ protoc version command works" | ||
| echo "status=passed" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "✗ protoc version command failed" | ||
| echo "status=failed" >> $GITHUB_OUTPUT | ||
| exit 1 | ||
| fi | ||
| END_TIME=$(date +%s) | ||
| echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT | ||
| - name: Test 3 - Check plugin execution (help/version) | ||
| id: test3 | ||
| run: | | ||
| START_TIME=$(date +%s) | ||
| # The plugin expects input from stdin, so running it directly might hang or error | ||
| # We check if it's executable | ||
| if [ -x "/usr/bin/protoc-gen-grpc-java" ]; then | ||
| echo "✓ Plugin is executable" | ||
| echo "status=passed" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "✗ Plugin is not executable" | ||
| echo "status=failed" >> $GITHUB_OUTPUT | ||
| exit 1 | ||
| fi | ||
| END_TIME=$(date +%s) | ||
| echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT | ||
| - name: Test 4 - Generate Java code from proto | ||
| id: test4 | ||
| run: | | ||
| START_TIME=$(date +%s) | ||
| # Create a simple proto file | ||
| cat > test.proto << EOF | ||
| syntax = "proto3"; | ||
| package test; | ||
| service Greeter { | ||
| rpc SayHello (HelloRequest) returns (HelloReply) {} | ||
| } | ||
| message HelloRequest { | ||
| string name = 1; | ||
| } | ||
| message HelloReply { | ||
| string message = 1; | ||
| } | ||
| EOF | ||
| # Create output directory | ||
| mkdir -p java_out | ||
| # Run protoc with grpc-java plugin | ||
| if protoc --plugin=protoc-gen-grpc-java=/usr/bin/protoc-gen-grpc-java --grpc-java_out=java_out --java_out=java_out test.proto; then | ||
| echo "✓ Code generation passed" | ||
| find java_out -name "*.java" | ||
| echo "status=passed" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "✗ Code generation failed" | ||
| echo "status=failed" >> $GITHUB_OUTPUT | ||
| exit 1 | ||
| fi | ||
| END_TIME=$(date +%s) | ||
| echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT | ||
| - name: Test 5 - Check generated files | ||
| id: test5 | ||
| run: | | ||
| START_TIME=$(date +%s) | ||
| if find java_out -name "GreeterGrpc.java"; then | ||
| echo "✓ GreeterGrpc.java generated" | ||
| echo "status=passed" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "✗ GreeterGrpc.java not generated" | ||
| echo "status=failed" >> $GITHUB_OUTPUT | ||
| exit 1 | ||
| fi | ||
| # Cleanup | ||
| rm test.proto | ||
| rm -rf java_out | ||
| END_TIME=$(date +%s) | ||
| echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT | ||
| - name: Generate Test Report | ||
| if: always() | ||
| run: | | ||
| # Define the report file path | ||
| REPORT_FILE="test-results.json" | ||
| # Initialize the JSON structure | ||
| echo "{" > $REPORT_FILE | ||
| echo " \"package\": \"${{ steps.metadata.outputs.package_slug }}\"," >> $REPORT_FILE | ||
| echo " \"version\": \"${{ steps.version.outputs.version }}\"," >> $REPORT_FILE | ||
| echo " \"install_status\": \"${{ steps.install.outputs.install_status }}\"," >> $REPORT_FILE | ||
| echo " \"timestamp\": \"${{ steps.metadata.outputs.timestamp }}\"," >> $REPORT_FILE | ||
| echo " \"tests\": [" >> $REPORT_FILE | ||
| # Collect test results | ||
| TESTS=("test1" "test2" "test3" "test4" "test5") | ||
| FIRST=true | ||
| for TEST_ID in "${TESTS[@]}"; do | ||
| STATUS="${{ steps[TEST_ID].outputs.status }}" | ||
| DURATION="${{ steps[TEST_ID].outputs.duration }}" | ||
| # Default to skipped if status is empty | ||
| if [ -z "$STATUS" ]; then STATUS="skipped"; fi | ||
| if [ -z "$DURATION" ]; then DURATION=0; fi | ||
| if [ "$FIRST" = true ]; then | ||
| FIRST=false | ||
| else | ||
| echo "," >> $REPORT_FILE | ||
| fi | ||
| echo " {" >> $REPORT_FILE | ||
| echo " \"id\": \"$TEST_ID\"," >> $REPORT_FILE | ||
| echo " \"status\": \"$STATUS\"," >> $REPORT_FILE | ||
| echo " \"duration\": $DURATION" >> $REPORT_FILE | ||
| echo " }" >> $REPORT_FILE | ||
| done | ||
| echo " ]" >> $REPORT_FILE | ||
| echo "}" >> $REPORT_FILE | ||
| # Pretty print the report | ||
| cat $REPORT_FILE | ||
| - name: Upload Test Results | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: test-results-${{ steps.metadata.outputs.package_slug }} | ||
| path: test-results.json | ||
| - name: Update Test Results in Repository | ||
| if: always() | ||
| run: | | ||
| # Create the results directory if it doesn't exist | ||
| mkdir -p test_results/${{ steps.metadata.outputs.package_slug }} | ||
| # Copy the report file to the results directory | ||
| cp test-results.json test_results/${{ steps.metadata.outputs.package_slug }}/result.json | ||
| # Configure git | ||
| git config --local user.email "action@github.com" | ||
| git config --local user.name "GitHub Action" | ||
| # Add and commit the changes | ||
| git add test_results/${{ steps.metadata.outputs.package_slug }}/result.json | ||
| git commit -m "Update test results for ${{ steps.metadata.outputs.package_slug }}" || echo "No changes to commit" | ||
| # git push is handled by the caller workflow or manually | ||