Skip to content

Commit

Permalink
merge scripts into a single cli (#22)
Browse files Browse the repository at this point in the history
* merge scripts into a single cli #21

* up docs with new script a.cli

merge scripts into a single cli #21

* fix ci

* minor fix

merge scripts into a single cli #21

* up

* use bash

* fix artifact, add a.cli

merge scripts into a single cli #21
  • Loading branch information
prudhomm authored Aug 17, 2024
1 parent 1591d4f commit 188f979
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 24 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/latex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ jobs:

- name: Install hooks
run: |
sh ./setup-hooks.sh
git checkout ${{ github.ref }} # checkout the branch or tag to update gitinfo2
bash ./a.cli setup
- name: Compile LaTeX document
uses: xu-cheng/latex-action@v3
Expand Down Expand Up @@ -98,9 +97,10 @@ jobs:
./*.bbl
./${{ needs.workflow-setup.outputs.pdf }}
./README.adoc
./img-*
./release
./setup-hooks.sh
./img*
./dat*
./*.png
./a.cli
!./.git*
!./.github*
!./.vscode*
Expand Down
33 changes: 30 additions & 3 deletions release → a.cli
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
# Exit immediately if a command exits with a non-zero status
set -e

# setup hooks
setup() {

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

git checkout

if ! test -f .git/gitHeadInfo.gin; then
cp .git/gitHeadInfo.gin gitHeadLocal.gin

git add gitHeadLocal.gin
git commit -m "Created gitHeadLocal.gin for initial setup"
fi
}

# Function to create a release
create_release() {
VERSION=$1
Expand Down Expand Up @@ -48,7 +67,7 @@ create_release() {

# Function to list releases
list_releases() {
git tag
git tag --sort=-creatordate | head -n $1
}

# Function to delete a release
Expand All @@ -71,17 +90,25 @@ delete_release() {

# Main script logic
case "$1" in
setup)
setup
;;
create)
create_release "$2"
;;
list)
list_releases
list_releases "${2:-5}"
;;
delete)
delete_release "$2"
;;
*)
echo "Usage: $0 {create|list|delete} [version]"
echo "Usage: $0 {setup|create|list|delete} [version]"
echo " setup : Setup hooks for commit, checkout, and merge"
echo " create : Create a new release with the provided version"
echo " list : List all existing releases"
echo " delete : Delete the release with the provided version"
echo " version : Optional argument specifying the version for create and delete commands"
exit 1
;;
esac
24 changes: 14 additions & 10 deletions article.template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,13 @@ \subsection{Configuration}
\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 repository includes the script \mintinline{sh}|a.cli| to simplify the installation of these hooks with the command:

\inputminted[linenos,autogobble,bgcolor=background,fontsize=\small]{sh}{setup-hooks.sh}
\begin{minted}[bgcolor=background]{sh}
./a.cli setup
\end{minted}

\inputminted[linenos,autogobble,bgcolor=background,fontsize=\small,firstline=6,lastline=23]{sh}{a.cli}

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 @@ -103,7 +107,7 @@ \subsection{Setting Up Git Hooks}

\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.
The GitHub Actions workflow is configured to run the command \mintinline{sh}|a.cli setup|, 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.
Expand All @@ -130,9 +134,9 @@ \subsection{Full Article Workflow}
cd your-repo
\end{minted}
\item \textbf{Set Up Git Hooks}:
Run the setup-hooks.sh script to set up the necessary Git hooks:
Run the \mintinline[bgcolor=background]{sh}|a.cli| script to set up the necessary Git hooks:
\begin{minted}[bgcolor=background]{sh}
./setup-hooks.sh
./a.cli setup
\end{minted}
\item \textbf{Compile the Document}:
Compile the LaTeX document to generate the PDF:
Expand All @@ -149,7 +153,7 @@ \subsection{Full Article Workflow}
\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}
./release create v1.0.0
./a.cli create 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.
Expand All @@ -164,22 +168,22 @@ \subsection{Document Release}

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

\inputminted[linenos, fontsize=\small, bgcolor=background]{sh}{release}
\inputminted[linenos, fontsize=\small, bgcolor=background,firstline=25,lastline=66]{sh}{a.cli}



\begin{description}
\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
./a.cli create v1.0.0
\end{minted}
\item[List All Releases]: To list all releases, use the following command:
\begin{minted}[bgcolor=background]{sh}
./release list
./a.cli list
\end{minted}
\item[Delete a Release]: To delete a release, use the following command:
\begin{minted}[bgcolor=background]{sh}
./release delete v1.0.0
./a.cli delete v1.0.0
\end{minted}

\end{description}
Expand Down
6 changes: 0 additions & 6 deletions setup-hooks.sh

This file was deleted.

0 comments on commit 188f979

Please sign in to comment.