Skip to content

Commit

Permalink
Update build-latex workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
range3 committed Sep 18, 2024
1 parent 2e0026a commit 947db81
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
11 changes: 11 additions & 0 deletions .github/actions/latexmk/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Build LaTeX using latexmk"
description: "Build LaTeX files and set output file name with version or branch info"
author: "range3"
runs:
using: "docker"
image: "Dockerfile"
inputs:
latex_file_name:
description: "LaTeX file to build (default: main.tex)"
required: false
default: "main.tex"
25 changes: 23 additions & 2 deletions .github/actions/latexmk/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
#!/bin/bash
set -eux

# build pdf
latexmk
# Set the LaTeX file name, defaulting to main.tex if not provided
LATEX_FILE_NAME="${INPUT_LATEX_FILE_NAME:-main.tex}"

# Determine the version or branch name
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION_NAME=$(echo "${GITHUB_REF}" | sed 's/refs\/tags\///')
else
VERSION_NAME=$(echo "${GITHUB_HEAD_REF}")
fi

# Determine the output PDF name
FILE_BASENAME=$(basename "${LATEX_FILE_NAME}" .tex)
OUTPUT_PDF="${FILE_BASENAME}-${VERSION_NAME}.pdf"

# Export environment variables for GitHub Actions to use in later steps
echo "LATEXMK_LATEX_FILE_NAME=${LATEX_FILE_NAME}" >> $GITHUB_ENV
echo "LATEXMK_OUTPUT_PDF=${OUTPUT_PDF}" >> $GITHUB_ENV

# Build the LaTeX document
latexmk -pdf "${LATEX_FILE_NAME}"

# Rename the output file with version or branch information
mv "${FILE_BASENAME}.pdf" "${OUTPUT_PDF}"
26 changes: 8 additions & 18 deletions .github/workflows/build-latex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,15 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
submodules: recursive
- name: Build LaTeX files by latexmk

- name: Build LaTeX and Set Output File Name
uses: ./.github/actions/latexmk
- name: Create a Release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload a Release Asset
id: upload-release-asset
uses: actions/[email protected]
latex_file_name: ${{ github.event.inputs.latex_file_name || 'main.tex' }}

- name: Create and Upload a Release Asset
uses: softprops/[email protected]
with:
files: ./${{ env.OUTPUT_PDF }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: ./main.pdf
asset_name: main.pdf
asset_content_type: application/pdf

0 comments on commit 947db81

Please sign in to comment.