|
1 | | -name: Validation check for CCP data connectors |
| 1 | +name: pull_request_target |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: |
| 4 | + pull_request_target: |
5 | 5 | types: [opened, synchronize] |
6 | 6 |
|
7 | | -permissions: |
8 | | - id-token: write # enable OIDC token issuance |
9 | | - contents: read # allow checkout of code |
10 | | - |
11 | | -env: |
12 | | - CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} |
13 | | - API_BASE: ${{ secrets.SENTINEL_CONTENT_API_URL }} |
14 | | - |
15 | | - |
16 | 7 | jobs: |
17 | 8 | send-json-files: |
18 | 9 | runs-on: ubuntu-latest |
19 | | - |
20 | 10 | steps: |
21 | | - |
22 | | - |
23 | | - |
24 | | - # 1. Fetch OIDC token in trusted context |
25 | | - - name: 🔐 Request OIDC token from GitHub |
26 | | - id: oidc |
27 | | - run: | |
28 | | - echo "🌐 Fetching OIDC token for audience: api://${CLIENT_ID}" |
29 | | - raw=$(curl -s \ |
30 | | - -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ |
31 | | - "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=api://${CLIENT_ID}") |
32 | | - token=$(echo "$raw" | jq -r '.value') |
33 | | - echo "TOKEN=$token" >> $GITHUB_ENV |
34 | | -
|
35 | | -
|
36 | | -
|
37 | | -
|
38 | | -
|
39 | | -
|
40 | | -
|
41 | 11 | - name: Checkout PR code |
42 | 12 | uses: actions/checkout@v3 |
43 | 13 | with: |
44 | 14 | fetch-depth: 0 |
| 15 | + ref: ${{ github.event.pull_request.head.ref }} |
| 16 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
45 | 17 |
|
46 | 18 | - name: Get changed JSON files and contents to send to API endpoint |
47 | 19 | id: prepare_json_files |
48 | 20 | run: | |
49 | 21 | echo "Collecting changed JSON files..." |
50 | | -
|
51 | 22 | BASE="origin/${{ github.event.pull_request.base.ref }}" |
52 | 23 | HEAD="${{ github.event.pull_request.head.sha }}" |
53 | | -
|
54 | | - # Get changed files with .json extension |
55 | 24 | mapfile -t files < <(git diff --name-only "$BASE" "$HEAD" | grep '\.json$') |
56 | | -
|
57 | 25 | json_array="[" |
58 | 26 | for file in "${files[@]}"; do |
59 | 27 | if [ -f "$file" ]; then |
60 | 28 | if jq -e . "$file" > /dev/null 2>&1; then |
61 | | - content=$(jq -c . < "$file") # compact JSON |
| 29 | + content=$(jq -c . < "$file") |
62 | 30 | json_array+="{\"filename\": \"${file}\", \"content\": $content}," |
63 | 31 | else |
64 | 32 | echo "❌ Invalid JSON structure in file: $file" |
65 | 33 | exit 1 |
66 | 34 | fi |
67 | 35 | fi |
68 | 36 | done |
69 | | -
|
70 | | - # Finalize the JSON array |
71 | 37 | json_array="${json_array%,}]" |
72 | | -
|
73 | 38 | echo "$json_array" > files_payload.json |
74 | 39 | echo "JSON_PAYLOAD_PATH=files_payload.json" >> $GITHUB_ENV |
75 | | - cat files_payload.json |
76 | | -
|
77 | | -
|
78 | 40 |
|
79 | 41 | - name: Send JSON files to API and check response |
80 | 42 | env: |
81 | | - API_URL: ${{ secrets.SENTINEL_CONTENT_API_URL }} |
| 43 | + API_URL: https://valid1-e2akhdekg6a7a2ch.canadacentral-01.azurewebsites.net/ |
82 | 44 | run: | |
83 | 45 | echo "Sending JSON payload to API" |
84 | | -
|
85 | 46 | response=$(curl -s -X POST "$API_URL" \ |
86 | 47 | -H "Content-Type: application/json" \ |
87 | 48 | --data-binary "@$JSON_PAYLOAD_PATH") |
88 | | -
|
89 | 49 | status=$(jq -r '.status' <<< "$response") |
90 | 50 | message=$(jq -r '.message' <<< "$response") |
91 | | -
|
92 | 51 | if [ "$status" != "passed" ]; then |
93 | 52 | echo "❌ Test Fail : $message" |
94 | 53 | exit 1 |
95 | 54 | fi |
96 | | -
|
97 | 55 | echo "✅ $message" |
0 commit comments