-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathweblate-version-map.sh
More file actions
74 lines (62 loc) · 2.04 KB
/
Copy pathweblate-version-map.sh
File metadata and controls
74 lines (62 loc) · 2.04 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
# SPDX-FileCopyrightText: 2026 William Jin <AuraMindNest@outlook.com>
#
# SPDX-License-Identifier: BSL-1.0
#
# Map PyPI Weblate calver releases to fixed Docker Hub tags (YEAR.MONTH.PATCH.BUILD).
# See https://docs.weblate.org/en/latest/contributing/release.html
# shellcheck shell=bash
pypi_to_docker_fixed() {
local v="$1"
local year month patch
IFS=. read -r year month patch <<< "$v"
patch="${patch:-0}"
echo "${year}.${month}.${patch}.0"
}
parse_pypi_weblate_version() {
local file="${1:-pyproject.toml}"
grep -E '^[[:space:]]*"Weblate(\[[^]]+\])?==[0-9][0-9.]+"' "$file" \
| head -n1 \
| sed -E 's/.*Weblate(\[[^]]+\])?==([0-9][0-9.]+).*/\2/'
}
parse_docker_weblate_tag() {
local file="${1:-docker/Dockerfile.weblate-plugin}"
grep -E '^FROM weblate/weblate:[0-9][0-9.]+' "$file" \
| head -n1 \
| sed -E 's/^FROM weblate\/weblate:([0-9][0-9.]+).*/\1/'
}
docker_weblate_tag_exists() {
local tag="$1"
local code
code="$(curl -sS --connect-timeout 10 --max-time 30 -o /dev/null -w '%{http_code}' \
"https://hub.docker.com/v2/repositories/weblate/weblate/tags/${tag}/")"
[[ "$code" == "200" ]]
}
# Modern calver Weblate releases from PyPI (newest first, one per line).
list_modern_weblate_pypi_releases() {
uv run --with packaging python3 - <<'PY'
import json
import re
import sys
import urllib.request
from packaging.version import Version
calver = re.compile(r"^\d{4}\.\d+(?:\.\d+)?$")
def is_modern_calver(name: str) -> bool:
if not calver.match(name):
return False
year = int(name.split(".", 1)[0])
return year >= 2020
with urllib.request.urlopen(
"https://pypi.org/pypi/Weblate/json", timeout=30
) as resp:
data = json.load(resp)
releases = [v for v in data["releases"] if is_modern_calver(v)]
if not releases:
print("ERROR: no modern calver Weblate releases found on PyPI", file=sys.stderr)
raise SystemExit(1)
for version in sorted(releases, key=Version, reverse=True):
print(version)
PY
}
latest_modern_weblate_pypi_release() {
list_modern_weblate_pypi_releases | head -n1
}