Skip to content

Commit

Permalink
Allow overriding the data directory in latest.py (endoflife-date#3690)
Browse files Browse the repository at this point in the history
The directory can be specified in script parameters using the new `-d` or `--data-directory` option.
It is needed to easily run the script against a working branch of the [release-data](https://github.com/endoflife-date/release-data) directory.
  • Loading branch information
marcwrobel authored Oct 7, 2023
1 parent 338c85f commit f3360f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ _data/gke.json
*.code-workspace
node_modules
.DS_Store
.venv
18 changes: 12 additions & 6 deletions _auto/latest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import argparse
import sys
import frontmatter
import json
import os
import re
import datetime
from time import time_ns
from glob import glob
from pathlib import Path
from ruamel.yaml import YAML
Expand All @@ -21,6 +21,7 @@
This is written in Python because the only package that supports writing back YAML with comments is ruamel
"""

DEFAULT_DATA_DIR = '_data/release-data/releases'
DEFAULT_POST_TEMPLATE = """\
---
{metadata}
Expand Down Expand Up @@ -109,7 +110,7 @@ def yaml_to_str(obj):
return output_str.strip()


def update_product(name):
def update_product(data_dir, name):
fn = "products/%s.md" % name
with open(fn, "r+") as f:
yaml = YAML()
Expand All @@ -119,7 +120,7 @@ def update_product(name):
f.seek(0)
_, content = frontmatter.parse(f.read())

fn = "_data/release-data/releases/%s.json" % (name)
fn = "%s/%s.json" % (data_dir, name)
if exists(fn):
with open(fn) as releases_file:
# Entire releases data as a dict
Expand Down Expand Up @@ -209,10 +210,15 @@ def new_version_is_higher(new_version):
# See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-a-multiline-string
github_output("warning<<$EOF\n")

if len(sys.argv) > 1:
update_product(sys.argv[1])
parser = argparse.ArgumentParser(description='Update product releases.')
parser.add_argument('product', nargs='?', help='restrict update to the given product')
parser.add_argument('-d', '--data-dir', default=DEFAULT_DATA_DIR, help='path to the release data directory')
args = parser.parse_args()

if args.product:
update_product(args.data_dir, args.product)
else:
for x in glob("products/*.md"):
update_product(Path(x).stem)
update_product(args.data_dir, Path(x).stem)

github_output("$EOF")

0 comments on commit f3360f2

Please sign in to comment.