Skip to content

Commit

Permalink
Merge pull request #3 from satackey/use-any-compiler
Browse files Browse the repository at this point in the history
Use any compiler
  • Loading branch information
satackey authored Dec 31, 2019
2 parents 43a7353 + 221f6e2 commit a41f36c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 44 deletions.
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
# action-latexmk
# action-latex

このアクションは指定されたファイルを`latexmk`コマンドでコンパイルします。
DooD(Docker outside of Docker)を使っているため、任意Dockerイメージが利用可能です。
このアクションは指定されたファイル・コマンドでコンパイルを行います。

このアクションの実行で起動されたコンテナ内で、
DooD(Docker outside of Docker)を使うことで、
任意Dockerイメージを起動しています。

## Inputs

### `docker-image`

_**必須**_ `latexmk`コマンドを実行するためのレジストリで公開されている Docker イメージ
_**必須**_ コンパイルコマンドを実行する Docker イメージ

### `build-files`

_**必須**_ 1行ごとに区切られたビルドするファイルリスト
(`host-workspace`からの相対パス)
_**必須**_ 1行ごとに区切られた、ビルドするTeXファイルの相対パスのリスト

### `host-workspace`

_任意_ ビルドするファイルのディレクトリ
(ホストVMの絶対パス)
このパスがDockerコンテナにマウントされます。
デフォルトは`actions/checkout`でチェックアウトされるパスです。
_任意_ ビルドするファイルがあるホストVMディレクトリの絶対パス

指定されなかった場合、アクションより起動された Docker コンテナの `/github/workspace` ディレクトリがコンパイル用の Docker コンテナへマウントされます。
指定された場合、そのパスがコンパイル用の Docker コンテナの `/custom/workspace` ディレクトリにマウントされます。

### `build-entrypoint`

### `container-workdir`
_任意_ コンパイル時に起動する Docker コンテナの Entrypoint
指定されなければ Docker イメージの Entrypoint で起動されます。
`latexmk` などを指定してください。

_任意_ コンテナ内のワークディレクトリ
`host-workspace`で指定されたディレクトリが、Dockerコンテナ内のこのパスへマウントされます。
### `build-args`

### `latexmk-options`
_任意_ `latexmk`コマンド実行時のオプション
_任意_ コンパイル実行時の追加オプション

## 使用例

```yaml
- name: Build LaTeX files
uses: satackey/action-latexmk@v1
uses: satackey/action-latex@v2
with:
docker-image: paperist/alpine-texlive-ja
build-entrypoint: latexmk
build-files: |
hoge/main.tex
fuga/main.tex
Expand Down
28 changes: 15 additions & 13 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
name: 'Build LaTeX with any Docker image'
description: 'Upload files to Google Drive'
name: Build LaTeX on any Docker image
description: |
Multiple file builds are supported.
# You can use not only latexmk but also pacdoc etc.

inputs:
docker-image:
description: 'Docker image to execute latexmk command'
description: Docker image to execute compile command
required: true

build-files:
description: 'List of TeX files separated by lines to build'
description: List of relative paths of TeX files to build, separated by lines
required: true

host-workspace:
description: 'Location of directory to build'
description: Absolute path of the host VM directory where the files to be built are located
required: false

container-workdir:
description: 'Working directory in container'
build-entrypoint:
description: Entrypoint of Docker container to be started at compile
required: false
default: /work

latexmk-options:
build-args:
description: Extra arguments used with the compile command.
required: false

branding:
Expand All @@ -28,10 +30,10 @@ branding:

runs:
using: docker
image: docker://satackey/action-latexmk:v1.0.1
image: docker://satackey/action-latex:v2.0.0
env:
BUILD_IMAGE: ${{ inputs.docker-image }}
HOST_WORKSPACE: ${{ inputs.host-workspace }}
WORKDIR: ${{ inputs.container-workdir }}
BUILD_FILES: ${{ inputs.build-files }}
LATEXMK_OPTIONS: ${{ inputs.latexmk-options }}
HOST_WORKSPACE: ${{ inputs.host-workspace }}
BUILD_ENTRYPOINT: ${{ inputs.build-entrypoint }}
BUILD_ARGS: ${{ inputs.build-args }}
38 changes: 23 additions & 15 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
#!/bin/sh

echo Pull the Docker image
docker pull $BUILD_IMAGE

BUILD_FILE_CMD="
TEX_FILE=\"{}\"
cd \$(dirname \"\$TEX_FILE\")
latexmk $LATEXMK_OPTIONS \$(basename \"\$TEX_FILE\")
"
ARG_ENTRYPOINT=""
if [ -n "$BUILD_ENTRYPOINT" ]; then
ARG_ENTRYPOINT="--entrypoint \"$BUILD_ENTRYPOINT\""
fi

DEFAULT_WORKSPACE="$RUNNER_WORKSPACE/$(basename $RUNNER_WORKSPACE)"
HOST_WORKSPACE=${HOST_WORKSPACE:-$DEFAULT_WORKSPACE}
ARG_MOUNT=""
BUILD_DIR="$PWD"
if [ -n "$HOST_WORKSPACE" ]; then
ARG_MOUNT="-v \"$HOST_WORKSPACE\":/custom/workspace"
BUILD_DIR="/custom/workspace"
fi

docker run \
-v "$HOST_WORKSPACE":"$WORKDIR" \
--workdir="$WORKDIR" \
--entrypoint '' \
$BUILD_IMAGE \
sh -c "
echo \"$BUILD_FILES\" | xargs -I{} -P $(nproc) -t sh -c '$BUILD_FILE_CMD'
"
echo "$BUILD_FILES" | xargs -I{TEX_FILE} -P $(nproc) -t sh -c "
WORKDIR=\"$BUILD_DIR/\$(dirname ./{TEX_FILE})\"
docker run --rm \\
--volumes-from $(basename $(cat /proc/1/cpuset)) \\
$ARG_ENTRYPOINT \\
$ARG_MOUNT \\
--workdir=\"\$WORKDIR\" \\
$BUILD_IMAGE \\
$BUILD_ARGS \\
\$(basename {TEX_FILE})
"

0 comments on commit a41f36c

Please sign in to comment.