1- name : PR Validation for Polling g
1+ name : PR Validation g
22
33on :
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
911permissions :
1012 id-token : write
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
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
0 commit comments