Skip to content

Commit

Permalink
Add support for update, install arguments
Browse files Browse the repository at this point in the history
- '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
  • Loading branch information
ferdnyc committed Dec 30, 2021
1 parent 64c81e3 commit 5860fc6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
13 changes: 12 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
image: 'Dockerfile'
24 changes: 23 additions & 1 deletion entrypoint.py
Original file line number Diff line number Diff line change
@@ -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))
Expand Down

0 comments on commit 5860fc6

Please sign in to comment.