Skip to content

Commit

Permalink
add self texlive runner if available (#20)
Browse files Browse the repository at this point in the history
* add self-texlive runner if available #19

* use runner defined in workflow-setup

add self-texlive runner if available #19

* use new runner ubuntu-24.04

add self-texlive runner if available #19

* use runner defined by workflow-setup in release job

add self-texlive runner if available #19

* define token for gh

add self-texlive runner if available #19

* add self-texlive runner if available #19

* use token

* change perms

add self-texlive runner if available #19

* up token

add self-texlive runner if available #19

* up workflow: check token existence, it handles cases outside feelpp org

add self-texlive runner if available #19

* fix "

add self-texlive runner if available #19

* up docs

add self-texlive runner if available #19

* add script for doc inclusion

add self-texlive runner if available #19
  • Loading branch information
prudhomm authored Aug 14, 2024
1 parent f82839a commit f662b43
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 48 deletions.
105 changes: 77 additions & 28 deletions .github/workflows/latex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,63 @@ on:
- '*'

jobs:
build_latex:
runs-on: ubuntu-latest
name: Build LaTeX Artifact
workflow-setup:
name: Workflow Setup
runs-on: ubuntu-24.04
outputs:
prefix: ${{ steps.repo_name.outputs.prefix }}
prefixwithref: ${{ steps.repo_name.outputs.prefixwithref }}
pdf: ${{ steps.repo_name.outputs.pdf }}
tex: ${{ steps.repo_name.outputs.tex }}
env:
VERSION: ${{ github.ref_name }}
runner: ${{ steps.texlive_runner.outputs.runner }}
prefix: ${{ steps.doc_prefix.outputs.prefix }}
prefixwithref: ${{ steps.doc_prefix.outputs.prefixwithref }}
pdf: ${{ steps.doc_prefix.outputs.pdf }}
tex: ${{ steps.doc_prefix.outputs.tex }}
steps:
- name: Set up Git repository
uses: actions/checkout@v4
- name: Get TeXLive Runner
id: texlive_runner
run: |
if ! [ -z "$GH_TOKEN" ]; then
runners=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /orgs/feelpp/actions/runners)
texlive=$(echo $runners | jq --arg label "self-texlive" '[.runners[] | any(.labels[]; .name == $label) and .status == "online"] | any')
if [ "$texlive" = "false" ]; then
echo "runner=ubuntu-latest" >> "$GITHUB_OUTPUT"
else
echo "runner=self-texlive" >> "$GITHUB_OUTPUT"
fi
else
echo "runner=ubuntu-latest" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ secrets.TOKEN_RUNNER }}

- name: Get Repository Name
id: repo_name
- name: Get Document Prefix
id: doc_prefix
run: |
prefix=$(echo "${{ github.repository }}" | cut -d'/' -f2)
echo "prefix=$prefix" >> "$GITHUB_OUTPUT"
prefixwithref=$(echo "$prefix")-${{ github.ref_name }}
echo "prefixwithref=$prefixwithref" >> "$GITHUB_OUTPUT"
echo "pdf=$prefixwithref.pdf" >> "$GITHUB_OUTPUT"
echo "tex=$prefix.tex" >> "$GITHUB_OUTPUT"
-
name: Show Outputs
run: |
echo "runner=${{ steps.texlive_runner.outputs.runner }}"
echo "prefix=${{ steps.doc_prefix.outputs.prefix }}"
echo "prefixwithref=${{ steps.doc_prefix.outputs.prefixwithref }}"
echo "pdf=${{ steps.doc_prefix.outputs.pdf }}"
echo "tex=${{ steps.doc_prefix.outputs.tex }}"
build_latex:
needs: workflow-setup
runs-on: ${{ needs.workflow-setup.outputs.runner }}
name: Build LaTeX Artifact
env:
VERSION: ${{ github.ref_name }}
steps:
- name: Set up Git repository
uses: actions/checkout@v4
with:
clean: true

- name: Install hooks
run: |
Expand All @@ -39,72 +73,87 @@ jobs:
- name: Compile LaTeX document
uses: xu-cheng/latex-action@v3
if: ${{ needs.workflow-setup.outputs.runner == 'ubuntu-latest' }}
with:
root_file: ${{ steps.repo_name.outputs.tex }}
root_file: ${{ needs.workflow-setup.outputs.tex }}
latexmk_shell_escape: true
post_compile: "latexmk -c; rm -rf _minted*"

- name: Compile LaTeX document
if: ${{ needs.workflow-setup.outputs.runner == 'self-texlive' }}
run: |
latexmk -shell-escape -pdf -file-line-error -halt-on-error -interaction=nonstopmode ${{ needs.workflow-setup.outputs.tex }}
- name: Rename PDF
run: mv ${{ steps.repo_name.outputs.prefix }}.pdf ${{ steps.repo_name.outputs.pdf }}
run: mv ${{ needs.workflow-setup.outputs.prefix }}.pdf ${{ needs.workflow-setup.outputs.pdf }}

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.repo_name.outputs.prefixwithref }}
name: ${{ needs.workflow-setup.outputs.prefixwithref }}
path: |
./*.tex
./*.bib
./*.gin
./*.bbl
./${{ steps.repo_name.outputs.pdf }}
./${{ needs.workflow-setup.outputs.pdf }}
./README.adoc
./img-*
./release
./setup-hooks.sh
!./.git*
!./.github*
!./.vscode*
!./.idea*
!./.DS_Store*
!./.gitignore*
check:
needs: build_latex
runs-on: ubuntu-latest
needs: [build_latex,workflow-setup]
runs-on: ${{ needs.workflow-setup.outputs.runner }}
name: Check LaTeX Artifact
steps:
-
name: Download Artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.build_latex.outputs.prefixwithref }}
name: ${{ needs.workflow-setup.outputs.prefixwithref }}
path: ${{ github.workspace }}/artifact
-
name: List Artifact
run: ls -R ${{ github.workspace }}
-
name: Check compilation of LaTeX document from artifact
if: ${{ needs.workflow-setup.outputs.runner == 'ubuntu-latest' }}
uses: xu-cheng/latex-action@v3
with:
root_file: ${{ needs.build_latex.outputs.tex }}
root_file: ${{ needs.workflow-setup.outputs.tex }}
latexmk_shell_escape: true
post_compile: "latexmk -c; rm -rf _minted*"
working_directory: ${{ github.workspace }}/artifact
-
name: Check compilation of LaTeX document from artifact
if: ${{ needs.workflow-setup.outputs.runner == 'self-texlive' }}
run: |
latexmk -shell-escape -pdf -file-line-error -halt-on-error -interaction=nonstopmode ${{ needs.workflow-setup.outputs.tex }}
working-directory: ${{ github.workspace }}/artifact

release:
needs: [build_latex, check]
runs-on: ubuntu-latest
needs: [workflow-setup,build_latex, check]
runs-on: ${{ needs.workflow-setup.outputs.runner }}
name: Create Release
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.build_latex.outputs.prefixwithref }}
name: ${{ needs.workflow-setup.outputs.prefixwithref }}
path: ${{ github.workspace }}/artifact

- name: Archive Article
run: |
temp_dir=$(mktemp -d)
tar -czvf "${temp_dir}/${{ needs.build_latex.outputs.prefixwithref }}.tar.gz" -C artifact ./
mv "${temp_dir}/${{ needs.build_latex.outputs.prefixwithref }}.tar.gz" ./
tar -czvf "${temp_dir}/${{ needs.workflow-setup.outputs.prefixwithref }}.tar.gz" -C artifact ./
mv "${temp_dir}/${{ needs.workflow-setup.outputs.prefixwithref }}.tar.gz" ./
rm -rf "$temp_dir"
- name: Create Release
Expand All @@ -118,5 +167,5 @@ jobs:
tag_name: ${{ github.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
files: |
artifact/${{ needs.build_latex.outputs.prefixwithref }}.pdf
${{ needs.build_latex.outputs.prefixwithref }}.tar.gz
artifact/${{ needs.workflow-setup.outputs.prefixwithref }}.pdf
${{ needs.workflow-setup.outputs.prefixwithref }}.tar.gz
38 changes: 20 additions & 18 deletions article.template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ \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.

\inputminted[linenos,autogobble,bgcolor=background,fontsize=\small]{sh}{setup-hooks.sh}

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.

Expand All @@ -104,11 +106,23 @@ \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.

The template article repository workflow uses \citep{cheng_xu_xu-chenglatex-action_2024} \mintinline{bash}{xu-cheng/latex-action} to build the latex document.

The GitHub Action workflow:
\begin{itemize}
\item Compiles the LaTeX document using \mintinline{bash}{xu-cheng/latex-action} on \texttt{ubuntu-latest} runner or \texttt{self-texlive} runner hosted on \texttt{feelpp} organisation.
\item Uploads the resulting PDF
\item Creates a release with the PDF as an asset when a new tag is pushed of the type \texttt{v*}, e.g., \texttt{v1.0.0}.
\end{itemize}

\subsection{Full Article Workflow}
\label{sec: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{Check out the organisation}: if the organisation is \texttt{feelpp} and a \texttt{self-texlive} labelled runner is online, the compilation will be done using the \texttt{self-texlive} runner other it will use the \texttt{ubuntu-latest} runner.
\item \textbf{Clone the Repository}:
Clone the repository to your local machine:
\begin{minted}[bgcolor=background]{sh}
Expand Down Expand Up @@ -146,12 +160,16 @@ \subsection{Full Article Workflow}

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.

\subsection{Release Script}
\subsection{Document Release}

The `release` script simplifies creating and listing releases for your LaTeX document.

\inputminted[linenos, fontsize=\small, bgcolor=background]{sh}{release}



\begin{description}
\item[Create a New Release]: To create a new release, use the following command:
\item[Create a New Release]: To create a new release on GitHub, use the following command:
\begin{minted}[bgcolor=background]{sh}
./release create v1.0.0
\end{minted}
Expand Down Expand Up @@ -224,23 +242,7 @@ \subsection{Cite References in Your LaTeX Document}
As shown by \citet{AuthorYear}, this method is effective.
\end{minted}

\section{GitHub Action Workflow for LaTeX Compilation}

The template article repository workflow uses \citep{cheng_xu_xu-chenglatex-action_2024} \mintinline{bash}{xu-cheng/latex-action} to build the latex document.

The GitHub Action workflow:
\begin{itemize}
\item Compiles the LaTeX document using \mintinline{bash}{xu-cheng/latex-action}
\item Uploads the resulting PDF
\item Creates a release with the PDF as an asset when a new tag is pushed of the type \texttt{v*}, e.g., \texttt{v1.0.0} or a pre-release \texttt{v1.0.0-preview.1}
\end{itemize}

To create a git tag, do the following:

\begin{minted}[bgcolor=background]{bash}
git tag -a v1.0.0 -m "Version 1.0.0"
git push origin v1.0.0
\end{minted}

\section{Steps to Use the Template Repository}

Expand Down
2 changes: 1 addition & 1 deletion release
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ create_release() {
exit 1
fi


# Tag the repository with the provided version
git tag -a "$VERSION" -m "Release $VERSION"

Expand Down
1 change: 0 additions & 1 deletion setup-hooks.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh


for i in commit checkout merge; do
cp hooks/post-commit .git/hooks/post-$i
Expand Down

0 comments on commit f662b43

Please sign in to comment.