From 501553bf558dfa45d43a800758451fc90624423d Mon Sep 17 00:00:00 2001 From: Shengqi Chen Date: Sat, 13 Sep 2025 16:35:45 +0800 Subject: [PATCH] Replace hardcoded versions passed to yum-sync.py with templates [ci skip] Signed-off-by: Shengqi Chen --- adoptium.py | 4 ++-- chef.sh | 2 +- gitlab-ce.sh | 2 +- gitlab-runner.sh | 2 +- influxdata.sh | 2 +- mongodb.sh | 2 +- rudder.sh | 2 +- virtualbox.sh | 2 +- yum-sync.py | 25 ++++++++++++++++++++++++- 9 files changed, 33 insertions(+), 10 deletions(-) diff --git a/adoptium.py b/adoptium.py index 803a796..3e9690b 100755 --- a/adoptium.py +++ b/adoptium.py @@ -118,7 +118,7 @@ if __name__ == "__main__": sp.run([str(here/"yum-sync.py"), BASE_URL+'/rpm/rhel/@{os_ver}/@{arch}', "--download-repodata", - '9,10', + '@rhel-current', 'Adoptium', 'x86_64,aarch64', "rhel@{os_ver}-@{arch}", @@ -128,7 +128,7 @@ if __name__ == "__main__": sp.run([str(here/"yum-sync.py"), BASE_URL+'/rpm/fedora/@{os_ver}/@{arch}', "--download-repodata", - '42', + '@fedora-current', 'Adoptium', 'x86_64,aarch64', "fedora@{os_ver}-@{arch}", diff --git a/chef.sh b/chef.sh index 4fecbaf..e7e4df4 100755 --- a/chef.sh +++ b/chef.sh @@ -13,7 +13,7 @@ YUM_PATH="${BASE_PATH}/yum/stable" APT_PATH="${BASE_PATH}/apt/stable" export REPO_SIZE_FILE=/tmp/reposize.$RANDOM -"$yum_sync" "${UPSTREAM}/yum/stable/el/@{os_ver}/@{arch}" 9 chef x86_64 "stable-el@{os_ver}-@{arch}" "$YUM_PATH" +"$yum_sync" "${UPSTREAM}/yum/stable/el/@{os_ver}/@{arch}" @rhel-current chef x86_64 "stable-el@{os_ver}-@{arch}" "$YUM_PATH" echo "YUM finished" "$apt_sync" --delete "${UPSTREAM}/apt/stable" @ubuntu-lts,@debian-current main amd64,i386,aarch64 "$APT_PATH" diff --git a/gitlab-ce.sh b/gitlab-ce.sh index 7a211c0..92d67b7 100755 --- a/gitlab-ce.sh +++ b/gitlab-ce.sh @@ -15,7 +15,7 @@ UBUNTU_PATH="${BASE_PATH}/ubuntu/" DEBIAN_PATH="${BASE_PATH}/debian/" export REPO_SIZE_FILE=/tmp/reposize.$RANDOM -"$yum_sync" "${UPSTREAM}/el/@{os_ver}/@{arch}/" 9 "gitlab" x86_64 "el@{os_ver}" "$YUM_PATH" +"$yum_sync" "${UPSTREAM}/el/@{os_ver}/@{arch}/" @rhel-current "gitlab" x86_64 "el@{os_ver}" "$YUM_PATH" echo "YUM finished" "$apt_sync" --delete "${UPSTREAM}/ubuntu" @ubuntu-lts main amd64,i386 "$UBUNTU_PATH" diff --git a/gitlab-runner.sh b/gitlab-runner.sh index 818c324..e06b093 100755 --- a/gitlab-runner.sh +++ b/gitlab-runner.sh @@ -15,7 +15,7 @@ UBUNTU_PATH="${BASE_PATH}/ubuntu/" DEBIAN_PATH="${BASE_PATH}/debian/" export REPO_SIZE_FILE=/tmp/reposize.$RANDOM -"$yum_sync" "${UPSTREAM}/el/@{os_ver}/@{arch}" 9 gitlab-runner x86_64,aarch64 "el@{os_ver}-@{arch}" "$YUM_PATH" +"$yum_sync" "${UPSTREAM}/el/@{os_ver}/@{arch}" @rhel-current gitlab-runner x86_64,aarch64 "el@{os_ver}-@{arch}" "$YUM_PATH" echo "YUM finished" "$apt_sync" --delete "${UPSTREAM}/ubuntu" @ubuntu-lts main amd64,i386,arm64 "$UBUNTU_PATH" diff --git a/influxdata.sh b/influxdata.sh index 192eb62..eaad792 100755 --- a/influxdata.sh +++ b/influxdata.sh @@ -27,7 +27,7 @@ echo "Debian/Ubuntu finished" # =================== YUM/DNF repos ========================== -"$yum_sync" "${BASE_URL}/rhel/@{os_ver}/@{arch}/stable/" 9 influxdata x86_64 "el@{os_ver}-@{arch}" "$YUM_PATH" +"$yum_sync" "${BASE_URL}/rhel/@{os_ver}/@{arch}/stable/" @rhel-current influxdata x86_64 "el@{os_ver}-@{arch}" "$YUM_PATH" echo "YUM finished" "${_here}/helpers/size-sum.sh" $REPO_SIZE_FILE --rm diff --git a/mongodb.sh b/mongodb.sh index 8d8ef24..ac08b0a 100755 --- a/mongodb.sh +++ b/mongodb.sh @@ -19,7 +19,7 @@ export REPO_SIZE_FILE=/tmp/reposize.$RANDOM components=$(printf ",%s" "${MONGO_VERSIONS[@]}") components=${components:1} -"$yum_sync" "${BASE_URL}/yum/redhat/@{os_ver}/mongodb-org/@{comp}/@{arch}/" 9 "$components" x86_64 "el@{os_ver}-@{comp}" "$YUM_PATH" +"$yum_sync" "${BASE_URL}/yum/redhat/@{os_ver}/mongodb-org/@{comp}/@{arch}/" @rhel-current "$components" x86_64 "el@{os_ver}-@{comp}" "$YUM_PATH" pushd "${YUM_PATH}" for stable in el*-${STABLE_VERSION}; do # e.g. "el8" -> "el8-4.2" diff --git a/rudder.sh b/rudder.sh index 2876751..9b3e494 100755 --- a/rudder.sh +++ b/rudder.sh @@ -16,7 +16,7 @@ export REPO_SIZE_FILE=/tmp/reposize.$RANDOM components=$(printf ",%s" "${RUDDER_VERS[@]}") components=${components:1} -"$yum_sync" "${UPSTREAM}/rpm/@{comp}/RHEL_@{os_ver}/" 9,10 $components x86_64 "rudder@{comp}-RHEL_@{os_ver}" "$YUM_PATH" +"$yum_sync" "${UPSTREAM}/rpm/@{comp}/RHEL_@{os_ver}/" @rhel-current $components x86_64 "rudder@{comp}-RHEL_@{os_ver}" "$YUM_PATH" echo "YUM finished" for ver in ${RUDDER_VERS[@]}; do diff --git a/virtualbox.sh b/virtualbox.sh index b05a1ce..ae723f3 100755 --- a/virtualbox.sh +++ b/virtualbox.sh @@ -19,7 +19,7 @@ export REPO_SIZE_FILE=/tmp/reposize.$RANDOM # === download rhel packages ==== -"$yum_sync" "${BASE_URL}/rpm/el/@{os_ver}/@{arch}" 9 VirtualBox x86_64 "el@{os_ver}" "$YUM_PATH" +"$yum_sync" "${BASE_URL}/rpm/el/@{os_ver}/@{arch}" @rhel-current VirtualBox x86_64 "el@{os_ver}" "$YUM_PATH" echo "YUM finished" # === download deb packages ==== diff --git a/yum-sync.py b/yum-sync.py index ab8bfd2..30de289 100755 --- a/yum-sync.py +++ b/yum-sync.py @@ -10,6 +10,7 @@ import shutil import sqlite3 import traceback import time +import re from email.utils import parsedate_to_datetime import xml.etree.ElementTree as ET from pathlib import Path @@ -21,6 +22,26 @@ DOWNLOAD_TIMEOUT = int(os.getenv("DOWNLOAD_TIMEOUT", "1800")) REPO_STAT = {} +OS_TEMPLATE = { + "rhel-current": ["9", "10"], + "fedora-current": ["41", "42"], +} + +pattern_os_template = re.compile(r"@\{(.+)\}") + +def replace_os_template(os_list: List[str]) -> List[str]: + ret = [] + for i in os_list: + matched = pattern_os_template.search(i) + if matched: + for os in OS_TEMPLATE[matched.group(1)]: + ret.append(pattern_os_template.sub(os, i)) + elif i.startswith("@"): + ret.extend(OS_TEMPLATE[i[1:]]) + else: + ret.append(i) + return ret + def calc_repo_size(path: Path): dbfiles = path.glob("repodata/*primary.*") with tempfile.NamedTemporaryFile() as tmp: @@ -175,7 +196,9 @@ def main(): args = parser.parse_args() os_list = [] - for os_version in args.os_version.split(","): + raw_os_list = args.os_version.split(",") + raw_os_list = replace_os_template(raw_os_list) + for os_version in raw_os_list.split(","): if "-" in os_version and "-stream" not in os_version: dash = os_version.index("-") os_list = os_list + [