Skip to content

Commit 76b29ad

Browse files
Merge branch 'Mayank-goel360:main' into main
2 parents 0dd8b17 + 6c2265a commit 76b29ad

File tree

2 files changed

+117
-117
lines changed

2 files changed

+117
-117
lines changed

.github/workflows/final_combined.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ jobs:
104104
run: |
105105
echo "Sending JSON payload to API"
106106
107-
response=$(curl -s -X POST "$API_BASE/CCP_dataconnector" \ -H "Authorization: Bearer $TOKEN" \-H "Content-Type: application/json" \-H "Source: GitHub" \--data-binary "@$JSON_PAYLOAD_PATH")
107+
response=$(curl -s -X POST "$API_BASE/CCP_dataconnector" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -H "Source: GitHub" --data-binary "@$JSON_PAYLOAD_PATH")
108108
109109
result_status=$(echo "$response" | jq -r '.status // empty')
110110
message=$(echo "$response" | jq -r '.message // "No message provided"')

.github/workflows/final_dev.yml

Lines changed: 116 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,117 @@
1-
# name: final PR code dev
2-
3-
# on:
4-
# pull_request_target:
5-
# branches:
6-
# - main
7-
# types:
8-
# - opened
9-
# - synchronize
10-
11-
# permissions:
12-
# id-token: write
13-
# contents: read
14-
15-
# env:
16-
# CLIENT_ID: da7fd62a-590e-4e7a-8525-55ea01ffb1ac
17-
# API_BASE: https://sentinel-content-validation-dev-edbve7bwfjbaa6cc.canadacentral-01.azurewebsites.net/
18-
19-
# jobs:
20-
# pr-validate:
21-
# runs-on: ubuntu-latest
22-
23-
# steps:
24-
# - name: Checkout PR code
25-
# uses: actions/checkout@v3
26-
# with:
27-
# token: ${{ secrets.GITHUB_TOKEN }} # needed when using pull_request_target on forks
28-
# fetch-depth: 0
29-
# ref: ${{ github.event.pull_request.head.ref }}
30-
# repository: ${{ github.event.pull_request.head.repo.full_name }}
31-
32-
# - name: Get changed JSON files and contents
33-
# id: prepare_json_files
34-
# run: |
35-
36-
# echo "🔍 Collecting changed JSON files…"
37-
# BASE="${{ github.event.pull_request.base.sha }}"
38-
# HEAD="${{ github.event.pull_request.head.sha }}"
39-
40-
# mapfile -t files < <(git diff --name-only "$BASE" "$HEAD" | grep -Ei '\.json$')
41-
# echo "→ All .json files: ${files[*]:-<none>}"
42-
43-
# if [ ${#files[@]} -eq 0 ]; then
44-
# echo "→ No JSON files changed; skipping validation."
45-
# echo "JSON_PAYLOAD_PATH=empty" >> $GITHUB_ENV
46-
# exit 0
47-
# fi
48-
49-
# echo "→ JSON files: ${files[*]}"
50-
51-
# # Build JSON array payload
52-
# json_array="["
53-
# for f in "${files[@]}"; do
54-
# if jq -e . "$f" > /dev/null; then
55-
# content=$(jq -c . "$f")
56-
# json_array+="{\"filename\":\"$f\",\"content\":$content},"
57-
# else
58-
# echo "❌ Invalid JSON in $f"
59-
# exit 1
60-
# fi
61-
# done
62-
# json_array="${json_array%,}]"
63-
# echo "$json_array" > files_payload.json
64-
# echo "JSON_PAYLOAD_PATH=files_payload.json" >> $GITHUB_ENV
65-
66-
# - name: Request OIDC token from GitHub
67-
# if: env.JSON_PAYLOAD_PATH != 'empty'
68-
# id: fetch_token
69-
# run: |
70-
71-
# echo "🔐 Fetching OIDC token…"
72-
# raw=$(curl -s -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=api://${CLIENT_ID}")
73-
# token=$(echo "$raw" | jq -r .value)
74-
# echo "✔️ Got token (length=${#token})"
75-
# echo "TOKEN=$token" >> $GITHUB_ENV
76-
77-
78-
# - name: Health-check GET
79-
# if: env.JSON_PAYLOAD_PATH != 'empty'
80-
# run: |
81-
82-
# echo "🚀 Hitting $API_BASE…"
83-
# # Capture both body and status
84-
# resp=$(curl -s -w "\n%{http_code}" -H "Authorization: Bearer $TOKEN" "$API_BASE")
85-
# body=$(echo "$resp" | sed '$d') # all but last line
86-
# status=$(echo "$resp" | tail -n1) # last line
1+
name: final PR code dev
2+
3+
on:
4+
pull_request_target:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- synchronize
10+
11+
permissions:
12+
id-token: write
13+
contents: read
14+
15+
env:
16+
CLIENT_ID: da7fd62a-590e-4e7a-8525-55ea01ffb1ac
17+
API_BASE: https://sentinel-content-validation-dev-edbve7bwfjbaa6cc.canadacentral-01.azurewebsites.net/
18+
19+
jobs:
20+
pr-validate:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout PR code
25+
uses: actions/checkout@v3
26+
with:
27+
token: ${{ secrets.GITHUB_TOKEN }} # needed when using pull_request_target on forks
28+
fetch-depth: 0
29+
ref: ${{ github.event.pull_request.head.ref }}
30+
repository: ${{ github.event.pull_request.head.repo.full_name }}
31+
32+
- name: Get changed JSON files and contents
33+
id: prepare_json_files
34+
run: |
35+
36+
echo "🔍 Collecting changed JSON files…"
37+
BASE="${{ github.event.pull_request.base.sha }}"
38+
HEAD="${{ github.event.pull_request.head.sha }}"
39+
40+
mapfile -t files < <(git diff --name-only "$BASE" "$HEAD" | grep -Ei '\.json$')
41+
echo "→ All .json files: ${files[*]:-<none>}"
42+
43+
if [ ${#files[@]} -eq 0 ]; then
44+
echo "→ No JSON files changed; skipping validation."
45+
echo "JSON_PAYLOAD_PATH=empty" >> $GITHUB_ENV
46+
exit 0
47+
fi
48+
49+
echo "→ JSON files: ${files[*]}"
50+
51+
# Build JSON array payload
52+
json_array="["
53+
for f in "${files[@]}"; do
54+
if jq -e . "$f" > /dev/null; then
55+
content=$(jq -c . "$f")
56+
json_array+="{\"filename\":\"$f\",\"content\":$content},"
57+
else
58+
echo "❌ Invalid JSON in $f"
59+
exit 1
60+
fi
61+
done
62+
json_array="${json_array%,}]"
63+
echo "$json_array" > files_payload.json
64+
echo "JSON_PAYLOAD_PATH=files_payload.json" >> $GITHUB_ENV
65+
66+
- name: Request OIDC token from GitHub
67+
if: env.JSON_PAYLOAD_PATH != 'empty'
68+
id: fetch_token
69+
run: |
70+
71+
echo "🔐 Fetching OIDC token…"
72+
raw=$(curl -s -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=api://${CLIENT_ID}")
73+
token=$(echo "$raw" | jq -r .value)
74+
echo "✔️ Got token (length=${#token})"
75+
echo "TOKEN=$token" >> $GITHUB_ENV
76+
77+
78+
- name: Health-check GET
79+
if: env.JSON_PAYLOAD_PATH != 'empty'
80+
run: |
81+
82+
echo "🚀 Hitting $API_BASE…"
83+
# Capture both body and status
84+
resp=$(curl -s -w "\n%{http_code}" -H "Authorization: Bearer $TOKEN" "$API_BASE")
85+
body=$(echo "$resp" | sed '$d') # all but last line
86+
status=$(echo "$resp" | tail -n1) # last line
8787
88-
# # Try to parse JSON, but don’t exit if it fails
89-
# if echo "$body" | jq . > /dev/null 2>&1; then
90-
# echo "✔️ Parsed JSON:"
91-
# echo "$body" | jq .
92-
# else
93-
# echo "⚠️ Body is not JSON or empty"
94-
# fi
95-
96-
# # Exit non-2xx
97-
# if [[ "$status" != 2* ]]; then
98-
# echo "❌ Health check failed (status $status)"
99-
# exit 1
100-
# fi
101-
102-
# - name: 📦 POST CCP payload
103-
# if: env.JSON_PAYLOAD_PATH != 'empty'
104-
# run: |
105-
# echo "Sending JSON payload to API"
106-
107-
# response=$(curl -s -X POST "$API_BASE/dataConnector" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data-binary "@$JSON_PAYLOAD_PATH")
108-
109-
# result_status=$(echo "$response" | jq -r '.status // empty')
110-
# message=$(echo "$response" | jq -r '.message // "No message provided"')
111-
112-
# if [ "$result_status" != "passed" ]; then
113-
# echo -e " ❌ Validation failed: \n $message"
114-
# exit 1
115-
# fi
116-
117-
# echo "✅ $message"
88+
# Try to parse JSON, but don’t exit if it fails
89+
if echo "$body" | jq . > /dev/null 2>&1; then
90+
echo "✔️ Parsed JSON:"
91+
echo "$body" | jq .
92+
else
93+
echo "⚠️ Body is not JSON or empty"
94+
fi
95+
96+
# Exit non-2xx
97+
if [[ "$status" != 2* ]]; then
98+
echo "❌ Health check failed (status $status)"
99+
exit 1
100+
fi
101+
102+
- name: 📦 POST CCP payload
103+
if: env.JSON_PAYLOAD_PATH != 'empty'
104+
run: |
105+
echo "Sending JSON payload to API"
106+
107+
response=$(curl -s -X POST "$API_BASE/dataConnector" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data-binary "@$JSON_PAYLOAD_PATH")
108+
109+
result_status=$(echo "$response" | jq -r '.status // empty')
110+
message=$(echo "$response" | jq -r '.message // "No message provided"')
111+
112+
if [ "$result_status" != "passed" ]; then
113+
echo -e " ❌ Validation failed: \n $message"
114+
exit 1
115+
fi
116+
117+
echo "✅ $message"

0 commit comments

Comments
 (0)