[splunk] Refactor script (#249)

Make the script more readable, mostly by:

- using the Product class,
- a little bit of renaming and documentation.
This commit is contained in:
Marc Wrobel
2023-12-12 07:42:28 +01:00
committed by GitHub
parent d49923887c
commit 56591af370

View File

@@ -4,14 +4,11 @@ from common import http
from common import dates
from common import endoflife
PRODUCT = "splunk"
URL = "https://docs.splunk.com/Documentation/Splunk"
RELNOTES_URL_TEMPLATE = "https://docs.splunk.com/Documentation/Splunk/{version}/ReleaseNotes/MeetSplunk"
PATTERN = r"Splunk Enterprise (?P<version>\d+\.\d+(?:\.\d+)*) was (?:first )?released on (?P<date>\w+\s\d\d?,\s\d{4})\."
VERSION_DATE_PATTERN = re.compile(r"Splunk Enterprise (?P<version>\d+\.\d+(?:\.\d+)*) was (?:first )?released on (?P<date>\w+\s\d\d?,\s\d{4})\.", re.MULTILINE)
def get_latest_minor_versions(versions):
versions_split = [version.split('.') for version in versions]
versions_split = [v.split('.') for v in versions]
# Group versions by major and minor version
version_groups = {}
@@ -34,27 +31,22 @@ def get_latest_minor_versions(versions):
return latest_versions
print(f"::group::{PRODUCT}")
versions = dict()
main = http.fetch_url(URL)
product = endoflife.Product("splunk")
print(f"::group::{product.name}")
main = http.fetch_url("https://docs.splunk.com/Documentation/Splunk")
soup = BeautifulSoup(main.text, features="html5lib")
all_versions = list(map(
lambda option: option.attrs['value'],
soup.select("select#version-select > option")
))
all_versions = list(map(lambda option: option.attrs['value'], soup.select("select#version-select > option")))
# Latest minor release notes contains release notes for all previous minor versions.
# For example, 9.0.5 release notes also contains release notes for 9.0.0 to 9.0.4.
latest_minor_versions = get_latest_minor_versions(all_versions)
latest_minor_versions_urls = [RELNOTES_URL_TEMPLATE.format(version=v) for v in latest_minor_versions]
latest_minor_versions_urls = [f"https://docs.splunk.com/Documentation/Splunk/{v}/ReleaseNotes/MeetSplunk" for v in latest_minor_versions]
for response in http.fetch_urls(latest_minor_versions_urls):
for (version, date_str) in re.findall(PATTERN, response.text, re.MULTILINE):
for (version, date_str) in VERSION_DATE_PATTERN.findall(response.text):
version = f"{version}.0" if len(version.split(".")) == 2 else version # convert x.y to x.y.0
date = dates.parse_date(date_str).strftime("%Y-%m-%d")
versions[version] = date
print(f"{version}: {date}")
date = dates.parse_date(date_str)
product.declare_version(version, date)
endoflife.write_releases(PRODUCT, versions)
product.write()
print("::endgroup::")