-
Notifications
You must be signed in to change notification settings - Fork 15
158 lines (137 loc) · 5.81 KB
/
check-pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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