-
Notifications
You must be signed in to change notification settings - Fork 15
213 lines (183 loc) · 8.05 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
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