Skip to content

Commit

Permalink
Generate a separate header for the overview file
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas committed Nov 13, 2024
1 parent 3bd44e5 commit 6702e7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/docs-convert-changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@ jobs:
run: |
out_dir=lua_changelog
mkdir -p $out_dir
python3 $SCRIPTS/changelog_markdown2lua.py changelog "${out_dir}"
# - name: Create an overview file
# run: |
# out_dir=lua_changelog
# mkdir -p $out_dir
# python3 $SCRIPTS/changelog_overview.py "changelog" "${out_dir}/overview.lua"
python3 $SCRIPTS/changelog_markdown2lua.py "docs/_posts" "${out_dir}"
- name: Add the Lua changelog as an artifact
uses: actions/upload-artifact@v4
Expand Down
20 changes: 17 additions & 3 deletions .github/workflows/scripts/python/changelog_markdown2lua.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@
HEADER_SEPARATOR = "--" * (MAX_LINE_LENGTH // len("--"))
HEADER_LINE_CENTER = MAX_LINE_LENGTH - 2 * len("--")
HEADER = f"""{HEADER_SEPARATOR}
--{{f"This file was autogenerated using {SCRIPT_NAME:}":^{HEADER_LINE_CENTER}}}--
--{f"This file was autogenerated using {SCRIPT_NAME:}":^{HEADER_LINE_CENTER}}--
--{{source:^{HEADER_LINE_CENTER}}}--
{HEADER_SEPARATOR}
"""

OVERVIEW_HEADER = f"""{HEADER_SEPARATOR}
--{f'This file was autogenerated using {SCRIPT_NAME}':^{HEADER_LINE_CENTER}}--
{HEADER_SEPARATOR}
"""


def get_parser():
"""Sets up the argument parser for command line execution."""
Expand Down Expand Up @@ -104,21 +109,29 @@ def create_overview_file(input_dir: Path, output_file: Path):
"""Creates an overview Lua file listing all changelogs with metadata."""
overview_entries = []
for markdown_file in input_dir.glob("*.md"):
# Extract date from the file name if it matches the expected format
file_name_parts = markdown_file.stem.split('-')
if len(file_name_parts) != 4:
continue

date = '-'.join(file_name_parts[:3])
version = file_name_parts[3]

yaml_content, _ = extract_yaml_front_matter(markdown_file.read_text())
yaml_data = yaml.safe_load(yaml_content) if yaml_content else {}

version = yaml_data.get('version', markdown_file.stem)
name = yaml_data.get('name', 'Unknown')

entry = {
'Version': version,
'Name': name,
'Date': date,
'URL': f"http://faforever.github.io/fa/{version}",
'Path': f"/lua/ui/lobby/changelog/generated/{markdown_file.stem}.lua"
}
overview_entries.append(entry)

overview_content = HEADER.format(source='Overview Generation Script') + """
overview_content = OVERVIEW_HEADER + """
---@type UIChangelogOverview
Overview = {
Changelogs = {
Expand All @@ -127,6 +140,7 @@ def create_overview_file(input_dir: Path, output_file: Path):
overview_content += " {\n"
overview_content += f" Version = {entry['Version']},\n"
overview_content += f" Name = \"{entry['Name']}\",\n"
overview_content += f" Date = \"{entry['Date']}\",\n"
overview_content += f" URL = \"{entry['URL']}\",\n"
overview_content += f" Path = \"{entry['Path']}\"\n"
overview_content += " },\n"
Expand Down

0 comments on commit 6702e7c

Please sign in to comment.