Skip to content

Commit

Permalink
Merge pull request #5 from andygruber/feature/improveVersionHandling
Browse files Browse the repository at this point in the history
Add more version information to PDF
  • Loading branch information
andygruber authored Nov 11, 2023
2 parents c9b8c85 + a54cb54 commit df22936
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
22 changes: 18 additions & 4 deletions .github/workflows/compileLaTeX.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ jobs:
- name: Set up Git repository
uses: actions/checkout@v3

- name: Add version if real release
if: github.event_name == 'release'
run: echo '\newcommand\docversion{${{ github.event.release.tag_name }}}' > section/versinfo.tex
- 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
Expand All @@ -36,6 +43,10 @@ jobs:
# 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
Expand All @@ -45,7 +56,10 @@ jobs:
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)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ To ensure the release workflow functions optimally, grant the necessary read/wri

### **Versioning**

The `section/versinfo.tex` file contains version details. To incorporate it in another `.tex` file, use:
The `data/versinfo.tex` file contains version details. To incorporate it in another `.tex` file, use:
```latex
\input{section/versinfo.tex}
\input{data/versinfo.tex}
```
During standard builds (be it local or via GitHub Action), the output will display `DRAFT` followed by the date and time (e.g., `DRAFT 2023-03-06 13:32:10`). For release builds, the tag name will be shown (e.g., `v0.0.1`).

Expand Down
5 changes: 5 additions & 0 deletions data/docdata.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
% if not using overleaf - data is needed separately
\newcommand{\mySubject}{Your document subject}
\newcommand{\myNameInclTitle}{FirstName LastName}
\newcommand{\myTitle}{Your document title}
\newcommand{\PDFdocumentLang}{en-US}
1 change: 1 addition & 0 deletions data/versinfo.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\newcommand\docversion{DRAFT; \today\hspace{0.1cm}\DTMcurrenttime}
27 changes: 24 additions & 3 deletions demo.tex
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
\documentclass{article}
\usepackage[paperheight=16cm, paperwidth=12cm,includehead,nomarginpar,textwidth=10cm,headheight=10mm,]{geometry}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage{datetime2}
\input{section/versinfo.tex}
\input{data/versinfo.tex}
\input{data/docdata.tex}

\hypersetup{
pdftitle={\myTitle},
pdfsubject={\mySubject},
pdfauthor={\myNameInclTitle},
breaklinks, % permits line breaks for long links
bookmarksnumbered, % ... and include section numbers
linktocpage, % "make page number, not text, be link on TOC ..."
colorlinks, % yes ...
linkcolor=black, % normal internal links;
anchorcolor=black,
citecolor=black,
urlcolor=blue, % quite common
pdfstartview={Fit}, % "Fit" fits the page to the window
pdfpagemode=UseOutlines, % open bookmarks in Acrobat
plainpages=false, % avoids duplicate page number problem
pdflang={\PDFdocumentLang},
pdfkeywords={\docversion}
}

\begin{document}
% Set the page style to "fancy"...
\pagestyle{fancy}
\title{Single-sided document}
\author{Andreas Gruber}
\title{\myTitle}
\author{\myNameInclTitle}
\date{\docversion}
\fancyhf{} % clear existing header/footer entries
% We don't need to specify the O coordinate
Expand Down
1 change: 0 additions & 1 deletion section/versinfo.tex

This file was deleted.

0 comments on commit df22936

Please sign in to comment.