-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (98 loc) · 4.91 KB
/
openscad_build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Generate STL and Thumbnails using OpenSCAD
on:
push:
paths:
- "*/**/*.txt"
- "*/**/*.scad"
- ".github/workflows/**/*"
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install OpenSCAD, WebP tools, and Xvfb
run: |
sudo apt-get update
sudo apt-get install -y openscad webp xvfb imagemagick
- name: Generate STL files and multiple PNG thumbnails
run: |
xvfb-run -a --server-args="-screen 0 1024x768x24" bash -c '
find . -name "*.scad" | grep -v "^./lib/" | while read scad; do
stl_path="${scad%.scad}.stl"
openscad -o $stl_path $scad
angles=(
"0,0,0,65,0,25,100"
"0,0,0,65,0,205,100"
"0,0,0,25,25,25,100"
"0,0,0,-155,-25,0,100"
)
thumbnail_counter=1
for angle in "${angles[@]}"; do
png_path="${scad%.scad}_$thumbnail_counter.png"
openscad --camera=$angle --colorscheme="Tomorrow" --render --imgsize=512,512 -o $png_path $scad
thumbnail_counter=$((thumbnail_counter + 1))
done
done
'
- name: Combine thumbnails into a single image
run: |
find . -name "*.stl" | while read stl; do
base_name="${stl%.stl}"
output="${base_name}.png"
montage \
"${base_name}_1.png" "${base_name}_2.png" \
"${base_name}_3.png" "${base_name}_4.png" \
-geometry +0+0 -tile 2x2 \
$output
rm "${base_name}_1.png" "${base_name}_2.png" \
"${base_name}_3.png" "${base_name}_4.png"
done
- name: Convert PNG thumbnails to WebP
run: |
for png in $(find . -name "*.png"); do
cwebp $png -o ${png%.png}.webp
done
- name: Clean up directory (Only keep STL and WebP files and txt descriptions)
run: |
find . ! -path "./.git/*" ! -name ".git" -type f ! \( -name "*.stl" -o -name "*.webp" -o -name "*.txt" \) -exec rm -rf {} \;
- name: Generate index.html
run: |
repo_url="https://github.com/$GITHUB_REPOSITORY/blob/gh-pages"
echo "<!DOCTYPE html><html><head><link href='https://cdn.jsdelivr.net/npm/tailwindcss@2.2.16/dist/tailwind.min.css' rel='stylesheet'></head><body class='bg-gray-200'>" > index.html
echo '<div class="container mx-auto px-4">' >> index.html
echo "<h1 class='my-8 text-4xl font-extrabold leading-none tracking-tight text-gray-900'>$GITHUB_REPOSITORY</h1>" >> index.html
find . -name "*.stl" | sort | while read stl; do
scad_name="${stl%.stl}.scad"
txt_name="${stl%.stl}.txt"
thumbnail_name="${stl%.stl}.webp"
stl_link="https://github.com/$GITHUB_REPOSITORY/blob/gh-pages/${stl#./}"
github_link="https://github.com/$GITHUB_REPOSITORY/blob/main/$scad_name"
title="${stl#./}"
echo "<div class='bg-white w-full flex rounded overflow-hidden shadow-lg mb-8'>" >> index.html
echo " <div class='h-48 w-48 flex-none bg-cover rounded-l text-center overflow-hidden' style='background-image: url(\"$thumbnail_name\")'></div>" >> index.html
echo " <div class='px-4 py-2 flex flex-col justify-between leading-normal'>" >> index.html
echo " <div>" >> index.html
echo " <div class='text-gray-900 font-bold text-xl mb-2'>$title</div>" >> index.html
if [ -f $txt_name ]; then
echo " <div class='text-gray-700 text-sm'>" >> index.html
awk 'BEGIN{ORS="<br/>"} NF{print $0}' $txt_name | sed '$ s/<br\/>$//' >> index.html
echo " </div>" >> index.html
fi
echo " </div>" >> index.html
echo " <div>" >> index.html
echo " <a href='$github_link' class='inline-block bg-gray-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2'>View on GitHub</a>" >> index.html
echo " <a href='$stl_link' class='inline-block bg-gray-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2'>Preview STL</a>" >> index.html
echo " </div>" >> index.html
echo " </div>" >> index.html
echo "</div>" >> index.html
done
echo "</div></body></html>" >> index.html
- name: Deploy to GitHub Pages
run: |
git config user.name "GitHub Actions Bot"
git config user.email "masuidrive@users.noreply.githufullb.com"
git checkout -b gh-pages
git add **/*.stl **/*.webp index.html
git commit -m "Update STL files and thumbnails of https://github.com/$GITHUB_REPOSITORY"
git push -f origin gh-pages