Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Foereaper committed Jan 18, 2024
2 parents dd105d3 + 64af481 commit 3331547
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 13 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/create-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Adapted from https://github.com/paygoc6/action-pull-request-another-repo

CLONE_DIR=$(mktemp -d)

echo "Setting git variables"
export GITHUB_TOKEN=$API_TOKEN_GITHUB
git config --global user.email "$USER_EMAIL"
git config --global user.name "$USER_NAME"

date=$(date '+%Y-%m-%d_%H-%M')
DESTINATION_HEAD_BRANCH="$DESTINATION_HEAD_BRANCH-$date"

echo "Cloning destination git repository"
git clone "https://$API_TOKEN_GITHUB@github.com/$DESTINATION_REPO.git" "$CLONE_DIR"
cd "$CLONE_DIR"
git checkout "$DESTINATION_BASE_BRANCH"
git pull origin "$DESTINATION_BASE_BRANCH"
git checkout -b "$DESTINATION_HEAD_BRANCH"

echo "Copying contents to git repo"
mkdir -p "$CLONE_DIR/$DESTINATION_FOLDER"
cp -r "$SOURCE_FOLDER/." "$CLONE_DIR/$DESTINATION_FOLDER/"

echo "Adding files"
git add .
echo "Git status:"
git status -- ":!date.js"
if git status -- ":!date.js" | grep -q "Changes to be committed"
then
echo "Adding git commit"
git commit -m "$COMMIT_MESSAGE"
echo "Pushing git commit"
git push -u origin "$DESTINATION_HEAD_BRANCH"
echo "Creating a pull request"
gh pr create -t "$PR_TITLE" \
-B "$DESTINATION_BASE_BRANCH" \
-b "" \
-H "$DESTINATION_HEAD_BRANCH"
else
echo "No changes detected"
fi
38 changes: 38 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: documentation
on:
push:
branches:
- 'main'
- 'master'
jobs:
Push-Docs-To-Website:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
architecture: 'x64'
- name: Install Python dependencies
run: pip install jinja2 typedecorator markdown
- name: Compile documentation
run: |
cd ${{ github.workspace }}/docs/
python -m ElunaDoc
- name: Create pull request
run: |
chmod +x "${GITHUB_WORKSPACE}/.github/workflows/create-pr.sh"
"${GITHUB_WORKSPACE}/.github/workflows/create-pr.sh"
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
SOURCE_FOLDER: '${{ github.workspace }}/docs/build'
DESTINATION_REPO: 'elunaluaengine/elunaluaengine.github.io'
DESTINATION_FOLDER: ''
DESTINATION_BASE_BRANCH: 'master'
DESTINATION_HEAD_BRANCH: 'master'
PR_TITLE: 'Update Eluna documentation'
COMMIT_MESSAGE: 'Update Eluna documentation'
USER_EMAIL: '[email protected]'
USER_NAME: 'Foereaper'
14 changes: 7 additions & 7 deletions docs/ElunaDoc/__main__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
import shutil
from types import FileType
import typing
from jinja2 import Environment, FileSystemLoader
from typedecorator import params, returns
from parser import ClassParser, MethodDoc
from ElunaDoc.parser import ClassParser, MethodDoc
import glob
import time


@returns([(str, FileType)])
@returns([(str, typing.IO)])
@params(search_path=str)
def find_class_files(search_path):
"""Find and open all files containing Eluna class methods in `search_path`.
Expand All @@ -32,7 +32,7 @@ def make_renderer(template_path, link_parser_factory):
"""Return a function that can be used to render Jinja2 templates from the `template_path` directory."""

# Set up jinja2 environment to load templates from the templates folder.
env = Environment(loader=FileSystemLoader(template_path), extensions=['jinja2.ext.with_'])
env = Environment(loader=FileSystemLoader(template_path))


def inner(template_name, output_path, level, **kwargs):
Expand Down Expand Up @@ -64,13 +64,13 @@ def make_root(level):

# Load up all files with methods we need to parse.
# Hard-coded to the TC files for now. Will have to add core support later on.
print 'Finding Eluna method files...'
print('Finding Eluna method files...')
class_files = find_class_files('../TrinityCore/')

# Parse all the method files.
classes = []
for f in class_files:
print 'Parsing file {}...'.format(f.name)
print(f'Parsing file {f.name}...')
classes.append(ClassParser.parse_file(f))
f.close()

Expand Down Expand Up @@ -156,7 +156,7 @@ def data_type_parser(content):
render('date.js', 'date.js', level=0, currdate=time.strftime("%d/%m/%Y"))

for class_ in classes:
print 'Rending pages for class {}...'.format(class_.name)
print(f'Rendering pages for class {class_.name}...')

# Make a folder for the class.
os.mkdir('build/' + class_.name)
Expand Down
12 changes: 6 additions & 6 deletions docs/ElunaDoc/parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from types import FileType
import typing
import markdown
from typedecorator import params, returns, Nullable

Expand All @@ -23,7 +23,7 @@ class ParameterDoc(object):
'ObjectGuid': ('0', '18,446,744,073,709,551,615'),
}

@params(self=object, name=Nullable(unicode), data_type=str, description=unicode, default_value=Nullable(unicode))
@params(self=object, name=Nullable(str), data_type=str, description=str, default_value=Nullable(str))
def __init__(self, name, data_type, description, default_value=None):
"""If `name` is not provided, the Parameter is a returned value instead of a parameter."""
self.name = name
Expand Down Expand Up @@ -59,12 +59,12 @@ def __init__(self, name, data_type, description, default_value=None):
self.data_type = '[' + self.data_type + ']'

elif not self.data_type in ['nil', 'boolean', 'number', 'string', 'table', 'function', '...'] and self.data_type[:1] != '[':
print "Missing angle brackets [] around the data type name: `" + self.data_type + "`"
print(f"Missing angle brackets [] around the data type name: `{self.data_type}`")


class MethodDoc(object):
"""The documentation data of an Eluna method."""
@params(self=object, name=unicode, description=unicode, prototypes=[unicode], parameters=[ParameterDoc], returned=[ParameterDoc])
@params(self=object, name=str, description=str, prototypes=[str], parameters=[ParameterDoc], returned=[ParameterDoc])
def __init__(self, name, description, prototypes, parameters, returned):
self.name = name
self.prototypes = prototypes
Expand All @@ -81,7 +81,7 @@ def __init__(self, name, description, prototypes, parameters, returned):

class MangosClassDoc(object):
"""The documentation of a MaNGOS class that has Lua methods."""
@params(self=object, name=unicode, description=unicode, methods=[MethodDoc])
@params(self=object, name=str, description=str, methods=[MethodDoc])
def __init__(self, name, description, methods):
self.name = name
# Parse the description as Markdown.
Expand Down Expand Up @@ -317,7 +317,7 @@ def to_class_doc(self):

@staticmethod
@returns(MangosClassDoc)
@params(file=FileType)
@params(file=typing.IO)
def parse_file(file):
"""Parse the file `file` into a documented class."""
# Get the class name from "ClassMethods.h" by stripping off "Methods.h".
Expand Down

0 comments on commit 3331547

Please sign in to comment.