From 64c81e39425c85ec5499bed717aa0b8696c9d83b Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 29 Dec 2021 19:03:03 -0500 Subject: [PATCH 1/4] Use latest sphinxdoc image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9184847..c588dbb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM sphinxdoc/sphinx:2.4.4 +FROM sphinxdoc/sphinx:latest LABEL "maintainer"="Ammar Askar " From 5860fc697513e5b1c9b8f333f93b66b297f971fe Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 29 Dec 2021 19:03:19 -0500 Subject: [PATCH 2/4] Add support for update, install arguments - 'install' takes a list of packages to install with apt - 'update' triggers an 'apt update' before the run - setting 'install' will force an update regardless of the 'update' value - 'entrypoint.py' is made unbuffered (by running 'python3 -u') to more accurately interleave the output of various commands --- action.yml | 13 ++++++++++++- entrypoint.py | 24 +++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index a914bdf..52f24b2 100644 --- a/action.yml +++ b/action.yml @@ -21,6 +21,17 @@ 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 runs: using: 'docker' - image: 'Dockerfile' \ No newline at end of file + image: 'Dockerfile' diff --git a/entrypoint.py b/entrypoint.py index 1d3416d..c9223fd 100755 --- a/entrypoint.py +++ b/entrypoint.py @@ -1,14 +1,36 @@ -#!/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)) From 468d403f5919b75235ac919d1f40ea830e601953 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 29 Dec 2021 20:25:31 -0500 Subject: [PATCH 3/4] Black-formatted code --- entrypoint.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entrypoint.py b/entrypoint.py index c9223fd..72e3163 100755 --- a/entrypoint.py +++ b/entrypoint.py @@ -9,11 +9,13 @@ # 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.") From 324ac0efa5258835b989031f5df5d48d223e2e4c Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 29 Dec 2021 21:38:32 -0500 Subject: [PATCH 4/4] Support selection of container image --- Dockerfile | 2 +- Dockerfile.pdflatex | 8 ++++++++ Dockerfile.sphinx4 | 8 ++++++++ action.yml | 9 ++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 Dockerfile.pdflatex create mode 100644 Dockerfile.sphinx4 diff --git a/Dockerfile b/Dockerfile index c588dbb..9184847 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM sphinxdoc/sphinx:latest +FROM sphinxdoc/sphinx:2.4.4 LABEL "maintainer"="Ammar Askar " 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 52f24b2..ce825a1 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,13 @@ inputs: 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' + image: ${{ format('Dockerfile.{0}', inputs.container) }} +