-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathupdate-versions.sh
More file actions
executable file
·70 lines (57 loc) · 2.62 KB
/
update-versions.sh
File metadata and controls
executable file
·70 lines (57 loc) · 2.62 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
#!/usr/bin/env bash
# Fetches the latest compatible any-sync versions from puppetdoc.anytype.io
# and updates the version variables in .env in-place.
#
# Usage:
# ./update-versions.sh # updates .env with prod versions
# ./update-versions.sh --stage1 # updates .env with stage1 versions
# ./update-versions.sh my.env # updates a custom env file
# ./update-versions.sh my.env --stage1 # updates a custom env file with stage1 versions
set -euo pipefail
ENV_FILE=".env"
CHANNEL="prod"
for arg in "$@"; do
case "$arg" in
--stage1) CHANNEL="stage1" ;;
*) ENV_FILE="$arg" ;;
esac
done
API_URL="https://puppetdoc.anytype.io/api/v1/${CHANNEL}-any-sync-compatible-versions/"
for cmd in curl jq; do
command -v "$cmd" >/dev/null 2>&1 || { echo "Error: '$cmd' is required but not installed."; exit 1; }
done
if [[ ! -f "$ENV_FILE" ]]; then
echo "Error: $ENV_FILE not found. Run: cp .env.example .env"
exit 1
fi
echo "Fetching latest compatible versions (channel: ${CHANNEL})..."
response=$(curl -fsSL --max-time 10 "$API_URL") || {
echo "Error: failed to fetch versions from $API_URL"
exit 1
}
versions=$(echo "$response" | jq -r 'to_entries | sort_by(.key | tonumber) | last | .value')
node_version=$(echo "$versions" | jq -r '."pkg::any-sync-node"')
filenode_version=$(echo "$versions" | jq -r '."pkg::any-sync-filenode"')
coordinator_version=$(echo "$versions" | jq -r '."pkg::any-sync-coordinator"')
consensusnode_version=$(echo "$versions" | jq -r '."pkg::any-sync-consensusnode"')
for v in "$node_version" "$filenode_version" "$coordinator_version" "$consensusnode_version"; do
if [[ "$v" == "null" || -z "$v" ]]; then
echo "Error: unexpected API response — could not parse versions."
exit 1
fi
done
# sed -i is not portable between Linux and macOS
if [[ "$(uname)" == "Darwin" ]]; then
SED_I=(-i '')
else
SED_I=(-i)
fi
sed "${SED_I[@]}" "s/^ANY_SYNC_NODE_VERSION=.*/ANY_SYNC_NODE_VERSION=v${node_version}/" "$ENV_FILE"
sed "${SED_I[@]}" "s/^ANY_SYNC_FILENODE_VERSION=.*/ANY_SYNC_FILENODE_VERSION=v${filenode_version}/" "$ENV_FILE"
sed "${SED_I[@]}" "s/^ANY_SYNC_COORDINATOR_VERSION=.*/ANY_SYNC_COORDINATOR_VERSION=v${coordinator_version}/" "$ENV_FILE"
sed "${SED_I[@]}" "s/^ANY_SYNC_CONSENSUSNODE_VERSION=.*/ANY_SYNC_CONSENSUSNODE_VERSION=v${consensusnode_version}/" "$ENV_FILE"
echo "Updated $ENV_FILE:"
echo " ANY_SYNC_NODE_VERSION=v${node_version}"
echo " ANY_SYNC_FILENODE_VERSION=v${filenode_version}"
echo " ANY_SYNC_COORDINATOR_VERSION=v${coordinator_version}"
echo " ANY_SYNC_CONSENSUSNODE_VERSION=v${consensusnode_version}"