Skip to content

Commit

Permalink
Migrate latest.py from endoflife.date to release-data (#4313)
Browse files Browse the repository at this point in the history
It makes more sense as it is closely linked to the JSON version file format, which is more subject to change than the product file format.

Also took the opportunity to refactor the bulk_update.py script.
  • Loading branch information
marcwrobel authored Dec 16, 2023
1 parent 79208bd commit 68bfaa0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 255 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/auto-merge-release-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ jobs:
python-version: '3.11'

- name: Install Python Dependencies
run: pip install -r requirements.txt
run: pip install -r '_data/release-data/requirements.txt'

- id: latest
name: Update latest releases
run: python _auto/latest.py -p 'products/' -d '_data/release-data/releases'
run: python '_data/release-data/latest.py' -p 'products/' -d '_data/release-data/releases'

- name: Update latest and latestReleaseDate
uses: stefanzweifel/git-auto-commit-action@v5
Expand Down
70 changes: 22 additions & 48 deletions _auto/bulk-update.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,38 @@
import sys
import frontmatter
import json
import re
import datetime
from glob import glob
from pathlib import Path
from distutils.version import StrictVersion
from ruamel.yaml import YAML
from io import StringIO
from os.path import exists
from ruamel.yaml.resolver import Resolver

DEFAULT_POST_TEMPLATE = """\
---
{metadata}
---

{content}
"""
"""Helper script that can be used to bulk-update product files."""


def yaml_to_str(obj):
yaml = YAML()
yaml.indent(sequence=4)
string_stream = StringIO()
yaml.dump(obj, string_stream)
output_str = string_stream.getvalue()
string_stream.close()
return output_str
def update(yaml_frontmatter):
return yaml_frontmatter


"""
Takes a product dict
and return the updated version
"""
# Force YAML to format version numbers as strings, see https://stackoverflow.com/a/71329221/368328.
Resolver.add_implicit_resolver("tag:yaml.org,2002:string", re.compile(r"\d+(\.\d+){0,3}", re.X), list(".0123456789"))


def update(obj):
return obj


def update_product(name):
fn = "products/%s.md" % name
print(name)
with open(fn, "r+") as f:
for product_path in glob("products/*.md"):
with open(product_path, "r+") as product_file:
# Read YAML
yaml = YAML()
yaml.preserve_quotes = True
data = next(yaml.load_all(f))
f.seek(0)
_, content = frontmatter.parse(f.read())
yaml.indent(sequence=4)
data = next(yaml.load_all(product_file))
product_file.seek(0)
_, content = frontmatter.parse(product_file.read())

print(f"Updating {product_path}...")
data = update(data)
final_contents = DEFAULT_POST_TEMPLATE.format(
metadata=yaml_to_str(data), content=content
)

f.seek(0)
f.truncate()
f.write(final_contents)


if __name__ == "__main__":
for x in glob("products/*.md"):
update_product(Path(x).stem)
# Read updated YAML
product_file.seek(0)
product_file.truncate()
product_file.write("---\n")
yaml.dump(data, product_file)
product_file.write("\n---\n\n")
product_file.write(content)
product_file.write("\n")
4 changes: 2 additions & 2 deletions _auto/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ echo "Deploy URL: $1"

# See https://github.com/endoflife-date/endoflife.date/pull/2081
echo "Updating latest product information..."
pip install -r requirements.txt
pip install -r '_data/release-data/requirements.txt'
git submodule update --remote
if ! python3 '_auto/latest.py' -p 'products/' -d '_data/release-data/releases'; then # if the latest.py script fails...
if ! python3 '_data/release-data/latest.py' -p 'products/' -d '_data/release-data/releases'; then # if the latest.py script fails...
git checkout -- products/ # ...just undo the changes, and carry on
fi

Expand Down
202 changes: 0 additions & 202 deletions _auto/latest.py

This file was deleted.

1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
python-frontmatter==1.0.1
ruamel.yaml==0.18.5
ruamel.yaml.clib==0.2.8
packaging==23.2

0 comments on commit 68bfaa0

Please sign in to comment.