Skip to content

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

fix: Added a new job to trigger Firebolt api workflow

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

Workflow file for this run

name: Check Pull Request
on:
workflow_dispatch:
pull_request:
types:
- 'opened'
- '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-repo2:
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"
while true; do
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, retrying in 10 seconds..."
sleep 10
continue
fi
# Get the latest workflow 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')
if [ "$status" == "completed" ] && [ "$conclusion" == "success" ]; then
echo "JavaScript SDK generated successfully."
break
elif [ "$status" == "completed" ] && [ "$conclusion" == "failure" ]; then
echo "Failed to generate JavaScript SDK."
exit 1
else
echo "Still in progress. Checking again in 120 seconds..."
sleep 120
fi
done
- 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"
# Debugging workflow names
echo "Polling workflow: $WORKFLOW_NAME"
# Poll for the latest workflow run in Repo2
while true; do
# Fetch the list of workflows
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)')
echo "Workflow response: $response"
workflow_id=$(echo $response | jq -r '.id')
if [ "$workflow_id" == "null" ]; then
echo "Workflow not found, retrying in 10 seconds..."
sleep 10
continue
fi
# Get the latest workflow 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")
echo "Raw run response: $run_response"
run_id=$(echo $run_response | jq -r '.workflow_runs[0].id')
conclusion=$(echo $run_response | jq -r '.workflow_runs[0].conclusion')
status=$(echo $run_response | jq -r '.workflow_runs[0].status')
# Echo the run_id and conclusion for debugging
echo "Current run ID: $run_id"
echo "Current workflow conclusion: $conclusion"
echo "Current workflow status: $status"
# Check if the workflow run is still in progress
if [ "$status" != "completed" ]; then
echo "CPP SDK generation still in progress. Checking again in 120 seconds..."
sleep 120
continue
fi
# Check if the workflow completed successfully or failed
if [ "$conclusion" == "success" ]; then
echo "CPP SDK generated successfully."
# Post a comment on the PR with success message
curl -s -H "Authorization: token $TOKEN" \
-X POST \
-d "{\"body\": \"CPP SDK generation succeeded for PR #$PR_NUMBER.\"}" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/issues/$PR_NUMBER/comments"
break
elif [ "$conclusion" == "failure" ]; then
echo "CPP SDK generation failed."
# Post a comment on the PR with failure message
curl -s -H "Authorization: token $TOKEN" \
-X POST \
-d "{\"body\": \"CPP SDK generation failed for PR #$PR_NUMBER.\"}" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/issues/$PR_NUMBER/comments"
exit 1
fi
done