Improve and fix haproxy.py

- Get cycles URL by parsing https://www.haproxy.org/download/:
  - This way the script does not have to be updated each time a new minor version is released.
  - The old algorithm was missing some versions (such as 1.6.x).
- Use a GitHub actions log group to wrap the script logs.
- Display version like the other scripts.
This commit is contained in:
Marc Wrobel
2023-01-08 14:30:09 +01:00
parent a78de5f188
commit 803a8be040

View File

@@ -2,21 +2,73 @@ import json
import re
import urllib.request
from bs4 import BeautifulSoup
"""Fetch HAProxy versions with their dates from https://www.haproxy.org/download/.
"""
PRODUCT = "haproxy"
CYCLE_REGEX = r"^(\d+\.\d+)/$"
# https://regex101.com/r/1JCnFC/1
REGEX = r"^(\d{4})\/(\d{2})\/(\d{2})\s+:\s+(\d+\.\d+\.\d.?)$"
VERSION_REGEX = r"^(\d{4})\/(\d{2})\/(\d{2})\s+:\s+(\d+\.\d+\.\d.?)$"
versions = {}
for i in range(17, 28):
url = "https://www.haproxy.org/download/%s/src/CHANGELOG" % (i / 10)
print(url)
with urllib.request.urlopen(url) as response:
for line in response:
m = re.match(REGEX, line.decode("utf-8"))
def fetch_cycles():
cycles = []
print("Fetching cycles")
with urllib.request.urlopen(
"https://www.haproxy.org/download/") as response:
soup = BeautifulSoup(response, features="html5lib")
for link in soup.select("a"):
m = re.match(CYCLE_REGEX, link.attrs["href"])
if m:
year, month, date, version = m.groups()
abs_date = "%s-%s-%s" % (year, month, date)
versions[version] = abs_date
cycle = m.groups()[0]
cycles.append(cycle)
print(f"Found {cycle}")
with open("releases/haproxy.json", "w") as f:
f.write(json.dumps(versions, indent=2))
# No changelog in https://www.haproxy.org/download/1.0/src
cycles.remove("1.0")
return cycles
def fetch_releases(cycles):
releases = {}
for cycle in cycles:
url = f"https://www.haproxy.org/download/{cycle}/src/CHANGELOG"
print(f"Fetching version from {url}")
with urllib.request.urlopen(url) as response:
for line in response:
m = re.match(VERSION_REGEX, line.decode("utf-8"))
if m:
year, month, day, version = m.groups()
date = f"{year}-{month}-{day}"
releases[version] = date
return releases
def print_releases(releases):
# Do not print versions in fetch_releases because it contains duplicates
for version, date in releases.items():
print(f"{version} : {date}")
def main():
print(f"::group::{PRODUCT}")
cycles = fetch_cycles()
releases = fetch_releases(cycles)
print_releases(releases)
print("::endgroup::")
with open(f"releases/{PRODUCT}.json", "w") as f:
f.write(json.dumps(dict(
# sort by date then version (desc)
sorted(releases.items(), key=lambda x: (x[1], x[0]), reverse=True)
), indent=2))
if __name__ == '__main__':
main()