From 2535357b301d3f7c6317f9bfd3e64a0c406322df Mon Sep 17 00:00:00 2001 From: Cheng XU Date: Fri, 6 Oct 2023 21:38:43 -0700 Subject: [PATCH] feat: reimplement the action * make scheme choice as an input * allow to choose texlive version * allow using custom docker image --- .editorconfig | 12 ++++ .github/workflows/test.yml | 10 +++- README.md | 47 +++++++++++++-- action.sh | 115 +++++++++++++++++++++++++++++++++++++ action.yml | 27 +++++++++ full/action.yml | 19 ------ small/action.yml | 19 ------ 7 files changed, 205 insertions(+), 44 deletions(-) create mode 100644 .editorconfig create mode 100755 action.sh create mode 100644 action.yml delete mode 100644 full/action.yml delete mode 100644 small/action.yml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..29cb96a --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b2d1dec..0ac3efc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/README.md b/README.md index f2f9225..7395fd3 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 diff --git a/action.sh b/action.sh new file mode 100755 index 0000000..ea9ab40 --- /dev/null +++ b/action.sh @@ -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" diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..5677f59 --- /dev/null +++ b/action.yml @@ -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 diff --git a/full/action.yml b/full/action.yml deleted file mode 100644 index f05f8ec..0000000 --- a/full/action.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Github Action with TeXLive [Full] -description: Run arbitrary commands in a TeXLive environment. -author: Cheng XU -inputs: - run: - description: Arbitrary bash codes to be executed - required: true -runs: - using: docker - image: docker://ghcr.io/xu-cheng/texlive-full:latest - entrypoint: /bin/bash - args: - - -eo - - pipefail - - -c - - ${{ inputs.run }} -branding: - icon: book - color: blue diff --git a/small/action.yml b/small/action.yml deleted file mode 100644 index 8259444..0000000 --- a/small/action.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Github Action with TeXLive [Small] -description: Run arbitrary commands in a TeXLive environment. -author: Cheng XU -inputs: - run: - description: Arbitrary bash codes to be executed - required: true -runs: - using: docker - image: docker://ghcr.io/xu-cheng/texlive-small:latest - entrypoint: /bin/bash - args: - - -eo - - pipefail - - -c - - ${{ inputs.run }} -branding: - icon: book - color: blue