├── Dockerfile ├── action.yml ├── README.md └── entrypoint.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | # Container image that runs your code 2 | FROM vinay0410/tectonic-image:latest 3 | 4 | # Copies your code file from your action repository to the filesystem path `/` of the container 5 | COPY entrypoint.sh /entrypoint.sh 6 | 7 | # Code file to execute when the docker container starts up (`entrypoint.sh`) 8 | ENTRYPOINT ["/entrypoint.sh"] -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | # action.yml 2 | name: 'Compile LateX' 3 | description: 'Compile Latex/XeLatex files easily !' 4 | branding: 5 | icon: file-text 6 | color: blue 7 | inputs: 8 | tex_path: # id of input 9 | description: 'Path of Tex File' 10 | required: true 11 | push: 12 | description: 'String stating whether to push output PDF, PDF will only be pushed in case of "yes"' 13 | default: 'no' 14 | required: false 15 | runs: 16 | using: 'docker' 17 | image: 'Dockerfile' 18 | args: 19 | - ${{ inputs.tex_path }} 20 | - ${{ inputs.push }} 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Latex Action 2 | 3 | This action compiles latex/xelatex files using [Tectonic](https://tectonic-typesetting.github.io/en-US/), which automatically downloads necessary dependencies, and compiles to pdf. 4 | 5 | ## Inputs 6 | 7 | ### `tex-path` 8 | 9 | **Required** Path of tex, xtx file to compile. 10 | 11 | ### `push` 12 | 13 | **Optional** Compiled PDF is pushed, if `push` is passed as 'yes'. 14 | 15 | ## Outputs 16 | Pushes a Compiled PDF file parallel to the tex, xtx file, if push is passed as 'yes'. 17 | 18 | ## Example usage 19 | 20 | ### Pushes Compiled PDF 21 | ``` 22 | on: [push] 23 | 24 | jobs: 25 | latex-job: 26 | runs-on: ubuntu-latest 27 | name: A job to Compile Latex file 28 | steps: 29 | - uses: actions/checkout@v1 30 | - name: Compilation 31 | uses: vinay0410/tectonic-action@master 32 | env: 33 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 34 | with: 35 | tex_path: 'dir/file.tex' 36 | push: 'yes' 37 | ``` 38 | 39 | ### Doesn't Push Compiled PDF 40 | ``` 41 | on: [push] 42 | 43 | jobs: 44 | latex-job: 45 | runs-on: ubuntu-latest 46 | name: A job to Compile Latex file 47 | steps: 48 | - uses: actions/checkout@v1 49 | - name: Compilation 50 | uses: vinay0410/tectonic-action@master 51 | env: 52 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 53 | with: 54 | tex_path: 'dir/file.tex' 55 | ``` 56 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | echo "Compiling $1" 5 | tectonic $1 6 | 7 | PUSH_OUTPUT=$(echo "$2" | tr '[:upper:]' '[:lower:]') 8 | 9 | if [[ $PUSH_OUTPUT != "yes" ]]; then # Don't push PDF 10 | exit 0; 11 | fi 12 | 13 | OUTPUT_PDF="${1%.*}.pdf" 14 | 15 | if [[ ${OUTPUT_PDF:0:1} == "/" ]]; then 16 | OUTPUT_PDF=${OUTPUT_PDF:1} 17 | fi 18 | 19 | FILE_NAME=$(basename $OUTPUT_PDF) 20 | DIR=$(dirname $OUTPUT_PDF) 21 | 22 | STATUSCODE=$(curl --silent --output resp.json --write-out "%{http_code}" -X GET -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/${GITHUB_REPOSITORY}/contents/$DIR) 23 | 24 | if [ $((STATUSCODE/100)) -ne 2 ]; then 25 | echo "Github's API returned $STATUSCODE" 26 | cat resp.json 27 | exit 22; 28 | fi 29 | 30 | SHA="" 31 | for i in $(jq -c '.[]' resp.json); 32 | do 33 | NAME=$(echo $i | jq -r .name) 34 | if [ "$NAME" = "$FILE_NAME" ]; then 35 | SHA=$(echo $i | jq -r .sha) 36 | break 37 | fi 38 | done 39 | 40 | echo '{ 41 | "message": "'"update $OUTPUT_PDF"'", 42 | "committer": { 43 | "name": "Tectonic Action", 44 | "email": "tectonic-action@github.com" 45 | }, 46 | "content": "'"$(base64 -w 0 $OUTPUT_PDF)"'", 47 | "sha": "'$SHA'" 48 | }' > payload.json 49 | 50 | STATUSCODE=$(curl --silent --output /dev/stderr --write-out "%{http_code}" \ 51 | -i -X PUT -H "Authorization: token $GITHUB_TOKEN" -d @payload.json \ 52 | https://api.github.com/repos/${GITHUB_REPOSITORY}/contents/${OUTPUT_PDF}) 53 | 54 | if [ $((STATUSCODE/100)) -ne 2 ]; then 55 | echo "Github's API returned $STATUSCODE" 56 | exit 22; 57 | fi 58 | --------------------------------------------------------------------------------