Skip to content

fix: Added a new job to trigger Firebolt api workflow #514

fix: Added a new job to trigger Firebolt api workflow

fix: Added a new job to trigger Firebolt api workflow #514

Workflow file for this run

name: Check Pull Request
on:
workflow_dispatch:
pull_request:
types:
- 'ready_for_review'
- 'opened'
- 'reopened'
- 'synchronize'
push:
branches:
- next
env:
HUSKY: 0
jobs:
release:
name: Trigger Workflows
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 'lts/*'
- name: Install dependencies
run: npm ci
- name: Run validation and tests
run: npm pack
- name: Trigger Workflows
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.WORKFLOW_TRIGGER_SECRET }} # or use a custom token with proper permissions
repository: rdkcentral/firebolt-apis
event-type: trigger-workflow
client-payload: '{"OPENRPC_PR_BRANCH": "${{ github.event.pull_request.head.ref }}"}'
- name: Store the workflow run ID
run: |
echo "Waiting for Repo2 to finish execution"
wait-for-sdk-generation:
needs: release
runs-on: ubuntu-latest
steps:
- name: Poll Firebolt-api for JavaScript SDK generation
id: poll-javascript-sdk
run: |
TOKEN="${{ secrets.WORKFLOW_TRIGGER_SECRET }}"
REPO_OWNER="rdkcentral"
REPO_NAME="firebolt-apis"
WORKFLOW_NAME="MFOS standalone sanity report - CORE,MANAGE,DISCOVERY"
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
for ((i=0; i<MAX_POLLS; i++)); do
# Use the same response to get the latest run
run_response=$(curl -s -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/workflows/$workflow_id/runs?per_page=1")
status=$(echo $run_response | jq -r '.workflow_runs[0].status')
conclusion=$(echo $run_response | jq -r '.workflow_runs[0].conclusion')
# Store conclusion if available
echo "JS_SDK_CONCLUSION=$conclusion" >> $GITHUB_ENV
if [ "$status" == "completed" ] && [ "$conclusion" == "success" ]; then
echo "JavaScript SDK generated successfully for the OpenRPC changes."
break
elif [ "$status" == "completed" ] && [ "$conclusion" == "failure" ]; then
echo "Failed to generate JavaScript SDK for the OpenRPC changes."
exit 1
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 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"
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
for ((i=0; i<MAX_POLLS; i++)); do
# Use the same response to get the latest run
run_response=$(curl -s -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/workflows/$workflow_id/runs?per_page=1")
status=$(echo $run_response | jq -r '.workflow_runs[0].status')
conclusion=$(echo $run_response | jq -r '.workflow_runs[0].conclusion
# Store conclusion if available
echo "CPP_SDK_CONCLUSION=$conclusion" >> $GITHUB_ENV
if [ "$status" == "completed" ] && [ "$conclusion" == "success" ]; then
echo "C++ SDK generated successfully for the OpenRPC changes."
break
elif [ "$status" == "completed" ] && [ "$conclusion" == "failure" ]; then
echo "Failed to generate C++ 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."
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: |
TOKEN="${{ secrets.WORKFLOW_TRIGGER_SECRET }}"
REPO_OWNER="${{ github.repository_owner }}"
REPO_NAME="${{ github.event.repository.name }}"
PR_NUMBER="${{ github.event.pull_request.number }}"
# Construct comment body based on conclusions
COMMENT_BODY=""
# JavaScript SDK status
if [[ "$JS_SDK_CONCLUSION" == "success" ]]; then
COMMENT_BODY+="JavaScript SDK generation succeeded for the OpenRPC changes.\\n"
elif [[ "$JS_SDK_CONCLUSION" == "failure" ]]; then
COMMENT_BODY+="JavaScript SDK generation failed for the OpenRPC changes.\\n"
fi
# C++ SDK status
if [[ "$CPP_SDK_CONCLUSION" == "success" ]]; then
COMMENT_BODY+="C++ SDK generation succeeded for the OpenRPC changes."
elif [[ "$CPP_SDK_CONCLUSION" == "failure" ]]; then
COMMENT_BODY+="C++ SDK generation failed for the OpenRPC changes."
fi
# Check if comment body is not empty before posting
if [ -n "$COMMENT_BODY" ]; then
curl -s -H "Authorization: token $TOKEN" \
-X POST \
-d "{\"body\": \"$COMMENT_BODY\"}" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/issues/$PR_NUMBER/comments"
else
echo "No SDKs were generated, no comment will be posted."
fi