Update openscad_build.yml #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Generate STL and WebP Thumbnails using OpenSCAD | |
on: | |
push: | |
paths: | |
- "**/*.scad" | |
- ".github/workflows/**/*" | |
jobs: | |
build_and_deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- 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" "70,330,0" "140,0,0" "210,330,0") | |
for angle in "${angles[@]}"; do | |
png_path="${scad%.scad}_$(echo $angle | tr ',' '-').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 and WebP files) | |
run: | | |
find . ! -path "./.git/*" ! -name ".git" -type f ! \( -name "*.stl" -o -name "*.webp" \) -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 dir in $(find . -type d -not -path './.git*'); do | |
dirName=$(basename $dir) | |
echo "<h2 class='text-2xl font-bold'>$dirName</h2><div class='grid grid-cols-4 gap-4'>" >> index.html | |
for webp in $(find $dir -name "*.webp"); do | |
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 |