Skip to content

Commit a298fb1

Browse files
committed
setup article.template workflow
#1
1 parent 53b31f1 commit a298fb1

8 files changed

+242
-13
lines changed

.github/workflows/latex.yml

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
name: Compile Latex and Release PDF
3+
4+
5+
on:
6+
push:
7+
tags:
8+
- 'v*'
9+
branches:
10+
- '*'
11+
12+
13+
jobs:
14+
build_latex:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
prefix: ${{ steps.repo_name.outputs.prefix }}
18+
prefixwithref: ${{ steps.repo_name.outputs.prefixwithref }}
19+
pdf: ${{ steps.repo_name.outputs.pdf }}
20+
tex: ${{ steps.repo_name.outputs.tex }}
21+
env:
22+
VERSION: ${{ github.ref_name }}
23+
steps:
24+
- name: Set up Git repository
25+
uses: actions/checkout@v4
26+
- name: Get Repository Name
27+
id: repo_name
28+
run: |
29+
ls -lrt
30+
prefix=$(echo "${{ github.repository }}" | cut -d'/' -f2)
31+
echo "prefix=$prefix" >> "$GITHUB_OUTPUT"
32+
prefixwithref=$(echo "$prefix")-${{ github.ref_name }}
33+
echo "prefixwithref=$prefixwithref" >> "$GITHUB_OUTPUT"
34+
echo "pdf=$prefixwithref.pdf" >> "$GITHUB_OUTPUT"
35+
echo "tex=$prefix.tex" >> "$GITHUB_OUTPUT"
36+
- name: Install hooks
37+
run: |
38+
sh ./setup-hooks.sh
39+
git checkout ${{ github.ref }} # checkout the branch or tag to update gitinfo2
40+
- name: Compile LaTeX document
41+
uses: xu-cheng/latex-action@v3
42+
with:
43+
root_file: ${{ steps.repo_name.outputs.tex }}
44+
latexmk_shell_escape: true
45+
post_compile: "latexmk -c; rm -rf _minted*"
46+
-
47+
name: Rename PDF
48+
run: |
49+
mv ${{ steps.repo_name.outputs.prefix }}.pdf ${{ steps.repo_name.outputs.pdf }}
50+
51+
- name: Archive Article
52+
run: |
53+
temp_dir=$(mktemp -d)
54+
tar -czvf "${temp_dir}/${{ steps.repo_name.outputs.prefixwithref }}.tar.gz" --exclude="*.git*" --exclude="*.github*" --exclude="*.vscode*" --exclude="*.idea*" --exclude="*.gitignore" --exclude="*.DS_Store*" ./
55+
mv "${temp_dir}/${{ steps.repo_name.outputs.prefixwithref }}.tar.gz" ./
56+
rm -rf "$temp_dir"
57+
58+
- name: Upload Artifact
59+
uses: actions/upload-artifact@v4.1.0
60+
with:
61+
# get the name of the repo without the organisation
62+
name: ${{ steps.repo_name.outputs.prefixwithref }}
63+
path: |
64+
./
65+
!./.git*
66+
!./.github*
67+
!./.vscode*
68+
!./.idea*
69+
!./.DS_Store*
70+
!./.gitignore*
71+
72+
-
73+
name: Create Release
74+
id: create_release
75+
if: startsWith(github.ref, 'refs/tags/v')
76+
uses: softprops/action-gh-release@v2
77+
with:
78+
draft: false
79+
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') || contains(github.ref, 'preview') }}
80+
name: Release ${{ github.ref_name }}
81+
generate_release_notes: true
82+
tag_name: ${{ github.ref }}
83+
token: ${{ secrets.GITHUB_TOKEN }}
84+
files: |
85+
${{ steps.repo_name.outputs.pdf }}
86+
${{ steps.repo_name.outputs.prefixwithref }}.tar.gz

.gitignore

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,15 @@
55
*.dvi
66
*.fdb_latexmk
77
*.fls
8+
*.bbl
9+
*.fls
10+
*.tdo
11+
*.blg
12+
*.toc
813
.venv
9-
checkdir.tex
14+
checkdir.tex
15+
*.DS_Store*
16+
article.hid2-ub-cicd.ppam24.pdf
17+
hid2-urban-building-cicd-diff.pdf
18+
main-d.pdf
19+
main-d.tex
File renamed without changes.

compress.py

+22-12
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,37 @@
22
import os
33

44

5-
def compress_images(directory, quality=85):
5+
def resize_and_compress_images(directory, max_width, max_height, quality=85):
66
if not os.path.exists(directory):
77
print("Directory does not exist")
88
return
99

10-
output_directory = os.path.join(directory, "compressed")
10+
output_directory = os.path.join(directory, "processed")
1111
if not os.path.exists(output_directory):
1212
os.makedirs(output_directory)
1313

1414
for filename in os.listdir(directory):
15-
if filename.endswith(".jpg") or filename.endswith(".jpeg"):
16-
img = Image.open(os.path.join(directory, filename))
17-
img.save(os.path.join(output_directory, filename),
18-
"JPEG", quality=quality)
19-
elif filename.endswith(".png"):
20-
img = Image.open(os.path.join(directory, filename))
21-
img.save(os.path.join(output_directory, filename),
22-
"PNG", optimize=True, quality=quality)
15+
print(f"Processing {filename}")
16+
if filename.endswith(".jpg") or filename.endswith(".jpeg") or filename.endswith(".png"):
17+
img_path = os.path.join(directory, filename)
18+
with Image.open(img_path) as img:
19+
# Calculate the new size preserving the aspect ratio
20+
img.thumbnail((max_width, max_height), Image.Resampling.LANCZOS)
21+
# Save the processed image
22+
if filename.endswith(".jpg") or filename.endswith(".jpeg"):
23+
img.save(os.path.join(output_directory, filename),
24+
"JPEG", quality=quality)
25+
elif filename.endswith(".png"):
26+
img.save(os.path.join(output_directory, filename),
27+
"PNG", optimize=True, quality=quality)
2328

24-
print(f"Images compressed and saved to {output_directory}")
29+
print(f"Images resized and compressed, saved to {output_directory}")
2530

2631

32+
# Set the directory path to your image folder
2733
directory = 'images'
28-
compress_images(directory,quality=50)
34+
# Set the maximum width and height for the images (in pixels)
35+
max_width = 595 # A4 width in points (1 point = 1/72 inch)
36+
max_height = 842 # A4 height in points
37+
38+
resize_and_compress_images(directory, max_width, max_height)

hooks/post-commit

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
# Copyright 2015 Brent Longborough
3+
# Part of gitinfo2 package Version 2
4+
# Release 2.0.7 2015-11-22
5+
# Please read gitinfo2.pdf for licencing and other details
6+
# -----------------------------------------------------
7+
# Post-{commit,checkout,merge} hook for the gitinfo2 package
8+
#
9+
# Get the first tag found in the history from the current HEAD
10+
FIRSTTAG=$(git describe --tags --always --dirty='-*' 2>/dev/null)
11+
# Get the first tag in history that looks like a Release
12+
RELTAG=$(git describe --tags --long --always --dirty='-*' --match 'v[0-9]*\.[0-9]*\.[0-9]*' 2>/dev/null)
13+
# Hoover up the metadata
14+
git --no-pager log -1 --date=short --decorate=short \
15+
--pretty=format:"\usepackage[%
16+
shash={%h},
17+
lhash={%H},
18+
authname={%an},
19+
authemail={%ae},
20+
authsdate={%ad},
21+
authidate={%ai},
22+
authudate={%at},
23+
commname={%cn},
24+
commemail={%ce},
25+
commsdate={%cd},
26+
commidate={%ci},
27+
commudate={%ct},
28+
refnames={%d},
29+
firsttagdescribe={$FIRSTTAG},
30+
reltag={$RELTAG}
31+
]{gitexinfo}" HEAD > .git/gitHeadInfo.gin
32+
33+

package.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"description": "Ktirio Urban Building",
3+
"scripts": {
4+
"readme": "npx downdoc README.adoc"
5+
},
6+
"devDependencies": {
7+
"downdoc": "^1.0.2"
8+
}
9+
}

release

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
# Exit immediately if a command exits with a non-zero status
4+
set -e
5+
6+
# Function to create a release
7+
create_release() {
8+
VERSION=$1
9+
10+
if [ -z "$VERSION" ]; then
11+
echo "Usage: $0 create vx.y.z"
12+
exit 1
13+
fi
14+
15+
# Tag the repository with the provided version
16+
git tag -a "$VERSION" -m "Release $VERSION"
17+
18+
# Checkout the tag to trigger post-commit hook to update gitinfo2 info file
19+
git checkout
20+
21+
# show the reltag line of .git/gitHeadInfo.gin
22+
grep reltag .git/gitHeadInfo.gin
23+
24+
cp .git/gitHeadInfo.gin gitHeadLocal.gin
25+
26+
git add gitHeadLocal.gin
27+
git commit -m "Updated gitHeadLocal.gin for release $VERSION"
28+
git tag -f -a "$VERSION" -m "Release $VERSION"
29+
30+
# Push the changes and the tags
31+
git push origin main --follow-tags
32+
33+
echo "Release $VERSION created and pushed successfully."
34+
}
35+
36+
# Function to list releases
37+
list_releases() {
38+
git tag
39+
}
40+
41+
# Function to delete a release
42+
delete_release() {
43+
VERSION=$1
44+
45+
if [ -z "$VERSION" ]; then
46+
echo "Usage: $0 delete vx.y.z"
47+
exit 1
48+
fi
49+
50+
# Delete the tag locally
51+
git tag -d "$VERSION"
52+
53+
# Delete the tag remotely
54+
#git push origin --delete "$VERSION"
55+
56+
echo "Release $VERSION deleted successfully."
57+
}
58+
59+
# Main script logic
60+
case "$1" in
61+
create)
62+
create_release "$2"
63+
;;
64+
list)
65+
list_releases
66+
;;
67+
delete)
68+
delete_release "$2"
69+
;;
70+
*)
71+
echo "Usage: $0 {create|list|delete} [version]"
72+
exit 1
73+
;;
74+
esac

setup-hooks.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
4+
for i in commit checkout merge; do
5+
cp hooks/post-commit .git/hooks/post-$i
6+
chmod +x .git/hooks/post-$i
7+
done

0 commit comments

Comments
 (0)