Skip to content

Feat: Bidirectional openrpc gen #557

Feat: Bidirectional openrpc gen

Feat: Bidirectional openrpc gen #557

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 }}
repository: rdkcentral/firebolt-apis
event-type: trigger-workflow
client-payload: '{"OPENRPC_PR_BRANCH": "${{ github.event.pull_request.head.ref }}"}'
- name: Wait for Triggered Workflow to Initialize
run: |
echo "Waiting for the workflow to initialize..."
sleep 40
- 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"
MAX_RETRIES=20
SLEEP_TIME=15 # seconds
for ((i=0; i<MAX_RETRIES; i++)); do
# Fetch workflows
response=$(curl -s -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/workflows")
# Capture workflow ID
js_workflow_id=$(echo "$response" | jq --arg WORKFLOW_NAME "$WORKFLOW_NAME" '.workflows[] | select(.name == $WORKFLOW_NAME).id')
# Capture the specific run ID for the workflow
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 "JavaScript Workflow Run ID: $js_run_id"
if [ "$js_run_id" != "null" ]; then
echo "JS_RUN_ID=$js_run_id" >> $GITHUB_ENV
break
else
echo "Waiting for JavaScript workflow to start..."
sleep $SLEEP_TIME
fi
done
# Poll until the C++ SDK workflow run is available
- name: Get CPP Workflow Run ID
run: |
TOKEN="${{ secrets.WORKFLOW_TRIGGER_SECRET }}"
REPO_OWNER="rdkcentral"
REPO_NAME="firebolt-apis"
WORKFLOW_NAME="CXX build"
MAX_RETRIES=20
SLEEP_TIME=15 # seconds
for ((i=0; i<MAX_RETRIES; i++)); do
# 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')
# Capture the specific run ID for the 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')
if [ "$cpp_run_id" != "null" ]; then
echo "CPP_RUN_ID=$cpp_run_id" >> $GITHUB_ENV
break
else
echo "Waiting for C++ workflow to start..."
sleep $SLEEP_TIME
fi
done
- 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"
RUN_ID="${{ env.JS_RUN_ID }}"
MAX_POLLS=30 # Max polls before timeout
POLL_INTERVAL=50 # In seconds
# Poll the specific run ID for status
for ((i=0; i<MAX_POLLS; i++)); do
run_response=$(curl -s -H "Authorization: token $TOKEN" \
"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 "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
if [ "$i" -eq "$MAX_POLLS" ]; then
echo "Timeout reached while waiting for JavaScript SDK generation."
exit 1
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"
RUN_ID="${{ env.CPP_RUN_ID }}"
MAX_POLLS=30 # Max polls before timeout
POLL_INTERVAL=50 # In seconds
# Poll the specific run ID for status
for ((i=0; i<MAX_POLLS; i++)); do
run_response=$(curl -s -H "Authorization: token $TOKEN" \
"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 "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."
else
echo "Still in progress. Checking again in ${POLL_INTERVAL} seconds..."
sleep $POLL_INTERVAL
fi
done
if [ "$i" -eq "$MAX_POLLS" ]; then
echo "Timeout reached while waiting for JavaScript SDK generation."
exit 1
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 }}"
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