|
| 1 | +__author__ = "Ariel Otilibili <[email protected]>" |
| 2 | +__copyright__ = "Copyright (c) 2025 Ariel Otilibili" |
| 3 | +__license__ = "MIT" |
| 4 | + |
| 5 | +import json |
| 6 | +import requests |
| 7 | +import re |
| 8 | + |
| 9 | +from bs4 import BeautifulSoup |
| 10 | + |
| 11 | +URL = "https://packages.debian.org/search?keywords=erlang" |
| 12 | +WORKFLOW = ".github/workflows/main.yml" |
| 13 | + |
| 14 | + |
| 15 | +def get_webpage_in_html(url): |
| 16 | + response = requests.get(url) |
| 17 | + return BeautifulSoup(response.content) |
| 18 | + |
| 19 | + |
| 20 | +def get_latest_otp_versions(webpage): |
| 21 | + # Samples of expected 'li' elements: |
| 22 | + # |
| 23 | + # <li class="bullseye"><a class="resultlink" href="/bullseye/erlang">bullseye (oldstable)</a> (interpreters): |
| 24 | + # Concurrent, real-time, distributed functional language |
| 25 | + # |
| 26 | + # <br/>1:23.2.6+dfsg-1+deb11u2 [<strong class="pmarker" title="">security</strong>]: all |
| 27 | + # |
| 28 | + # |
| 29 | + # </li> |
| 30 | + # <li class="bookworm"><a class="resultlink" href="/bookworm/erlang">bookworm (stable)</a> (interpreters): |
| 31 | + # Concurrent, real-time, distributed functional language |
| 32 | + # |
| 33 | + # <br/>1:25.2.3+dfsg-1+deb12u1: all |
| 34 | + # |
| 35 | + # |
| 36 | + # </li> |
| 37 | + HEADER = "Concurrent, real-time, distributed functional language" |
| 38 | + OTP_REGEX = r"1:(\d+)" |
| 39 | + |
| 40 | + versions = { |
| 41 | + m.group(1) |
| 42 | + for p in webpage.find_all("li") |
| 43 | + if re.search(HEADER, p.text) |
| 44 | + and not re.search("security", p.text) |
| 45 | + and (m := re.search(OTP_REGEX, p.text)) |
| 46 | + } |
| 47 | + |
| 48 | + return sorted(list(versions), reverse=True) |
| 49 | + |
| 50 | + |
| 51 | +def update_otp_versions(versions, workflow): |
| 52 | + otp_versions = ", ".join(f"'{version}'" for version in versions) |
| 53 | + |
| 54 | + with open(workflow) as ci: |
| 55 | + conf = ci.read() |
| 56 | + |
| 57 | + conf = re.sub("(otp_version: ).*\n", "\\1" + f"[{otp_versions}]" + "\n", conf) |
| 58 | + |
| 59 | + with open(workflow, "w") as ci: |
| 60 | + ci.write(conf) |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == "__main__": |
| 64 | + webpage = get_webpage_in_html(URL) |
| 65 | + versions = get_latest_otp_versions(webpage) |
| 66 | + update_otp_versions(versions, WORKFLOW) |
| 67 | + |
| 68 | + print(json.dumps({"source": URL, "versions": versions, "file-changed": WORKFLOW})) |
0 commit comments