[aws-lambda] Refactor script (#215)
Make the script more readable, mostly by: - using the endoflife.Product class, - removing the unnecessary use of functions, - a little bit of renaming.
This commit is contained in:
@@ -3,56 +3,48 @@ from common import http
|
|||||||
from common import endoflife
|
from common import endoflife
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
"""Fetch new AWS lambda runtimes from https://docs.aws.amazon.com.
|
"""Fetches AWS lambda runtimes from https://docs.aws.amazon.com.
|
||||||
|
|
||||||
This script does not retrieve release dates, as they are only available
|
This script does not retrieve release dates, as they are only available in release announcements.
|
||||||
in release announcements. Instead, it uses the release dates from the
|
Instead, it uses the release dates from the endoflife.date product file. This has the advantage of
|
||||||
endoflife.date product file. This has the advantage of being warned
|
being warned about new releases, without having releaseDate information (wrongly) updated.
|
||||||
about new releases, without having releaseDate information (wrongly)
|
|
||||||
updated.
|
|
||||||
|
|
||||||
If one day release dates are available in the AWS documentation, it would
|
If one day release dates are available in the AWS documentation, it would be better to make use
|
||||||
be better to make use them though. Note that this would also be unnecessary
|
them though. Note that this would also be unnecessary if it was possible to disable release/latest
|
||||||
if it was possible to disable release / latest release dates updates in the
|
release dates updates in the latest.py script."""
|
||||||
latest.py script.
|
|
||||||
"""
|
|
||||||
|
|
||||||
PRODUCT = 'aws-lambda'
|
|
||||||
URL = 'https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html'
|
|
||||||
|
|
||||||
|
|
||||||
def fetch_product_file_release_date(releaseCycle, product):
|
def get_release_data(product):
|
||||||
if 'releases' in product.keys():
|
try:
|
||||||
for release in product['releases']:
|
return endoflife.load_product(product.name)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f"{product.name} file not found, real release dates will not be used.")
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
def release_date(releaseCycle, releases_data):
|
||||||
|
if 'releases' in releases_data.keys():
|
||||||
|
for release in releases_data['releases']:
|
||||||
if releaseCycle == release['releaseCycle']:
|
if releaseCycle == release['releaseCycle']:
|
||||||
return release['releaseDate'].strftime("%Y-%m-%d")
|
return release['releaseDate']
|
||||||
|
|
||||||
return datetime.now().strftime("%Y-%m-%d")
|
return datetime.now()
|
||||||
|
|
||||||
|
|
||||||
print(f"::group::{PRODUCT}")
|
product = endoflife.Product("aws-lambda")
|
||||||
releases_data = {}
|
print(f"::group::{product.name}")
|
||||||
try:
|
releases_data = get_release_data(product)
|
||||||
releases_data = endoflife.load_product(PRODUCT)
|
response = http.fetch_url("https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html")
|
||||||
except FileNotFoundError:
|
|
||||||
releases_data = {}
|
|
||||||
print(f"{PRODUCT} file not found, real release dates will not be used.")
|
|
||||||
|
|
||||||
versions = {}
|
|
||||||
response = http.fetch_url(URL)
|
|
||||||
soup = BeautifulSoup(response.text, features="html5lib")
|
soup = BeautifulSoup(response.text, features="html5lib")
|
||||||
|
|
||||||
for row in soup.find_all("tr"):
|
for row in soup.find_all("tr"):
|
||||||
cells = row.find_all("td")
|
cells = row.find_all("td")
|
||||||
if len(cells) == 6: # Supported Runtimes
|
if len(cells) != 6 and len(cells) != 5: # 6 = Supported Runtimes, 5 = Unsupported Runtimes
|
||||||
identifier = cells[1].get_text().strip()
|
|
||||||
elif len(cells) == 5: # Unsupported Runtimes
|
|
||||||
identifier = cells[1].get_text().strip()
|
|
||||||
else: # Header rows
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
date = fetch_product_file_release_date(identifier, releases_data)
|
identifier = cells[1].get_text().strip()
|
||||||
versions[identifier] = date
|
date = release_date(identifier, releases_data)
|
||||||
print(f"{identifier}: {date}")
|
product.declare_version(identifier, date)
|
||||||
|
|
||||||
endoflife.write_releases(PRODUCT, versions)
|
product.write()
|
||||||
print("::endgroup::")
|
print("::endgroup::")
|
||||||
|
|||||||
Reference in New Issue
Block a user