-
Notifications
You must be signed in to change notification settings - Fork 1
112 lines (94 loc) · 3.43 KB
/
Copy pathsend-get-request.yml
File metadata and controls
112 lines (94 loc) · 3.43 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Send GET Request on Push
on:
push:
branches:
- master
jobs:
send-request:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Sync repository
env:
SYNC_TOKEN: ${{ secrets.SYNC_TOKEN }}
run: |
set -uo pipefail
if [ -z "$SYNC_TOKEN" ]; then
echo "SYNC_TOKEN is not configured"
exit 1
fi
sync_base="https://docs.rms.net.cn/api/sync?token=${SYNC_TOKEN}"
temp_dir="$(mktemp -d -p "${RUNNER_TEMP:-/tmp}" sync.XXXXXX)"
trap 'rm -rf "$temp_dir"' EXIT
manifest_path="$temp_dir/manifest.json"
python3 scripts/generate_manifest.py "$manifest_path"
if [ ! -s "$manifest_path" ]; then
echo "Manifest is empty"
exit 0
fi
sync_once() {
local response_path="$temp_dir/response.json"
local -a update_files=()
local -a deleted_files=()
if ! curl --fail -sS -X POST \
-H 'Content-Type: application/json' \
--data-binary "@$manifest_path" \
"${sync_base}&mode=manifest" \
-o "$response_path"; then
echo "Manifest submission failed"
return 1
fi
if ! mapfile -t update_files < <(python3 scripts/parse_manifest_response.py "$response_path"); then
echo "Failed to parse manifest response"
return 1
fi
if ! mapfile -t deleted_files < <(python3 scripts/parse_manifest_response.py "$response_path" --field deleted); then
echo "Failed to parse deleted entries"
return 1
fi
if [ ${#update_files[@]} -eq 0 ] && [ ${#deleted_files[@]} -eq 0 ]; then
echo "No changes required"
return 0
fi
if [ ${#deleted_files[@]} -gt 0 ]; then
echo "Removed files reported by server:"
for relpath in "${deleted_files[@]}"; do
echo " $relpath"
done
fi
for relpath in "${update_files[@]}"; do
file="./$relpath"
if [ ! -f "$file" ]; then
echo "Requested file '$relpath' not found"
return 1
fi
if ! curl --fail -sS -X POST \
--form "path=$relpath" \
--form "file=@$file;type=application/octet-stream" \
"${sync_base}&mode=upload"; then
echo "Upload failed for '$relpath'"
return 1
fi
done
if ! timeout 10s curl -sS -X GET 'http://api.chuckfang.com/XRPAD/RMS%20Docs%20Update/The%20docs%20has%20update%20certainly'; then
echo "Notification to XRPAD failed"
return 1
fi
if ! timeout 10s curl -sS -X GET 'http://api.chuckfang.com/XRPHONE/RMS%20Docs%20Update/The%20docs%20has%20update%20certainly'; then
echo "Notification to XRPHONE failed"
return 1
fi
return 0
}
retries=1
while [ $retries -ge 0 ]; do
if sync_once; then
exit 0
fi
retries=$((retries-1))
if [ $retries -ge 0 ]; then
sleep 5
fi
done
exit 1