Skip to content

Commit

Permalink
feat: reimplement the action
Browse files Browse the repository at this point in the history
* make scheme choice as an input
* allow to choose texlive version
* allow using custom docker image

Closes #10.
  • Loading branch information
xu-cheng committed Oct 7, 2023
1 parent a5a06d0 commit 5f523af
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 44 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# vim: set ft=dosini nospell:
# document: http://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
indent_size = 2
10 changes: 8 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ name: Test Github Action
on: [push, pull_request]
jobs:
test:
strategy:
fail-fast: false
matrix:
texlive_version: [2020, 2021, 2022, latest]
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Test Action
uses: ./small/
uses: ./
with:
scheme: small
texlive_version: ${{ matrix.texlive_version }}
run: |
apk add make
tlmgr install blindtext
Expand Down
47 changes: 43 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ This action is suitable to run arbitrary commands in a LaTeX environment. If you
## Inputs

* `run`: Arbitrary bash codes to be executed. It will be executed in the form of `bash -eo pipefail -c {input}`.
* `scheme`: The scheme of TeXLive to be used, either full or small. By default, full TeXLive is used.
* `texlive_version`: The version of TeXLive to be used. Supported inputs include 2020, 2021, 2022, 2023, and latest. By default the latest TeXLive is used. This input cannot co-exist with `docker_image` input.
* `docker_image`: Custom which docker image to be used. Only [latex-docker images](https://github.com/xu-cheng/latex-docker/pkgs/container/texlive-full) are supported.

## Example

Expand All @@ -24,9 +27,10 @@ This action is suitable to run arbitrary commands in a LaTeX environment. If you
build_latex:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: xu-cheng/texlive-action/full@v1
- uses: actions/checkout@v4
- uses: xu-cheng/texlive-action@v2
with:
scheme: full
run: |
apk add make
make
Expand All @@ -40,9 +44,44 @@ This action is suitable to run arbitrary commands in a LaTeX environment. If you
build_latex:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: xu-cheng/texlive-action/small@v1
- uses: actions/checkout@v4
- uses: xu-cheng/texlive-action@v2
with:
scheme: small
run: |
apk add make
make
```

* Run commands in a 2022 TeXLive environment.

```yaml
on: [push]
jobs:
build_latex:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: xu-cheng/texlive-action@v2
with:
texlive_version: 2022
run: |
apk add make
make
```

* Run commands using custom docker image.

```yaml
on: [push]
jobs:
build_latex:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: xu-cheng/texlive-action@v2
with:
docker_image: ghcr.io/xu-cheng/texlive-full:20230801
run: |
apk add make
make
Expand Down
115 changes: 115 additions & 0 deletions action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/env bash

set -eo pipefail

run() {
echo -e "\033[1;34m$@\033[0m"
"$@"
}

error() {
echo "::error :: $1"
exit 1
}

scheme="${1}"
texlive_version="${2}"
docker_image="${3}"
run="${4}"

if [[ -n "$scheme" && -n "$docker_image" ]]; then
error "Input 'scheme' and 'docker_image' cannot co-exist".
fi

if [[ -n "$texlive_version" && -n "$docker_image" ]]; then
error "Input 'texlive_version' and 'docker_image' cannot co-exist".
fi

if [[ -z "$docker_image" ]]; then
case "$texlive_version" in
"" | "latest" | "2023")
image_version="latest"
;;
"2022")
image_version="20230301"
;;
"2021")
image_version="20220201"
;;
"2020")
image_version="20210301"
;;
*)
error "TeX Live version $texlive_version is not supported. The currently supported versions are 2020-2023 or latest."
;;
esac
docker_image="ghcr.io/xu-cheng/texlive-$scheme:$image_version"
fi

# ref: https://docs.miktex.org/manual/envvars.html
run docker run --rm \
-e "BIBINPUTS" \
-e "BSTINPUTS" \
-e "MFINPUTS" \
-e "TEXINPUTS" \
-e "TFMFONTS" \
-e "HOME" \
-e "GITHUB_JOB" \
-e "GITHUB_REF" \
-e "GITHUB_SHA" \
-e "GITHUB_REPOSITORY" \
-e "GITHUB_REPOSITORY_OWNER" \
-e "GITHUB_REPOSITORY_OWNER_ID" \
-e "GITHUB_RUN_ID" \
-e "GITHUB_RUN_NUMBER" \
-e "GITHUB_RETENTION_DAYS" \
-e "GITHUB_RUN_ATTEMPT" \
-e "GITHUB_REPOSITORY_ID" \
-e "GITHUB_ACTOR_ID" \
-e "GITHUB_ACTOR" \
-e "GITHUB_TRIGGERING_ACTOR" \
-e "GITHUB_WORKFLOW" \
-e "GITHUB_HEAD_REF" \
-e "GITHUB_BASE_REF" \
-e "GITHUB_EVENT_NAME" \
-e "GITHUB_SERVER_URL" \
-e "GITHUB_API_URL" \
-e "GITHUB_GRAPHQL_URL" \
-e "GITHUB_REF_NAME" \
-e "GITHUB_REF_PROTECTED" \
-e "GITHUB_REF_TYPE" \
-e "GITHUB_WORKFLOW_REF" \
-e "GITHUB_WORKFLOW_SHA" \
-e "GITHUB_WORKSPACE" \
-e "GITHUB_ACTION" \
-e "GITHUB_EVENT_PATH" \
-e "GITHUB_ACTION_REPOSITORY" \
-e "GITHUB_ACTION_REF" \
-e "GITHUB_PATH" \
-e "GITHUB_ENV" \
-e "GITHUB_STEP_SUMMARY" \
-e "GITHUB_STATE" \
-e "GITHUB_OUTPUT" \
-e "RUNNER_OS" \
-e "RUNNER_ARCH" \
-e "RUNNER_NAME" \
-e "RUNNER_ENVIRONMENT" \
-e "RUNNER_TOOL_CACHE" \
-e "RUNNER_TEMP" \
-e "RUNNER_WORKSPACE" \
-e "ACTIONS_RUNTIME_URL" \
-e "ACTIONS_RUNTIME_TOKEN" \
-e "ACTIONS_CACHE_URL" \
-e GITHUB_ACTIONS=true \
-e CI=true \
-v "/var/run/docker.sock":"/var/run/docker.sock" \
-v "$HOME:$HOME" \
-v "$GITHUB_ENV:$GITHUB_ENV" \
-v "$GITHUB_OUTPUT:$GITHUB_OUTPUT" \
-v "$GITHUB_STEP_SUMMARY:$GITHUB_STEP_SUMMARY" \
-v "$GITHUB_PATH:$GITHUB_PATH" \
-v "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" \
-w "$GITHUB_WORKSPACE" \
"$docker_image" \
/bin/bash -eo pipefail -c -- \
"$run"
27 changes: 27 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Github Action with TeXLive
description: Run arbitrary commands in a TeXLive environment.
author: Cheng XU
inputs:
run:
description: Arbitrary bash codes to be executed
required: true
scheme:
description: The scheme of TeXLive to be used, either full or small
default: full
texlive_version:
description: The version of TeXLive to be used
docker_image:
description: The docker image to be used
runs:
using: composite
steps:
- shell: bash
run: |
"${GITHUB_ACTION_PATH}/action.sh" \
"${{ inputs.scheme }}" \
"${{ inputs.texlive_version }}" \
"${{ inputs.docker_image }}" \
"${{ inputs.run }}"
branding:
icon: book
color: blue
19 changes: 0 additions & 19 deletions full/action.yml

This file was deleted.

19 changes: 0 additions & 19 deletions small/action.yml

This file was deleted.

0 comments on commit 5f523af

Please sign in to comment.