Skip to content

Commit

Permalink
Merge pull request #1 from raverank/github-action
Browse files Browse the repository at this point in the history
Introduce Github Action to run Manki
  • Loading branch information
raverank committed Nov 21, 2022
2 parents 24cf9c5 + cf8ddd7 commit 77e2aef
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tests/**
.vscode/**
action.yml
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,5 @@ cython_debug/
.idea/inspectionProfiles/profiles_settings.xml
.idea/inspectionProfiles/Project_Default.xml
.vscode/settings.json

.DS_Store
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM python:3.9-alpine

# RUN adduser -D mankiuser
# USER mankiuser
# ENV PATH="/home/mankiuser/.local/bin:${PATH}"

# WORKDIR /home/mankiuser/app

# COPY --chown=mankiuser:mankiuser requirements.txt .
# RUN chmod -R 777 .
# RUN /usr/local/bin/python -m pip install --upgrade pip
# RUN pip install --user -r requirements.txt

# COPY --chown=mankiuser:mankiuser . .
# RUN pip install --user -e .

WORKDIR /app

RUN pip install --no-cache-dir --upgrade pip
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .
RUN pip install -e .

WORKDIR /run

ENTRYPOINT [ "manki" ]
16 changes: 16 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: 'Manki Converter'
description: 'Generate Anki Packages from Markdown Files using Manki'
inputs:
project-root:
description: 'The root of the manki project (including the manki.toml)'
required: true
outputs:
conversion-log:
description: 'Output of the conversion process.'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- "--git-action"
- "--root"
- ${{ inputs.project-root }}
6 changes: 6 additions & 0 deletions manki/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
const="my_anki_project",
help="Create a new dummy project with some defaults."
)
parser.add_argument(
"--git-action",
action="store_true",
default=False,
help="Write the correct output to the GITHUB_ environment variables"
)
# parser.add_argument(
# "--macros", "-m",
# type=str,
Expand Down
11 changes: 10 additions & 1 deletion manki/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging
from rich.logging import RichHandler
import rich.traceback as traceback
import os

from jinja2 import Environment, FileSystemLoader

Expand Down Expand Up @@ -63,7 +64,7 @@ def main():
create_new(args)
exit()

root = args.root or Path.cwd()
root = Path(args.root or Path.cwd())
config = MankiConfig(root=root)
# page = config.render_template("anki/question.html")
# print(page)
Expand Down Expand Up @@ -95,6 +96,14 @@ def main():
exit(code=1)

exporter.export()

if args.git_action:
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
file_name = sanitize_string(exporter.package.title) + ".apkg"
n_decks = exporter.package.n_chapters
n_cards = exporter.package.n_items
info = f"Exporting '{file_name}' with {n_decks} decks and {n_cards} cards in total"
print(f'conversion-log={info}', file=fh)


if __name__ == "__main__":
Expand Down
19 changes: 13 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
beautifulsoup4==4.10.0
Markdown==3.3.6

genanki~=0.13.0
pytest~=7.0.1
setuptools~=57.4.0
beautifulsoup4==4.10
Markdown==3.3
jinja2==3.1
genanki~=0.13
pytest~=7.0
setuptools~=57.4
toml==0.10
inflection==0.5
pygments==2.13
rich==12.6
pdfkit==1.0.0
python-markdown-math==0.8
pymdown-extensions==9.8
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = manki
description = Convert Markdown Files to Anki Decks
author = Frieder Frank
license = MIT
license_file = LICENSE
license_files = LICENSE
platforms = unix, linux, osx, cygwin, win32
classifiers =
Programming Language :: Python :: 3
Expand Down

0 comments on commit 77e2aef

Please sign in to comment.