From ea76988053d78e6d803be0ae461a015b30c7f71e Mon Sep 17 00:00:00 2001 From: Arran Ubels Date: Fri, 31 May 2024 19:57:17 +1000 Subject: [PATCH 1/7] Added `options` to example To make it more obvious --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 072759f..bf37612 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,9 @@ jobs: - name: Typst uses: lvignoli/typst-action@main with: + options: | + --font-path + fonts source_file: | first_file.typ second_file.typ From 4dfc00332e61cad2203cf28bc7eb2af843b54991 Mon Sep 17 00:00:00 2001 From: Arran Ubels Date: Fri, 31 May 2024 19:58:53 +1000 Subject: [PATCH 2/7] Yaml alignment --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bf37612..aa8daa7 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,9 @@ jobs: - name: Typst uses: lvignoli/typst-action@main with: - options: | - --font-path - fonts + options: | + --font-path + fonts source_file: | first_file.typ second_file.typ From ef01b3c4597aa9c7ddaaebc0f7b257977b9e2ceb Mon Sep 17 00:00:00 2001 From: Arran Ubels Date: Tue, 13 Aug 2024 15:17:01 +1000 Subject: [PATCH 3/7] test 1 --- README.md | 14 ++++++++++++++ entrypoint.py | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 072759f..e4e461b 100644 --- a/README.md +++ b/README.md @@ -78,3 +78,17 @@ Repository [lvignoli/typst-action-example](https://github.com/lvignoli/typst-act - I was hasty to tag for a v1. I have now deleted it. As long as Typst is not in a stable state, the action will stay in v0. You should use `lvignoli/typst-action@main` in the meantime. + +## Extra + +To specify the output filename use `:` in the filename to denote the name, such as: +``` + - name: Typst + uses: lvignoli/typst-action@main + with: + source_file: | + first_file.typ:first.pdf + second_file.typ + third_and_final_file.typ:third.pdf + +``` \ No newline at end of file diff --git a/entrypoint.py b/entrypoint.py index 227792f..0531b94 100644 --- a/entrypoint.py +++ b/entrypoint.py @@ -4,12 +4,14 @@ import sys -def compile(filename: str, options: list[str]) -> bool: +def compile(filename: str, options: list[str], outputname: string | None) -> bool: """Compiles a Typst file with the specified global options. Returns True if the typst command exited with status 0, False otherwise. """ command = ["typst"] + options + ["compile", filename] + if outputname is not None: + command.append(outputname) logging.debug("Running: " + " ".join(command)) result = subprocess.run(command, capture_output=True, text=True) @@ -27,12 +29,15 @@ def main(): logging.basicConfig(level=logging.INFO) # Parse the positional arguments, expected in the following form - # 1. The Typst files to compile in a line separated string + # 1. The Typst files to compile in a line separated string. Optionally To + # specify the ooutput name separate it with a : so such as: + # input.typ:output.pdf # 2. The global Typst CLI options, in a line separated string. It means each # whitespace separated field should be on its own line. source_files = sys.argv[1].splitlines() options = sys.argv[2].splitlines() + version = subprocess.run( ["typst", "--version"], capture_output=True, text=True ).stdout @@ -40,12 +45,17 @@ def main(): success: dict[str, bool] = {} - for filename in source_files: + for filename_pair in source_files: + (filename, _, outputfilename) = filename_pair.partition(":") filename = filename.strip() if filename == "": continue + if outputfilename == "": + outputfilename = None + elif outputfilename is not None: + outputfilename = outputfilename.strip logging.info(f"Compiling {filename}…") - success[filename] = compile(filename, options) + success[filename] = compile(filename, options, outputfilename) # Log status of each input files. for filename, status in success.items(): From e32323d65495f3047cbbc3fe1f289e43d4f953a4 Mon Sep 17 00:00:00 2001 From: Arran Ubels Date: Tue, 13 Aug 2024 15:19:01 +1000 Subject: [PATCH 4/7] It's an `str` language --- entrypoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.py b/entrypoint.py index 0531b94..bfc2b8d 100644 --- a/entrypoint.py +++ b/entrypoint.py @@ -4,7 +4,7 @@ import sys -def compile(filename: str, options: list[str], outputname: string | None) -> bool: +def compile(filename: str, options: list[str], outputname: str | None) -> bool: """Compiles a Typst file with the specified global options. Returns True if the typst command exited with status 0, False otherwise. From 1641c41c8ecc27bf66ed7fa702c075daaa690cac Mon Sep 17 00:00:00 2001 From: Arran Ubels Date: Tue, 13 Aug 2024 15:21:58 +1000 Subject: [PATCH 5/7] Ah! --- entrypoint.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/entrypoint.py b/entrypoint.py index bfc2b8d..e89bbdc 100644 --- a/entrypoint.py +++ b/entrypoint.py @@ -4,14 +4,14 @@ import sys -def compile(filename: str, options: list[str], outputname: str | None) -> bool: +def compile(filename: str, options: list[str], outputfilename: str | None) -> bool: """Compiles a Typst file with the specified global options. Returns True if the typst command exited with status 0, False otherwise. """ command = ["typst"] + options + ["compile", filename] - if outputname is not None: - command.append(outputname) + if outputfilename is not None: + command.append(outputfilename) logging.debug("Running: " + " ".join(command)) result = subprocess.run(command, capture_output=True, text=True) @@ -53,7 +53,7 @@ def main(): if outputfilename == "": outputfilename = None elif outputfilename is not None: - outputfilename = outputfilename.strip + outputfilename = outputfilename.strip() logging.info(f"Compiling {filename}…") success[filename] = compile(filename, options, outputfilename) From 4fc9643eeaf0793d646c527d2b2ba4d131363f43 Mon Sep 17 00:00:00 2001 From: Arran Ubels Date: Tue, 13 Aug 2024 15:25:32 +1000 Subject: [PATCH 6/7] Options are layered, root tier is unlikely to ever be relevant: arran@arran-desktop:/home/arran 27401 % typst -h The Typst compiler Usage: typst [OPTIONS] Commands: compile Compiles an input file into a supported output format [aliases: c] watch Watches an input file and recompiles on changes [aliases: w] init Initializes a new project from a template query Processes an input file to extract provided metadata fonts Lists all discovered fonts in system and custom font paths update Self update the Typst CLI (disabled) help Print this message or the help of the given subcommand(s) Options: --color[=] Set when to use color. auto = use color if a capable terminal is detected [default: auto] [possible values: auto, always, never] --cert Path to a custom CA certificate to use when making network requests [env: TYPST_CERT=] -h, --help Print help -V, --version Print version arran@arran-desktop:/home/arran 27402 % typst compile -h Compiles an input file into a supported output format Usage: typst compile [OPTIONS] [OUTPUT] Arguments: Path to input Typst file, use `-` to read input from stdin [OUTPUT] Path to output file (PDF, PNG, or SVG) Options: --root Configures the project root (for absolute paths) [env: TYPST_ROOT=] --input Add a string key-value pair visible through `sys.inputs` --font-path Adds additional directories to search for fonts [env: TYPST_FONT_PATHS=] --diagnostic-format The format to emit diagnostics in [default: human] [possible values: human, short] -f, --format The format of the output file, inferred from the extension by default [possible values: pdf, png, svg] --open [] Opens the output file using the default viewer after compilation --ppi The PPI (pixels per inch) to use for PNG export [default: 144] --timings [] Produces performance timings of the compilation process (experimental) -h, --help Print help (see more with '--help') --- entrypoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.py b/entrypoint.py index e89bbdc..1d042a4 100644 --- a/entrypoint.py +++ b/entrypoint.py @@ -9,7 +9,7 @@ def compile(filename: str, options: list[str], outputfilename: str | None) -> bo Returns True if the typst command exited with status 0, False otherwise. """ - command = ["typst"] + options + ["compile", filename] + command = ["typst", "compile"] + options + [filename] if outputfilename is not None: command.append(outputfilename) logging.debug("Running: " + " ".join(command)) From d606b0e636f56407cce0b91a13b052c70ee61fe6 Mon Sep 17 00:00:00 2001 From: Arran Ubels Date: Tue, 13 Aug 2024 15:27:32 +1000 Subject: [PATCH 7/7] Info command no need to hide it --- entrypoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.py b/entrypoint.py index 1d042a4..7f62b9a 100644 --- a/entrypoint.py +++ b/entrypoint.py @@ -12,7 +12,7 @@ def compile(filename: str, options: list[str], outputfilename: str | None) -> bo command = ["typst", "compile"] + options + [filename] if outputfilename is not None: command.append(outputfilename) - logging.debug("Running: " + " ".join(command)) + logging.info("Running: " + " ".join(command)) result = subprocess.run(command, capture_output=True, text=True) try: