1-
2- name : PR Validation for Polling file prod
1+ name : PR Validation for Polling g
32
43on :
5- pull_request_target :
4+ pull_request : # ← use pull_request so forks can be checked out
65 branches :
7- # - doNotMerge-ContentValidationCCP ##########################################################################
86 - main
97 types : [opened, synchronize]
108
@@ -14,7 +12,7 @@ permissions:
1412
1513env :
1614 CLIENT_ID : ${{ secrets.AZURE_CONTENT_VALIDATION_CLIENT_ID }}
17- API_BASE : https://sentinel-content-validationapi-prod-bvgsc3hjhyeqangg.canadacentral-01.azurewebsites.net/
15+ API_BASE : https://sentinel-content-validationapi-prod-bvgsc3hjhyeqangg.canadacentral-01.azurewebsites.net/
1816
1917jobs :
2018 pr-validate :
@@ -24,96 +22,83 @@ jobs:
2422 - name : Checkout PR code
2523 uses : actions/checkout@v3
2624 with :
25+ token : ${{ secrets.GITHUB_TOKEN }} # ← ensure forks can be checked out
2726 fetch-depth : 0
2827 ref : ${{ github.event.pull_request.head.ref }}
2928 repository : ${{ github.event.pull_request.head.repo.full_name }}
3029
31- - name : Get changed JSON files and contents to send to API endpoint
30+ - name : Get changed JSON files and contents
3231 id : prepare_json_files
3332 run : |
34- echo "Collecting changed JSON files:"
33+ set -eux
34+ echo "🔍 Collecting changed JSON files…"
3535 BASE="${{ github.event.pull_request.base.sha }}"
3636 HEAD="${{ github.event.pull_request.head.sha }}"
3737
38- mapfile -t files < <(git diff --name-only "$BASE" "$HEAD" | grep '\.json$')
39- echo "Changed JSON files:"
40- for file in "${files[@]}"; do
41- echo "$file"
42- done
43-
44- filtered_files=()
45- for file in "${files[@]}"; do
46- if [[ "$file" =~ [Pp][Oo][Ll][Ll] ]]; then
47- filtered_files+=("$file")
48- fi
49- done
38+ mapfile -t files < <(git diff --name-only "$BASE" "$HEAD" | grep -Ei '\.json$')
39+ echo "→ All .json files: ${files[*]:-<none>}"
5040
51- echo "Polling JSON files:"
52- for file in "${filtered_files[@]}"; do
53- echo "$file"
41+ # Filter to only ones containing “poll” (case-insensitive)
42+ filtered=()
43+ for f in "${files[@]}"; do
44+ [[ "$f" =~ poll ]] && filtered+=("$f")
5445 done
5546
56- if [ ${#filtered_files [@]} -eq 0 ]; then
57- echo "No JSON files with 'poll' in the name changed in this PR ."
47+ if [ ${#filtered [@]} -eq 0 ]; then
48+ echo "→ No polling JSON files changed; skipping validation ."
5849 echo "JSON_PAYLOAD_PATH=empty" >> $GITHUB_ENV
5950 exit 0
6051 fi
6152
62- json_array="["
63- for file in "${filtered_files[@]}"; do
64- if [ -f "$file" ]; then
65- if jq -e . "$file" > /dev/null 2>&1; then
66- content=$(jq -c . < "$file")
67- json_array+="{\"filename\": \"${file}\", \"content\": $content},"
68- else
69- echo "❌ Invalid JSON structure in file: $file"
70- exit 1
71- fi
72- fi
53+ echo "→ Polling files: ${filtered[*]}"
54+ # Build the JSON array
55+ json='['
56+ for f in "${filtered[@]}"; do
57+ jq -c . "$f" \
58+ | xargs -I% printf '{"filename":"%s","content":%s},' "$f" "%" \
59+ >> tmp_payload.json
7360 done
74- json_array="${json_array%,}]"
75-
76- # 🔍 Debug echo
77- echo "Constructed JSON array: $json_array"
78-
79- echo "$json_array" > files_payload.json
61+ # trim trailing comma and wrap
62+ payload=$(<tmp_payload.json)
63+ payload="[${payload%,}]"
64+ echo "$payload" > files_payload.json
8065 echo "JSON_PAYLOAD_PATH=files_payload.json" >> $GITHUB_ENV
8166
8267 - name : Request OIDC token from GitHub
83- if : ${{ env.JSON_PAYLOAD_PATH != 'empty' }}
68+ if : env.JSON_PAYLOAD_PATH != 'empty'
8469 id : fetch_token
8570 run : |
86- raw=$(curl -s -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=api://${CLIENT_ID}")
87- token=$(echo "$raw" | jq -r '.value')
71+ set -eux
72+ echo "🔐 Fetching OIDC token…"
73+ raw=$(curl -s \
74+ -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
75+ "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=api://${CLIENT_ID}")
76+ token=$(echo "$raw" | jq -r .value)
77+ echo "✔️ Got token, length=${#token}"
8878 echo "TOKEN=$token" >> $GITHUB_ENV
8979
90- - name : Send GET request to check if API is live
91- if : ${{ env.JSON_PAYLOAD_PATH != 'empty' }}
92- id : check_api
93- run : |
94- response=$(curl -s -H "Authorization: Bearer $TOKEN" "$API_BASE")
95- echo "$response" | jq . || true
96-
97- - name : 📡 Send GET request with Bearer token
98- run : |
99- echo "🚀 Sending GET to $API_BASE"
100- response=$(curl -s -H "Authorization: Bearer $TOKEN" "$API_BASE")
101- echo "🔍 Response JSON:"
102- echo "$response" | jq .
103-
104- - name : Send POST request with JSON payload
105- if : ${{ env.JSON_PAYLOAD_PATH != 'empty' }}
80+ - name : 📡 Health-check GET
81+ if : env.JSON_PAYLOAD_PATH != 'empty'
10682 run : |
107- echo "Sending JSON payload to API"
108-
109- response=$(curl -s -X POST "$API_BASE" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data-binary "@$JSON_PAYLOAD_PATH")
110-
111- result_status=$(echo "$response" | jq -r '.status // empty')
112- message=$(echo "$response" | jq -r '.message // "No message provided"')
113-
114- if [ "$result_status" != "passed" ]; then
115- echo -e " ❌ Validation failed: $message"
83+ set -eux
84+ echo "🚀 Hitting $API_BASE…"
85+ 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
88+ echo "HTTP $code → $body"
89+ if [ "${code:0:1}" != "2" ]; then
90+ echo "❌ Health check failed"
11691 exit 1
11792 fi
11893
119- echo "✅ $message"
94+ - name : 📦 POST polling payload
95+ if : env.JSON_PAYLOAD_PATH != 'empty'
96+ run : |
97+ set -eux
98+ echo "🚀 Sending POST to $API_BASE/polling…"
99+ curl -s -X POST \
100+ -H "Authorization: Bearer $TOKEN" \
101+ -H "Content-Type: application/json" \
102+ --data-binary "@$JSON_PAYLOAD_PATH" \
103+ "$API_BASE/polling" \
104+ | jq .
0 commit comments