-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (72 loc) · 2.96 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
name: Generate STL and Thumbnails using OpenSCAD
on:
push:
paths:
- "*/**/*.scad"
- "*/**/*.txt"
- ".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
- 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,45,45,0,100"
"0,0,0,45,-45,180,100"
"0,0,0,-45,45,0,100"
"0,0,0,-45,-45,0,100"
)
count=0
for angle in "${angles[@]}"; do
count=$((count+1))
png_path="${scad%.scad}_$count.png"
openscad --camera=$angle --colorscheme="Tomorrow" --render --imgsize=512,512 -o $png_path $scad
done
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, WebP, and txt files)
run: |
find . ! -path "./.git/*" ! -name ".git" -type f ! \( -name "*.stl" -o -name "*.webp" -o -name "*.txt" \) -delete
- name: Generate index.html
run: |
echo "<!DOCTYPE html><html><head><link href='https://cdn.jsdelivr.net/npm/tailwindcss@2.2.16/dist/tailwind.min.css' rel='stylesheet'></head><body>" > index.html
for stl in $(find . -name "*.stl"); do
stlName=$(basename $stl)
echo "<h2 class='text-2xl font-bold'>$stlName</h2>" >> index.html
txtPath="${stl%.stl}.txt"
if [[ -f $txtPath ]]; then
echo "<p>$(cat $txtPath | sed 's/$/<br \/>/')</p>" >> index.html
fi
echo "<div class='grid grid-cols-4 gap-4'>" >> index.html
for i in {1..4}; do
webp="${stl%.stl}_$i.webp"
baseName=$(basename -s .webp $webp)
echo "<img class='w-24 h-24' src='$webp' title='$baseName'>" >> index.html
done
echo "</div>" >> index.html
done
echo "</body></html>" >> index.html
- name: Deploy to GitHub Pages
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<email>@users.noreply.github.com"
git checkout -b gh-pages
git add ./*.stl **/*.stl ./*.webp **/*.webp index.html
git commit -m "Update STL files and WebP thumbnails generated by GitHub Actions"
git push -f origin gh-pages