Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup for support of generated changelogs #6473

Draft
wants to merge 40 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
93bbc1d
Add MIT licenses
Garanas Oct 8, 2024
daadb85
Add example files that are to be generated
Garanas Oct 8, 2024
22df089
Move files into a separate folder
Garanas Oct 8, 2024
578fcd7
Update reference
Garanas Oct 8, 2024
336d3e8
Add dummy changelogs
Garanas Oct 8, 2024
be75a3a
Rework the changelog dialog to support the new setup
Garanas Oct 8, 2024
5f214b8
Log imports for testing
Garanas Oct 8, 2024
6565339
Remove the changelog data file
Garanas Oct 8, 2024
7d7bc2e
Fix typo in dummy changelog
Garanas Oct 8, 2024
1e592fd
Add auto-reload functionality
Garanas Oct 8, 2024
197718d
Rename the file
Garanas Oct 8, 2024
5cd7bf4
Improve developer experience
Garanas Oct 8, 2024
76d40ab
Remove annotations of the old changelog format
Garanas Oct 8, 2024
1fd942f
Add push event
Garanas Nov 13, 2024
55f2458
Copy other python file to make overview
Garanas Nov 13, 2024
7239df9
Clean up unused references
Garanas Nov 13, 2024
4f1f2af
Take into account generated workflows
Garanas Nov 13, 2024
591d633
Remove separate overview file
Garanas Nov 13, 2024
6db96d7
Convert a folder of markdown files to a folder of Lua files
Garanas Nov 13, 2024
3023fe6
Interpret the front matter
Garanas Nov 13, 2024
b17dd79
Generate an overview file
Garanas Nov 13, 2024
0f70be7
Add header that indicates the file is generated in the overview
Garanas Nov 13, 2024
3bd44e5
Add documentation
Garanas Nov 13, 2024
6702e7c
Generate a separate header for the overview file
Garanas Nov 13, 2024
96fb929
Separate python file to generate the header
Garanas Nov 13, 2024
f12567a
Fix the URL
Garanas Nov 13, 2024
bd1ed3f
Optionally download generated changelog
Garanas Nov 13, 2024
617b97f
Test setup for FAF Develop
Garanas Nov 13, 2024
c1b6777
Fix typo in syntax
Garanas Nov 13, 2024
e8342b2
Add dependencies
Garanas Nov 13, 2024
5d89529
Try merge multiple
Garanas Nov 13, 2024
b88b988
Fix name of artifact
Garanas Nov 13, 2024
f27533e
Prevent staging generated changelog files
Garanas Nov 13, 2024
2271f82
Sort the entries for the overview
Garanas Nov 15, 2024
e5d7c5c
Make changelog dialog more robust
Garanas Nov 15, 2024
76fc795
Add major/minor patch field
Garanas Nov 15, 2024
446b92c
Include name and patch in overview
Garanas Nov 15, 2024
b36a09d
Add fields and capitalize the keys
Garanas Nov 15, 2024
69e875e
Only include patch name, no version (that is part of the name)
Garanas Nov 15, 2024
6a52742
Add 'Online' button, remove others
Garanas Nov 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 46 additions & 13 deletions .github/workflows/deploy-fafdevelop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,31 @@ concurrency:
group: deployment

on:
push:
workflow_dispatch:
schedule:
- cron: "0 21 * * 4"

jobs:
test:
uses: ./.github/workflows/test.yaml

changelog:
name: Create changelog of FAF Develop
uses: ./.github/workflows/docs-changelog.yaml
with:
reference: deploy/fafdevelop

changelog-lua:
name: Convert changelogs to Lua
needs: [changelog]
uses: ./.github/workflows/docs-convert-changelog.yaml
with:
artifact: fafdevelop

update:
name: Update FAF Develop
needs: [test]
needs: [test, changelog-lua]
runs-on: ubuntu-latest
steps:
# https://github.com/actions/checkout/tree/v4/
Expand Down Expand Up @@ -68,18 +83,36 @@ jobs:
# debugging
cat lua/shared/components/DebugComponent.lua

# Create a commit with the changes of the workflow in it
- name: Create a commit
- name: Clear dummy logs
run: |
# Configure git
git config user.email "[email protected]"
git config user.name "FAForever Machine User"
rm -f lua/ui/lobby/changelog/generated/*

git add .
git commit -m "Post-process deployment"
# Retrieve the generated changelogs
- name: Download lua changelogs
uses: actions/download-artifact@v4
with:
name: lua_changelog
path: lua/ui/lobby/changelog/generated

# Update the deploy/fafdevelop branch, we force push here because
# we're not interested in fixing conflicts
- name: Update deploy/fafdevelop
run: |
git push origin HEAD:deploy/fafdevelop --force
- name: Add the changelog as an artifact
uses: actions/upload-artifact@v4
with:
name: lua
path: |
lua/ui/lobby

# # Create a commit with the changes of the workflow in it
# - name: Create a commit
# run: |
# # Configure git
# git config user.email "[email protected]"
# git config user.name "FAForever Machine User"

# git add .
# git commit -m "Post-process deployment"

# # Update the deploy/fafdevelop branch, we force push here because
# # we're not interested in fixing conflicts
# - name: Update deploy/fafdevelop
# run: |
# git push origin HEAD:deploy/fafdevelop --force
46 changes: 28 additions & 18 deletions .github/workflows/docs-convert-changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,12 @@
name: Convert Markdown changelog to Lua

on:
push:
workflow_dispatch:
inputs:
reference:
required: true
type: choice
description: The reference (branch or tag) to use to compile the changelog snippets from
options:
- develop
- deploy/fafbeta
- deploy/fafdevelop

workflow_call:
inputs:
reference:
required: true
type: string
artifact:
type: string # fafdevelop or fafbeta
description: The reference (branch or tag) to use to compile the changelog snippets from

jobs:
Expand All @@ -54,6 +44,23 @@ jobs:
sparse-checkout: |
${{ env.SCRIPTS }}
changelog
docs

- name: Download develop artifact
if: inputs.artifact == 'fafdevelop'
uses: actions/download-artifact@v4
with:
name: changelog-fafdevelop
path: docs/_posts
merge-multiple: true

- name: Download balance artifact
if: inputs.artifact == 'fafbeta'
uses: actions/download-artifact@v4
with:
name: changelog-fafbeta
path: docs/_posts
merge-multiple: true

- name: Setup python
uses: actions/setup-python@v5
Expand All @@ -68,11 +75,14 @@ jobs:
- name: Convert changelog to Lua
run: |
out_dir=lua_changelog
mkdir $out_dir
for file in changelog/*.md; do
out_file=$(basename ${file%.md}.lua)
python3 $SCRIPTS/changelog_markdown2lua.py "${file}" "${out_dir}/${out_file}"
done
mkdir -p $out_dir
python3 $SCRIPTS/changelog_markdown2lua.py "docs/_posts" "${out_dir}"

- name: Create changelog overview in Lua
run: |
out_dir=lua_changelog
mkdir -p $out_dir
python3 $SCRIPTS/changelog_overview.py "docs/_posts" "${out_dir}/overview.lua"

- name: Add the Lua changelog as an artifact
uses: actions/upload-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/scripts/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ python script_name.py

# Deactivate the Virtual Environment
deactivate
```
61 changes: 49 additions & 12 deletions .github/workflows/scripts/python/changelog_markdown2lua.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
"""
This script converts markdown changelog files into Lua files.

The script processes a directory of markdown files, extracting YAML front matter and converting
each markdown file into a corresponding Lua file.
"""

import mdformat
import yaml

from argparse import ArgumentParser
from pathlib import Path
Expand All @@ -22,26 +30,27 @@
--{f"This file was autogenerated using {SCRIPT_NAME:}":^{HEADER_LINE_CENTER}}--
--{{source:^{HEADER_LINE_CENTER}}}--
{HEADER_SEPARATOR}

"""


def get_parser():
ap = ArgumentParser(description="Converts Markdown release file to Lua.")
"""Sets up the argument parser for command line execution."""
ap = ArgumentParser(description="Converts Markdown release files in a folder to Lua files.")
ap.add_argument(
"input_file",
help="Markdown file",
"input_dir",
help="Directory containing markdown files",
type=Path,
)
ap.add_argument(
"output_file",
help="Lua file",
"output_dir",
help="Directory to save converted Lua files",
type=Path,
)
return ap


def convert_changelog(markdown: Path, lua: Path):
"""Converts a single markdown file to a Lua file."""
version = markdown.stem

source_info = f"Source: {markdown}"
Expand All @@ -51,27 +60,55 @@ def convert_changelog(markdown: Path, lua: Path):


def markdown2lua(version: str, content: str) -> str:
"""Converts markdown content to Lua format, excluding YAML front matter."""
yaml_content, markdown_content = extract_yaml_front_matter(content)
formatted_md = mdformat.text(
content,
markdown_content,
options={
"wrap": MAX_LINE_LENGTH,
},
)

escaped_md = escape_special_symbols(formatted_md)
lua_description = ",\n".join(
LUA_DESC_LINE.format(line=line) for line in escaped_md.splitlines()
)

# YAML content is read and available here, but not added to the output yet.
yaml_data = yaml.safe_load(yaml_content) if yaml_content else {}

return LUA_FILE.format(
version=version,
description=",\n".join(
LUA_DESC_LINE.format(line=line) for line in escaped_md.splitlines()
),
Name = yaml_data.get('title', 'Unknown'),
Patch = yaml_data.get('patch', 'Unknown'),
Version=version,
Description=lua_description,
)


def extract_yaml_front_matter(content: str) -> (str, str):
"""Extracts YAML front matter from markdown content."""
if content.startswith('---'):
end = content.find('---', 3)
if end != -1:
yaml_content = content[3:end].strip()
rest_of_content = content[end+3:].strip()
return yaml_content, rest_of_content
return '', content


def escape_special_symbols(text: str) -> str:
"""Escapes special symbols in text for Lua compatibility."""
return text.replace("\\", "\\\\").replace('"', '\\"')


def convert_changelog_folder(input_dir: Path, output_dir: Path):
"""Converts all markdown files in a directory to Lua files."""
for markdown_file in input_dir.glob("*.md"):
lua_file = output_dir / (markdown_file.stem + ".lua")
convert_changelog(markdown_file, lua_file)


if __name__ == "__main__":
parser = get_parser()
args = parser.parse_args()
convert_changelog(args.input_file, args.output_file)
convert_changelog_folder(args.input_dir, args.output_dir)
96 changes: 96 additions & 0 deletions .github/workflows/scripts/python/changelog_overview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""
This script generates an overview Lua file listing all changelogs with metadata.

The script processes a directory of markdown files, extracting metadata from the file names and
YAML front matter to create an overview file listing all converted changelogs with their version,
name, date, URL, and path.
"""

import yaml
from pathlib import Path

MAX_LINE_LENGTH = 150

HEADER_SEPARATOR = "--" * (MAX_LINE_LENGTH // len("--"))
HEADER_LINE_CENTER = MAX_LINE_LENGTH - 2 * len("--")
SCRIPT_NAME = Path(__file__).name

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


def extract_yaml_front_matter(content: str) -> (str, str):
"""Extracts YAML front matter from markdown content."""
if content.startswith('---'):
end = content.find('---', 3)
if end != -1:
yaml_content = content[3:end].strip()
rest_of_content = content[end+3:].strip()
return yaml_content, rest_of_content
return '', content


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 {}

name = yaml_data.get('title', 'Unknown')
patch = yaml_data.get('patch', 'Unknown')

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

# Sort the entries by version in reverse order
overview_entries.sort(key=lambda entry: entry['Version'], reverse=True)

overview_content = OVERVIEW_HEADER + """
---@type UIChangelogOverview
Overview = {
Changelogs = {
"""
for entry in overview_entries:
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"
overview_content += " }\n}\n"

output_file.write_text(overview_content)


def main():
import argparse

parser = argparse.ArgumentParser(description="Generate an overview Lua file for changelogs.")
parser.add_argument("input_dir", type=Path, help="Directory containing markdown files")
parser.add_argument("output_file", type=Path, help="Output Lua file path")
args = parser.parse_args()

create_overview_file(args.input_dir, args.output_file)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions .github/workflows/scripts/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mdformat==0.7.17
pyyaml>=3.10
1 change: 1 addition & 0 deletions docs/_posts/2014-12-12-3636.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
layout: post
patch: "Major"
title: Game version 3636
permalink: changelog/3636
---
Expand Down
1 change: 1 addition & 0 deletions docs/_posts/2014-12-12-3637.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
layout: post
patch: "Minor"
title: Game version 3637
permalink: changelog/3637
---
Expand Down
1 change: 1 addition & 0 deletions docs/_posts/2014-12-24-3638.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
layout: post
patch: "Minor"
title: Game version 3638
permalink: changelog/3638
---
Expand Down
1 change: 1 addition & 0 deletions docs/_posts/2015-02-05-3639.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
layout: post
patch: "Major"
title: Game version 3639
permalink: changelog/3639
---
Expand Down
Loading
Loading