diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml index d103f464..1caf57f3 100644 --- a/.github/workflows/check-pr.yml +++ b/.github/workflows/check-pr.yml @@ -37,6 +37,45 @@ jobs: repository: rdkcentral/firebolt-apis event-type: trigger-workflow client-payload: '{"OPENRPC_PR_BRANCH": "${{ github.event.pull_request.head.ref }}"}' + - name: Get JS Workflow Run ID + run: | + TOKEN="${{ secrets.WORKFLOW_TRIGGER_SECRET }}" + REPO_OWNER="rdkcentral" + REPO_NAME="firebolt-apis" + WORKFLOW_NAME="MFOS standalone sanity report - CORE,MANAGE,DISCOVERY" + + # Get workflow ID + js_workflow_id=$(curl -s -H "Authorization: token $TOKEN" \ + "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/workflows" | jq \ + --arg WORKFLOW_NAME "$WORKFLOW_NAME" '.workflows[] | select(.name == $WORKFLOW_NAME).id') + + # Capture the specific run ID for the workflow just triggered + js_run_id=$(curl -s -H "Authorization: token $TOKEN" \ + "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/workflows/$js_workflow_id/runs?per_page=1" | \ + jq -r '.workflow_runs[0].id') + + echo "JS_RUN_ID=$js_run_id" >> $GITHUB_ENV + + - name: Get CPP Workflow Run ID + run: | + TOKEN="${{ secrets.WORKFLOW_TRIGGER_SECRET }}" + REPO_OWNER="rdkcentral" + REPO_NAME="firebolt-apis" + WORKFLOW_NAME="CXX build" + + # Fetch workflow ID + cpp_workflow_id=$(curl -s -H "Authorization: token $TOKEN" \ + "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/workflows" | jq \ + --arg WORKFLOW_NAME "$WORKFLOW_NAME" '.workflows[] | select(.name == $WORKFLOW_NAME).id') + + # Fetch the specific run ID for the workflow triggered by this workflow + cpp_run_id=$(curl -s -H "Authorization: token $TOKEN" \ + "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/workflows/$cpp_workflow_id/runs?per_page=1" | \ + jq -r '.workflow_runs[0].id') + + echo "CPP_RUN_ID=$cpp_run_id" >> $GITHUB_ENV + + wait-for-sdk-generation: needs: release runs-on: ubuntu-latest @@ -47,34 +86,17 @@ jobs: TOKEN="${{ secrets.WORKFLOW_TRIGGER_SECRET }}" REPO_OWNER="rdkcentral" REPO_NAME="firebolt-apis" - WORKFLOW_NAME="MFOS standalone sanity report - CORE,MANAGE,DISCOVERY" + RUN_ID="${{ env.JS_RUN_ID }}" MAX_POLLS=30 # Max polls before timeout POLL_INTERVAL=50 # In seconds - # Fetch the workflow ID once - response=$(curl -s -H "Authorization: token $TOKEN" \ - "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/workflows" | jq \ - --arg WORKFLOW_NAME "$WORKFLOW_NAME" \ - '.workflows[] | select(.name == $WORKFLOW_NAME)') - - workflow_id=$(echo $response | jq -r '.id') - if [ "$workflow_id" == "null" ]; then - echo "Workflow not found." - sleep 10 - continue - fi - - # Start polling for the workflow run + # Poll the specific run ID for status for ((i=0; i> $GITHUB_ENV + status=$(echo $run_response | jq -r '.status') + conclusion=$(echo $run_response | jq -r '.conclusion') if [ "$status" == "completed" ] && [ "$conclusion" == "success" ]; then echo "JavaScript SDK generated successfully for the OpenRPC changes." @@ -88,68 +110,46 @@ jobs: fi done - # Final check after loop if [ "$i" -eq "$MAX_POLLS" ]; then echo "Timeout reached while waiting for JavaScript SDK generation." exit 1 - else - echo "Polling completed successfully." fi + - name: Poll Firebolt-api for CPP SDK generation id: poll-cpp-sdk run: | TOKEN="${{ secrets.WORKFLOW_TRIGGER_SECRET }}" REPO_OWNER="rdkcentral" REPO_NAME="firebolt-apis" - PR_NUMBER="${{ github.event.pull_request.number }}" - WORKFLOW_NAME="CXX build" + RUN_ID="${{ env.CPP_RUN_ID }}" MAX_POLLS=30 # Max polls before timeout POLL_INTERVAL=50 # In seconds - PR_NUMBER="${{ github.event.pull_request.number }}" - # Fetch the workflow ID once - response=$(curl -s -H "Authorization: token $TOKEN" \ - "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/workflows" | jq \ - --arg WORKFLOW_NAME "$WORKFLOW_NAME" \ - '.workflows[] | select(.name == $WORKFLOW_NAME)') - - workflow_id=$(echo $response | jq -r '.id') - if [ "$workflow_id" == "null" ]; then - echo "Workflow not found." - sleep 10 - continue - fi - # Start polling for the workflow run + # Poll the specific run ID for status for ((i=0; i> $GITHUB_ENV + "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runs/$RUN_ID") + + status=$(echo $run_response | jq -r '.status') + conclusion=$(echo $run_response | jq -r '.conclusion') if [ "$status" == "completed" ] && [ "$conclusion" == "success" ]; then - echo "C++ SDK generated successfully for the OpenRPC changes." + echo "JavaScript SDK generated successfully for the OpenRPC changes." break elif [ "$status" == "completed" ] && [ "$conclusion" == "failure" ]; then - echo "Failed to generate C++ SDK for the OpenRPC changes." + echo "Failed to generate JavaScript SDK for the OpenRPC changes." else echo "Still in progress. Checking again in ${POLL_INTERVAL} seconds..." sleep $POLL_INTERVAL fi done - # Final check after loop if [ "$i" -eq "$MAX_POLLS" ]; then - echo "Timeout reached while waiting for C++ SDK generation." + echo "Timeout reached while waiting for JavaScript SDK generation." exit 1 - else - echo "Polling completed successfully." fi + - name: Post comments on PR if: env.JS_SDK_CONCLUSION != 'unknown' || env.CPP_SDK_CONCLUSION != 'unknown' # Only run if at least one SDK ran run: |