Merge pull request #5 from andygruber/feature/improveVersionHandling #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build LaTeX document | |
on: | |
push: | |
branches: [ "main", "release/*", "develop", "develop/*" ] | |
pull_request: | |
branches: [ "main", "release/*", "develop", "develop/*" ] | |
release: | |
types: [published] | |
jobs: | |
build_latex: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Git repository | |
uses: actions/checkout@v3 | |
- name: Add version or PR info | |
run: | | |
if [[ "${{ github.event_name }}" == "release" ]]; then | |
echo '\newcommand\docversion{${{ github.event.release.tag_name }}}' > data/versinfo.tex | |
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
echo '\newcommand\docversion{PR\#${{ github.event.pull_request.number }}; \today\hspace{0.1cm}\DTMcurrenttime}' > data/versinfo.tex | |
else | |
SHASHORT=$(echo ${{ github.sha }} | cut -c1-7) | |
echo "\newcommand\docversion{Git-sha ${SHASHORT}; \today\hspace{0.1cm}\DTMcurrenttime}" > data/versinfo.tex | |
fi | |
- name: Compile LaTeX document | |
uses: xu-cheng/latex-action@v2 | |
with: | |
root_file: "*.tex" | |
glob_root_file: true | |
- name: Rename PDFs | |
run: | | |
pdfs=( *.pdf ) | |
num_pdfs=${#pdfs[@]} | |
if [ "$num_pdfs" -eq 0 ]; then | |
echo "No PDFs found." | |
exit 1 | |
fi | |
# Generate the base name for the PDFs | |
base_name="${GITHUB_REPOSITORY##*/}" | |
# set base_name to custom value if required | |
# base_name='my custom pdf file name' | |
# Add tag to file name in case of release | |
if [ "$GITHUB_EVENT_NAME" == "release" ]; then | |
base_name="${base_name}_${{ github.event.release.tag_name }}" | |
fi | |
# If only one PDF is found, rename it | |
if [ "$num_pdfs" -eq 1 ]; then | |
mv "${pdfs[0]}" "${base_name}.pdf" | |
exit 0 | |
fi | |
# Uncomment if there can only be 1 PDF in this repository | |
# exit 1 | |
# If multiple PDFs are found, rename them with their original names appended | |
for pdf in "${pdfs[@]}"; do | |
original_name=$(basename "$pdf" .pdf) | |
new_name="${base_name}_${original_name}.pdf" | |
mv "$pdf" "$new_name" | |
done | |
- name: Upload PDF file | |
uses: actions/upload-artifact@v3 | |
with: | |
name: PDF | |
path: "*.pdf" | |
release: | |
if: github.event_name == 'release' | |
name: Release | |
runs-on: ubuntu-latest | |
needs: build_latex | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: PDF | |
path: ./ | |
- name: Upload to Release | |
id: upload_to_release | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: | | |