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