Skip to content

Commit eae1b59

Browse files
making the json format error
1 parent acc409c commit eae1b59

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Send changed JSON files on PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
jobs:
8+
send-json-files:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout PR code
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Get changed JSON files and contents to send to API endpoint
18+
id: prepare_json_files
19+
run: |
20+
echo "Collecting changed JSON files..."
21+
22+
BASE="origin/${{ github.event.pull_request.base.ref }}"
23+
HEAD="${{ github.event.pull_request.head.sha }}"
24+
25+
# Get changed files with .json extension
26+
mapfile -t files < <(git diff --name-only "$BASE" "$HEAD" | grep '\.json$')
27+
28+
json_array="["
29+
for file in "${files[@]}"; do
30+
if [ -f "$file" ]; then
31+
if jq -e . "$file" > /dev/null 2>&1; then
32+
content=$(jq -c . < "$file") # compact JSON
33+
json_array+="{\"filename\": \"${file}\", \"content\": $content},"
34+
else
35+
echo "❌ Invalid JSON structure in file: $file"
36+
exit 1
37+
fi
38+
fi
39+
done
40+
41+
# Finalize the JSON array
42+
json_array="${json_array%,}]"
43+
44+
echo "$json_array" > files_payload.json
45+
echo "JSON_PAYLOAD_PATH=files_payload.json" >> $GITHUB_ENV
46+
47+
- name: Send JSON files to API and check response
48+
env:
49+
API_URL: https://valid1-e2akhdekg6a7a2ch.canadacentral-01.azurewebsites.net/
50+
run: |
51+
echo "Sending JSON payload to API"
52+
53+
response=$(curl -s -X POST "$API_URL" \
54+
-H "Content-Type: application/json" \
55+
--data-binary "@$JSON_PAYLOAD_PATH")
56+
57+
status=$(jq -r '.status' <<< "$response")
58+
message=$(jq -r '.message' <<< "$response")
59+
60+
if [ "$status" != "passed" ]; then
61+
echo "❌ Test Fail : $message"
62+
exit 1
63+
fi
64+
65+
echo "✅ $message"

0 commit comments

Comments
 (0)