Skip to content

Commit 72be99d

Browse files
Merge branch 'Mayank-goel360:main' into main
2 parents dc88413 + 931fac2 commit 72be99d

File tree

2 files changed

+58
-36
lines changed

2 files changed

+58
-36
lines changed

.github/workflows/dra.yml

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
name: PR Validation for Polling g
1+
name: PR Validation g
22

33
on:
4-
pull_request: # ← use pull_request so forks can be checked out
4+
pull_request:
55
branches:
66
- main
7-
types: [opened, synchronize]
7+
types:
8+
- opened
9+
- synchronize
810

911
permissions:
1012
id-token: write
@@ -22,7 +24,7 @@ jobs:
2224
- name: Checkout PR code
2325
uses: actions/checkout@v3
2426
with:
25-
token: ${{ secrets.GITHUB_TOKEN }} # ← ensure forks can be checked out
27+
token: ${{ secrets.GITHUB_TOKEN }}
2628
fetch-depth: 0
2729
ref: ${{ github.event.pull_request.head.ref }}
2830
repository: ${{ github.event.pull_request.head.repo.full_name }}
@@ -31,17 +33,21 @@ jobs:
3133
id: prepare_json_files
3234
run: |
3335
set -eux
36+
3437
echo "🔍 Collecting changed JSON files…"
3538
BASE="${{ github.event.pull_request.base.sha }}"
3639
HEAD="${{ github.event.pull_request.head.sha }}"
3740
41+
# List all .json files changed between base & head
3842
mapfile -t files < <(git diff --name-only "$BASE" "$HEAD" | grep -Ei '\.json$')
3943
echo "→ All .json files: ${files[*]:-<none>}"
4044
41-
# Filter to only ones containing poll (case-insensitive)
45+
# Filter for files containing "poll" (case-insensitive)
4246
filtered=()
4347
for f in "${files[@]}"; do
44-
[[ "$f" =~ poll ]] && filtered+=("$f")
48+
if [[ "$f" =~ [Pp]oll ]]; then
49+
filtered+=("$f")
50+
fi
4551
done
4652
4753
if [ ${#filtered[@]} -eq 0 ]; then
@@ -51,17 +57,21 @@ jobs:
5157
fi
5258
5359
echo "→ Polling files: ${filtered[*]}"
54-
# Build the JSON array
55-
json='['
60+
61+
# Build JSON array payload
62+
json_array="["
5663
for f in "${filtered[@]}"; do
57-
jq -c . "$f" \
58-
| xargs -I% printf '{"filename":"%s","content":%s},' "$f" "%" \
59-
>> tmp_payload.json
64+
if jq -e . "$f" > /dev/null 2>&1; then
65+
content=$(jq -c . "$f")
66+
json_array+="{\"filename\":\"$f\",\"content\":$content},"
67+
else
68+
echo "❌ Invalid JSON structure in file: $f"
69+
exit 1
70+
fi
6071
done
61-
# trim trailing comma and wrap
62-
payload=$(<tmp_payload.json)
63-
payload="[${payload%,}]"
64-
echo "$payload" > files_payload.json
72+
json_array="${json_array%,}]"
73+
74+
echo "$json_array" > files_payload.json
6575
echo "JSON_PAYLOAD_PATH=files_payload.json" >> $GITHUB_ENV
6676
6777
- name: Request OIDC token from GitHub
@@ -74,7 +84,7 @@ jobs:
7484
-H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
7585
"${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=api://${CLIENT_ID}")
7686
token=$(echo "$raw" | jq -r .value)
77-
echo "✔️ Got token, length=${#token}"
87+
echo "✔️ Got token (length=${#token})"
7888
echo "TOKEN=$token" >> $GITHUB_ENV
7989
8090
- name: 📡 Health-check GET
@@ -83,10 +93,10 @@ jobs:
8393
set -eux
8494
echo "🚀 Hitting $API_BASE…"
8595
resp=$(curl -s -w "%{http_code}" -H "Authorization: Bearer $TOKEN" "$API_BASE")
86-
body="${resp::-3}" # all but last 3 chars
87-
code="${resp: -3}" # last 3 chars
96+
body="${resp::-3}"
97+
code="${resp: -3}"
8898
echo "HTTP $code → $body"
89-
if [ "${code:0:1}" != "2" ]; then
99+
if [[ "${code:0:1}" != "2" ]]; then
90100
echo "❌ Health check failed"
91101
exit 1
92102
fi

.github/workflows/dra1.yml

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,36 @@ jobs:
8383
response=$(curl -s -H "Authorization: Bearer $TOKEN" "$API_BASE")
8484
echo "$response" | jq . || echo "⚠️ Invalid JSON response"
8585
86-
- name: Send POST request with JSON payload
87-
if: ${{ env.JSON_PAYLOAD_PATH != 'empty' && env.SKIP_API != 'true' }}
88-
run: |
89-
echo "Sending JSON payload to API..."
90-
response=$(curl -s -X POST "$API_BASE/polling" \
91-
-H "Authorization: Bearer $TOKEN" \
92-
-H "Content-Type: application/json" \
93-
--data-binary "@$JSON_PAYLOAD_PATH")
86+
- name: Send POST request with JSON payload
87+
if: ${{ env.JSON_PAYLOAD_PATH != 'empty' && env.SKIP_API != 'true' }}
88+
run: |
89+
echo "Sending JSON payload to API..."
9490
95-
echo "API response:"
96-
echo "$response" | jq .
91+
response=$(curl -s -w "\n%{http_code}" -X POST "$API_BASE/polling" \
92+
-H "Authorization: Bearer $TOKEN" \
93+
-H "Content-Type: application/json" \
94+
--data-binary "@$JSON_PAYLOAD_PATH")
9795
98-
result_status=$(echo "$response" | jq -r '.status // empty')
99-
message=$(echo "$response" | jq -r '.message // "No message provided"')
96+
http_body=$(echo "$response" | sed '$d')
97+
http_status=$(echo "$response" | tail -n1)
10098
101-
if [ "$result_status" != "passed" ]; then
102-
echo "❌ Validation failed: $message"
103-
exit 1
104-
fi
99+
echo "🔁 HTTP Status: $http_status"
100+
echo "🔍 Raw Response:"
101+
echo "$http_body"
102+
103+
# Try to parse status and message
104+
result_status=$(echo "$http_body" | jq -r '.status // empty')
105+
message=$(echo "$http_body" | jq -r '.message // "No message provided"')
106+
107+
if [ "$http_status" != "200" ]; then
108+
echo "❌ API call failed with status $http_status"
109+
exit 1
110+
fi
111+
112+
if [ "$result_status" != "passed" ]; then
113+
echo "❌ Validation failed: $message"
114+
exit 1
115+
fi
116+
117+
echo "✅ $message"
105118
106-
echo "✅ $message"

0 commit comments

Comments
 (0)