[apache-http-server] Refactor script (#212)

Make the script more readable, mostly by:

- using the endoflife.Product class,
- removing the unnecessary use of functions,
- renaming a few variables,
- declaring a constant for regexes.
This commit is contained in:
Marc Wrobel
2023-12-10 13:19:17 +01:00
committed by GitHub
parent 06c462c3cc
commit 7d462ffe90
2 changed files with 25 additions and 49 deletions

View File

@@ -7,7 +7,7 @@ from common import endoflife
"""Fetches Amazon Neptune versions from its RSS feed on docs.aws.amazon.com.""" """Fetches Amazon Neptune versions from its RSS feed on docs.aws.amazon.com."""
RSS_URL = "https://docs.aws.amazon.com/neptune/latest/userguide/rssupdates.rss" RSS_URL = "https://docs.aws.amazon.com/neptune/latest/userguide/rssupdates.rss"
VERSION_REGEX = re.compile(r"^Engine version (?P<version>[0-9R.]+)$") VERSION_PATTERN = re.compile(r"^Engine version (?P<version>[0-9R.]+)$")
product = endoflife.Product("amazon-neptune") product = endoflife.Product("amazon-neptune")
print(f"::group::{product.name}") print(f"::group::{product.name}")
@@ -18,7 +18,7 @@ for entry in rss.getElementsByTagName("item"):
version_str = entry.getElementsByTagName("title")[0].firstChild.nodeValue version_str = entry.getElementsByTagName("title")[0].firstChild.nodeValue
date_str = entry.getElementsByTagName("pubDate")[0].firstChild.nodeValue date_str = entry.getElementsByTagName("pubDate")[0].firstChild.nodeValue
version_match = VERSION_REGEX.match(version_str) version_match = VERSION_PATTERN.match(version_str)
if version_match: if version_match:
product.declare_version(version_match['version'], dates.parse_datetime(date_str)) product.declare_version(version_match['version'], dates.parse_datetime(date_str))

View File

@@ -1,62 +1,38 @@
import re import re
from pathlib import Path
from common import dates from common import dates
from common import endoflife from common import endoflife
from common.git import Git from common.git import Git
"""Fetch apache versions from its git repository. """Fetches Apache HTTP Server versions and release date from its git repository
by looking at the STATUS file of each <major>.<minor>.x branch."""
Every branch formatted like 2.4.x has a STATUS file which contains a version VERSION_AND_DATE_PATTERNS = [
history. Not every version was released, the lines are filtered with # for most versions
(?:Released|Announced) to get the released versions only (they were not re.compile(r"\s+(?P<version>\d+\.\d+\.\d+)\s*:.*(?:Released|Announced|Released and Retired)\s(?:on\s)?(?P<date>\w+\s\d\d?,\s\d{4})"),
consistent in the past with the wording, it seems better now). # for older 2.0.x versions (only GA versions are considered)
""" re.compile(r"\s+(?P<version>\d+\.\d+\.\d+)\s*:.*released\s(?P<date>\w+\s\d\d?,\s\d{4}) as GA"),
# for older 1.3.x versions, we take the date of the tag and not the date of the release (too difficult to parse)
re.compile(r"\s+(?P<version>\d+\.\d+\.\d+)\s*:.*Tagged and [rR]olled\s(?:on\s)?(?P<date>\w+\.?\s\d\d?,\s\d{4})"),
]
PRODUCT = "apache-http-server" product = endoflife.Product("apache-http-server")
REPO_URL = "https://github.com/apache/httpd.git" print(f"::group::{product.name}")
git = Git("https://github.com/apache/httpd.git")
git.setup()
for branch in git.list_branches("refs/heads/?.?.x"):
git.checkout(branch, file_list=["STATUS"])
def parse(date: str) -> str: release_notes_file = git.repo_dir / "STATUS"
date = date.replace("Feburary", "February")
date = date.replace(". ", " ")
return dates.parse_date(date).strftime("%Y-%m-%d")
def fetch_versions_from_file(release_notes_file: Path, versions: dict):
if not release_notes_file.exists(): if not release_notes_file.exists():
return {} continue
with open(release_notes_file, "rb") as f: with open(release_notes_file, "rb") as f:
plain = f.read().decode("utf-8", errors="ignore") release_notes = f.read().decode("utf-8", errors="ignore")
# for most versions for pattern in VERSION_AND_DATE_PATTERNS:
for (version, date_str) in re.findall(r"\s+(?P<version>\d+\.\d+\.\d+)\s*:.*(?:Released|Announced|Released and Retired)\s(?:on\s)?(?P<date>\w+\s\d\d?,\s\d{4})", plain): for (version, date_str) in pattern.findall(release_notes):
date = parse(date_str) product.declare_version(version, dates.parse_date(date_str))
versions[version] = date
print(f"{version}: {date}")
# for older 2.0.x versions (only GA versions are considered) product.write()
for (version, date_str) in re.findall(r"\s+(?P<version>\d+\.\d+\.\d+)\s*:.*released\s(?P<date>\w+\s\d\d?,\s\d{4}) as GA", plain):
date = parse(date_str)
versions[version] = date
print(f"{version}: {date}")
# for older 1.3.x versions, we take the date of the tag and not the date of the release (too difficult to parse)
for (version, date_str) in re.findall(r"\s+(?P<version>\d+\.\d+\.\d+)\s*:.*Tagged and [rR]olled\s(?:on\s)?(?P<date>\w+\.?\s\d\d?,\s\d{4})", plain):
date = parse(date_str)
versions[version] = date
print(f"{version}: {date}")
git = Git(REPO_URL)
git.setup()
versions = {}
print(f"::group::{PRODUCT}")
for branch in git.list_branches("refs/heads/?.?.x"):
status_file = "STATUS"
git.checkout(branch, file_list=[status_file])
fetch_versions_from_file(git.repo_dir / status_file, versions)
print("::endgroup::") print("::endgroup::")
endoflife.write_releases(PRODUCT, versions)