Skip to content

Commit

Permalink
add support for git (#6)
Browse files Browse the repository at this point in the history
* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* fix infinite commits

add support for gitinfo2 #5

* Updated gitHeadLocal.gin

* also trigger in post-checkout and post-merge

add support for gitinfo2 #5

* Updated gitHeadLocal.gin

* Updated gitHeadLocal.gin

* up artifact name

add support for gitinfo2 #5

* Updated gitHeadLocal.gin

* up workflow and improve doc

add support for gitinfo2 #5

* Updated gitHeadLocal.gin
  • Loading branch information
prudhomm authored Aug 4, 2024
1 parent 53aca10 commit b17e048
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 11 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/latex.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

name: Compile Latex and Release PDF
name: Compile Latex and Release PDF


on:
Expand All @@ -8,8 +8,8 @@ on:
- 'v*'
branches:
- '*'


jobs:
build_latex:
runs-on: ubuntu-latest
Expand All @@ -20,32 +20,34 @@ jobs:
steps:
- name: Set up Git repository
uses: actions/checkout@v4
- name: Install hooks
run: sh ./setup-hooks.sh
- name: Compile LaTeX document
uses: xu-cheng/latex-action@v3
with:
root_file: main.tex
latexmk_shell_escape: true
post_compile: "latexmk -c; rm -rf _minted*"

- name: Get Repository Name
id: repo_name
run: |
ls -lrt
prefix=$(echo "${{ github.repository }}" | cut -d'/' -f2)
echo "prefix=$prefix" >> "$GITHUB_OUTPUT"
echo "pdf=$prefix-${{ github.ref_name }}.pdf" >> "$GITHUB_OUTPUT"
-
-
name: Rename PDF
run: |
mv main.pdf ${{ steps.repo_name.outputs.pdf }}
- name: Upload PDF
uses: actions/[email protected]
with:
# get the name of the repo without the organisation
name: PDF
name: ${{ steps.repo_name.outputs.pdf }}
path: ${{ steps.repo_name.outputs.pdf }}

-
-
name: Create Release
id: create_release
if: startsWith(github.ref, 'refs/tags/v')
Expand Down
17 changes: 17 additions & 0 deletions gitHeadLocal.gin
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
\usepackage[%
shash={ef44c0f},
lhash={ef44c0f9fc99db73be3c4f02bcc83a0f4110f5c7},
authname={Christophe Prud'homme},
authemail={[email protected]},
authsdate={2024-08-04},
authidate={2024-08-04 16:56:51 +0200},
authudate={1722783411},
commname={Christophe Prud'homme},
commemail={[email protected]},
commsdate={2024-08-04},
commidate={2024-08-04 16:56:51 +0200},
commudate={1722783411},
refnames={ (HEAD -> 5-add-support-for-gitinfo2)},
firsttagdescribe={v1.0.2-2674-gef44c0f},
reltag={v1.0.2-2674-gef44c0f}
]{gitexinfo}
42 changes: 42 additions & 0 deletions hooks/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh
# Copyright 2015 Brent Longborough
# Part of gitinfo2 package Version 2
# Release 2.0.7 2015-11-22
# Please read gitinfo2.pdf for licencing and other details
# -----------------------------------------------------
# Post-{commit,checkout,merge} hook for the gitinfo2 package
#
# Get the first tag found in the history from the current HEAD
FIRSTTAG=$(git describe --tags --always --dirty='-*' 2>/dev/null)
# Get the first tag in history that looks like a Release
RELTAG=$(git describe --tags --long --always --dirty='-*' --match 'v[0-9]*\.[0-9]*\.[0-9]*' 2>/dev/null)
# Hoover up the metadata
git --no-pager log -1 --date=short --decorate=short \
--pretty=format:"\usepackage[%
shash={%h},
lhash={%H},
authname={%an},
authemail={%ae},
authsdate={%ad},
authidate={%ai},
authudate={%at},
commname={%cn},
commemail={%ce},
commsdate={%cd},
commidate={%ci},
commudate={%ct},
refnames={%d},
firsttagdescribe={$FIRSTTAG},
reltag={$RELTAG}
]{gitexinfo}" HEAD > .git/gitHeadInfo.gin

cp .git/gitHeadInfo.gin gitHeadLocal.gin

# Extract the base name of the script
SCRIPT_NAME=$(basename "$0")

git add gitHeadLocal.gin
mv .git/hooks/post-commit .git/hooks/post-commit.disabled
git commit -m "Updated gitHeadLocal.gin"
mv .git/hooks/post-commit.disabled .git/hooks/post-commit

93 changes: 89 additions & 4 deletions main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,30 @@
\usepackage{graphicx}
\usepackage{xcolor}

\usepackage{hyperref}
\IfFileExists{.git/gitHeadInfo.gin}{
\usepackage[pcount,grumpy,mark,markifdirty]{gitinfo2}
}{%
\usepackage[local,pcount,grumpy,mark,markifdirty]{gitinfo2}
}

\usepackage[bookmarksnumbered,bookmarksopen,linktocpage]{hyperref}

\usepackage{minted}
\usepackage{natbib}

\CatchFileDef{\myversion}{|echo $VERSION}{}

\title{Template Repository for Articles}
\author{Christophe Prud'homme\thanks{Cemosis, IRMA UMR 7501, Université de Strasbourg, CNRS, France, \tt \href{mailto:[email protected]}{[email protected]}}}
\date{\gitReln\ \gitAuthorDate\ (\gitAbbrevHash)}

% Define custom color
\definecolor{CustomBlue}{rgb}{0.25, 0.41, 0.88} % RoyalBlue
% Set up hyperref with the custom citecolor
\hypersetup{
pdftitle={\@title},
pdfauthor={\@author},
pdfsubject={\@subject},
pdfkeywords={mathematical and computational ophthalmology, finite element method, thermo-fluid dynamics, feelpp},
colorlinks=true,
citecolor=CustomBlue,
linkcolor=black, % You can set this to any color you prefer
Expand Down Expand Up @@ -41,8 +54,6 @@

\begin{document}

\title{Template Repository for Articles\\ \small\tt Version \myversion}
\author{Christophe Prud'homme\thanks{Cemosis, IRMA UMR 7501, Université de Strasbourg, CNRS, France, \tt \href{mailto:[email protected]}{[email protected]}}}
\maketitle
\tableofcontents

Expand All @@ -54,6 +65,80 @@ \section{Introduction}
By following this template, researchers can enhance their workflow efficiency and ensure consistent document formatting across platforms like Overleaf and local LaTeX installations.
The releases assets produced by the GitHub Actions allows to upload the article to HAL, arXiv, Zenodo, etc.

\section{Git Support}
\label{sec:git-support}

The `gitinfo2` package allows LaTeX documents to include information about the current state of the Git repository, such as the commit hash, author, and date. This is particularly useful for versioning and tracking changes in scientific documents.

\subsection{Configuration}

To include `gitinfo2` in your LaTeX document, add the following lines to your preamble:

\begin{minted}[bgcolor=background]{latex}
\IfFileExists{.git/gitHeadInfo.gin}{
\usepackage[pcount,grumpy,mark,markifdirty]{gitinfo2}
}{%
\usepackage[local,pcount,grumpy,mark,markifdirty]{gitinfo2}
}
\end{minted}

This configuration attempts to use .git/gitHeadInfo.gin if it exists (indicating a Git repository) and falls back to a local file if not.

\subsection{Setting Up Git Hooks}

To automatically generate the \mintinline{sh}|.git/gitHeadInfo.gin| file with each commit, you need to set up Git hooks.
This repository includes a script \mintinline{sh}|setup-hooks.sh| to simplify the installation of these hooks.

This will copy the \mintinline{sh}|post-commit| and \mintinline{sh}|post-checkout| hook scripts to the .git/hooks directory and make them executable.
These hooks will automatically generate the \mintinline{sh}|.git/gitHeadInfo.gin| and update \mintinline{sh}|gitHeadLocal.gin| file after each commit or checkout.

The file \mintinline{sh}|gitHeadLocal.gin| is used when the document is compiled outside of a Git repository, e.g., in Overleaf or in an public archive such as HAL or arXiv.


\subsection{Using GitHub Actions}

The GitHub Actions workflow is configured to run the \mintinline{sh}|setup-hooks.sh| script, ensuring that the Git hooks are set up in the CI environment.
This allows the automated compilation of the LaTeX document to include the latest Git information in the article.

\subsection{Full Article Workflow}

Here is a summary of the full workflow for creating and maintaining a LaTeX document with Git support:

\begin{enumerate}
\item \textbf{Clone the Repository}:
Clone the repository to your local machine:
\begin{minted}[bgcolor=background]{sh}
git clone https://github.com/your-username/your-repo.git
cd your-repo
\end{minted}
\item \textbf{Set Up Git Hooks}:
Run the setup-hooks.sh script to set up the necessary Git hooks:
\begin{minted}[bgcolor=background]{sh}
./setup-hooks.sh
\end{minted}
\item \textbf{Make Changes to Your Document}:
Edit your LaTeX document and add, commit, and push changes to the repository:
\begin{minted}[bgcolor=background]{sh}
git add .
git commit -m “Update document”
git push origin main
\end{minted}
\item \textbf{Create a Tag for Release}:
Create and push a tag, using semver\footnote{\url{https://semver.org}}, to trigger the GitHub Actions workflow for building and releasing the document:
\begin{minted}[bgcolor=background]{sh}
git tag -a v1.0.0 -m “Version 1.0.0”
git push origin v1.0.0
\end{minted}
\item \textbf{Review GitHub Actions Workflow}:
The GitHub Actions workflow will automatically compile your LaTeX document and upload the resulting PDF as an artifact.
You can download the compiled PDF from the Actions tab in your repository.
\item \textbf{Sync with Overleaf}:
If you are using Overleaf, sync your GitHub repository with Overleaf to ensure you always have the latest version of your document.
\end{enumerate}

By following this workflow, you can efficiently manage your LaTeX documents, keep track of changes with Git, and automate the compilation and release process with GitHub Actions.


\section{Image Naming Convention}

To ensure compatibility with platforms like HAL, arXiv, and Overleaf, name your images with the \texttt{img-*} prefix and store them in the same directory as the \texttt{.tex} file.
Expand Down
7 changes: 7 additions & 0 deletions setup-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh


for i in commit checkout merge; do
cp hooks/post-commit .git/hooks/post-$i
chmod +x .git/hooks/post-$i
done

0 comments on commit b17e048

Please sign in to comment.