-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-db.sh
More file actions
45 lines (33 loc) · 1.44 KB
/
update-db.sh
File metadata and controls
45 lines (33 loc) · 1.44 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
DB_FILE="${SCRIPT_DIR}/v2/version-db.json"
REPO="LiteLDev/LeviLamina"
command -v curl >/dev/null 2>&1 || { echo "curl is required" >&2; exit 1; }
command -v jq >/dev/null 2>&1 || { echo "jq is required" >&2; exit 1; }
if [[ ! -f "${DB_FILE}" ]]; then
echo "version-db.json not found at ${DB_FILE}" >&2
exit 1
fi
TAG="${TAG:-}" # Optional override via environment variable
if [[ -z "${TAG}" ]]; then
TAG=$(curl -fsSL "https://api.github.com/repos/${REPO}/tags?per_page=100" \
| jq -r '.[0].name // empty')
fi
if [[ -z "${TAG}" ]]; then
echo "Failed to determine latest tag" >&2
exit 1
fi
TOOTH_URL="https://github.com/${REPO}/raw/refs/tags/${TAG}/tooth.json"
CLIENT_BRD_VERSION=$(curl -fsSL "${TOOTH_URL}" \
| jq -r '.variants[] | select(.label=="client") | .dependencies["github.com/LiteLDev/bedrock-runtime-data"] | select(.!=null)')
if [[ -z "${CLIENT_BRD_VERSION}" ]]; then
echo "Failed to read bedrock-runtime-data dependency for client variant" >&2
exit 1
fi
SHORT_TAG="${TAG#v}"
RUNTIME_VERSION=$(echo "${CLIENT_BRD_VERSION%%-*}" | sed 's/\.\([0-9]\+\)$/.0\1/')
TMP_FILE=$(mktemp)
jq --arg tag "${SHORT_TAG}" --arg ver "1.${RUNTIME_VERSION}" '.versions[$ver] = ((.versions[$ver] // []) + [$tag] | unique)' "${DB_FILE}" > "${TMP_FILE}"
mv "${TMP_FILE}" "${DB_FILE}"
echo "Updated ${DB_FILE} with ${SHORT_TAG}: ${RUNTIME_VERSION}"