diff --git a/.github/workflows/create-pr.sh b/.github/workflows/create-pr.sh new file mode 100644 index 0000000000..eb8c00324f --- /dev/null +++ b/.github/workflows/create-pr.sh @@ -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 diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml new file mode 100644 index 0000000000..92b2c8dca8 --- /dev/null +++ b/.github/workflows/documentation.yml @@ -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: 'foe@elunatech.com' + USER_NAME: 'Foereaper' diff --git a/docs/ElunaDoc/__main__.py b/docs/ElunaDoc/__main__.py index 7da996bc05..d02c1b2581 100644 --- a/docs/ElunaDoc/__main__.py +++ b/docs/ElunaDoc/__main__.py @@ -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`. @@ -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): @@ -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() @@ -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) diff --git a/docs/ElunaDoc/parser.py b/docs/ElunaDoc/parser.py index 90b9c7718e..471c87f766 100644 --- a/docs/ElunaDoc/parser.py +++ b/docs/ElunaDoc/parser.py @@ -1,5 +1,5 @@ import re -from types import FileType +import typing import markdown from typedecorator import params, returns, Nullable @@ -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 @@ -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 @@ -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. @@ -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".