-
Notifications
You must be signed in to change notification settings - Fork 33
69 lines (56 loc) · 2.25 KB
/
watch.yml
File metadata and controls
69 lines (56 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: Add or Update Allocators on Merge
on:
push:
branches:
- main
jobs:
add-or-update-allocators:
runs-on: ubuntu-latest
env:
BACKEND_URL: https://api.allocator.tech
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Git
run: git fetch origin main
- name: Add or Update Allocator
run: |
failed=0
failures=""
echo "Processing changed JSON files from merge commit..."
CHANGED_FILES=$(git diff --name-only "${{ github.event.before }}" "${{ github.event.after }}" | grep '^Allocators/.*\.json$' || true)
if [[ -z "$CHANGED_FILES" ]]; then
echo "No relevant changed files in Allocators/"
exit 0
fi
echo "$CHANGED_FILES"
for file in $CHANGED_FILES; do
echo ""
echo "Adding/Updating: $file"
JSON_BODY="{\"files_changed\":[\"$file\"]}"
RESPONSE=$(curl --silent --show-error --write-out "HTTP_STATUS:%{http_code}" \
--header "Content-Type: application/json" \
--request POST \
--data "$JSON_BODY" \
"${BACKEND_URL}/allocator/create" 2>&1)
HTTP_BODY=$(echo "$RESPONSE" | sed -e 's/HTTP_STATUS\:.*//g')
HTTP_CODE=$(echo "$RESPONSE" | tr -d '\n' | sed -e 's/.*HTTP_STATUS://')
if [[ "$HTTP_CODE" -ge 200 && "$HTTP_CODE" -lt 300 ]]; then
echo "Success for $file"
else
reason="HTTP $HTTP_CODE $HTTP_BODY"
if [[ "$HTTP_CODE" == "000" ]]; then
reason="curl error: $(echo "$RESPONSE" | head -n 1)"
fi
echo "::error file=$file,title=Backend failed::Failed to add/update allocator for $file — $reason"
failures="${failures}\n- $file: $reason"
failed=1
fi
done
if [[ "$failed" -eq 1 ]]; then
echo ""
echo -e "::error title=One or more backend calls failed::Failed for the following files:$failures"
exit 1
fi