Skip to content

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

fix: Added a new job to trigger Firebolt api workflow

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

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: Run npm pack
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 Firebolt API repo workflow
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 Workflow Status
id: poll-firebolt-api
run: |
TOKEN="${{ secrets.WORKFLOW_TRIGGER_SECRET }}"
REPO_OWNER="rdkcentral"
REPO_NAME="firebolt-apis"
WORKFLOW_NAME="MFOS standalone sanity report - CORE,MANAGE,DISCOVERY"
# Poll for the latest workflow run in Repo2
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..."
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?status=completed&per_page=1")
conclusion=$(echo $run_response | jq -r '.workflow_runs[0].conclusion')
if [ "$conclusion" == "success" ]; then
echo "SDK generated successfully."
break
elif [ "$conclusion" == "failure" ]; then
echo "Failing to generate SDK with the following OPENRPC changes"
exit 1
else
echo " still in progress. Checking again in 120 seconds..."
sleep 120
fi
done
notify-slack-on-failure:
needs: wait-for-repo2
if: failure()
runs-on: ubuntu-latest
steps:
- name: Send Slack notification
env:
EVENT_NAME: ${{ github.event_name }}
run: |
# Determine the branch name based on the event type
if [ "$EVENT_NAME" == "repository_dispatch" ]; then
BRANCH_NAME=$OPENRPC_PR_BRANCH
elif [ "$EVENT_NAME" == "pull_request" ]; then
BRANCH_NAME=${{ github.event.pull_request.head.ref }}
elif [ "$EVENT_NAME" == "push" ]; then
BRANCH_NAME=${GITHUB_REF#refs/heads/} # Extract branch name from GITHUB_REF for push events
else
BRANCH_NAME="unknown"
fi
# Send the Slack notification with the branch name
curl -X POST -H 'Content-type: application/json' \
--data '{"text": "Failed to generate SDK artifact with the latest changes in the Branch: '$BRANCH_NAME'."}' \
${{ secrets.SLACK_WEBHOOK_URL }}