diff --git a/Dockerfile.pdflatex b/Dockerfile.pdflatex new file mode 100644 index 0000000..ad37a42 --- /dev/null +++ b/Dockerfile.pdflatex @@ -0,0 +1,8 @@ +FROM sphinxdoc/sphinx-pdflatex:4.3.2 + +LABEL "maintainer"="Ammar Askar " + +ADD entrypoint.py /entrypoint.py +ADD sphinx_action /sphinx_action + +ENTRYPOINT ["/entrypoint.py"] diff --git a/Dockerfile.sphinx4 b/Dockerfile.sphinx4 new file mode 100644 index 0000000..c665b66 --- /dev/null +++ b/Dockerfile.sphinx4 @@ -0,0 +1,8 @@ +FROM sphinxdoc/sphinx:4.3.2 + +LABEL "maintainer"="Ammar Askar " + +ADD entrypoint.py /entrypoint.py +ADD sphinx_action /sphinx_action + +ENTRYPOINT ["/entrypoint.py"] diff --git a/action.yml b/action.yml index a914bdf..ce825a1 100644 --- a/action.yml +++ b/action.yml @@ -21,6 +21,24 @@ inputs: dependencies, for example with "apt-get update -y && apt-get install -y perl" required: false + update: + description: + Set this flag to run 'apt update' in the container before starting + the sphinx build. + required: false + default: false + install: + description: + A list of additional 'apt' packages to install before running + sphinx. (Setting this will force-enable 'update' as well.) + required: false + container: + description: + Run the build in the named container. Must be one of + 'sphinx4', 'pdflatex', or 'default'. + required: false + default: 'default' runs: using: 'docker' - image: 'Dockerfile' \ No newline at end of file + image: ${{ format('Dockerfile.{0}', inputs.container) }} + diff --git a/entrypoint.py b/entrypoint.py index 1d3416d..72e3163 100755 --- a/entrypoint.py +++ b/entrypoint.py @@ -1,14 +1,38 @@ -#!/usr/bin/env python3 +#!/usr/bin/env -S python3 -u import os import json +import subprocess +import sys from sphinx_action import action # This is the entrypoint called by Github when our action is run. All the # Github specific setup is done here to make it easy to test the action code # in isolation. + + +def interpret_env(env_var): + if isinstance(env_var, str): + return env_var.lower() not in ["false", "no", "off" "0"] + return bool(env_var) + + if __name__ == "__main__": print("[sphinx-action] Starting sphinx-action build.") + update = os.environ.get("INPUT_UPDATE", False) + should_update = interpret_env(update) + + install = os.environ.get("INPUT_INSTALL", "") + packages = install.split() + + if should_update or packages: + print("Updating apt...") + subprocess.call(["/usr/bin/apt", "-y", "update"]) + + print(f"{len(packages)} packages (plus dependencies) to install") + if packages: + subprocess.call(["/usr/bin/apt", "-y", "install", *packages]) + if "INPUT_PRE-BUILD-COMMAND" in os.environ: pre_command = os.environ["INPUT_PRE-BUILD-COMMAND"] print("Running: {}".format(pre_command))