Skip to content

file rename for sequenzdiagram #90

file rename for sequenzdiagram

file rename for sequenzdiagram #90

name: Automatic Image Generation
on:
push:
paths:
- 'src/plantuml/**'
- 'src/drawio/**'
- '.github/workflows/generate_images.yml'
workflow_dispatch:
jobs:
generate_images:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
# fetch-depth: 0 # Not strictly needed anymore, default checkout is usually fine
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends graphviz xvfb
# Install drawio via snap
sudo snap remove drawio
sudo snap install drawio
# Wait a moment for snap changes to propagate if needed
sleep 5
- name: Download PlantUML jar
run: |
wget https://github.com/plantuml/plantuml/releases/latest/download/plantuml.jar -O /tmp/plantuml.jar
- name: Generate images from PlantUML files
id: generate_plantuml
run: |
set -e
GENERATED_COUNT=0
shopt -s nullglob # Ensure loop doesn't run if find returns nothing
while IFS= read -r -d $'\0' file; do
echo "Checking PlantUML file: $file"
output_dir=$(dirname "$file" | sed 's|^src/plantuml|images|')
image_base=$(basename "$file" .puml)
png_path="$output_dir/$image_base.png"
svg_path="$output_dir/$image_base.svg"
# Regenerate if PNG or SVG is missing, OR if the source file is newer than PNG or SVG
if [ ! -f "$png_path" ] || [ ! -f "$svg_path" ] || { [ -f "$png_path" ] && [ "$file" -nt "$png_path" ]; } || { [ -f "$svg_path" ] && [ "$file" -nt "$svg_path" ]; }; then
echo "-> Generating images for $file"
mkdir -p "$output_dir"
# Run generation commands
java -jar /tmp/plantuml.jar -tpng "$file" -o "$output_dir"
java -jar /tmp/plantuml.jar -tsvg "$file" -o "$output_dir"
# Verify files were created (for debugging)
if [ -f "$png_path" ] && [ -f "$svg_path" ]; then
echo " Successfully generated: $png_path and $svg_path"
GENERATED_COUNT=$((GENERATED_COUNT + 1))
else
echo " ERROR: Failed to generate images for $file" >&2
# Consider failing the step: exit 1
fi
else
echo "-> Images for $file are up-to-date."
fi
done < <(find src/plantuml -name "*.puml" -print0) # Use process substitution
echo "Generated/Updated $GENERATED_COUNT PlantUML image sets."
# Set output flag if any images were generated
if [ "$GENERATED_COUNT" -gt 0 ]; then
echo "plantuml_generated=true" >> $GITHUB_OUTPUT
else
echo "plantuml_generated=false" >> $GITHUB_OUTPUT
fi
shell: bash # Explicitly use bash for process substitution
- name: Generate images from drawio files
id: generate_drawio
run: |
set -e
GENERATED_COUNT=0
shopt -s nullglob # Ensure loop doesn't run if find returns nothing
while IFS= read -r -d $'\0' file; do
echo "Checking drawio file: $file"
output_dir=$(dirname "$file" | sed 's|^src/drawio|images|')
image_base=$(basename "$file" .drawio)
png_path="$output_dir/$image_base.png"
svg_path="$output_dir/$image_base.svg"
# Regenerate if PNG or SVG is missing, OR if the source file is newer than PNG or SVG
if [ ! -f "$png_path" ] || [ ! -f "$svg_path" ] || { [ -f "$png_path" ] && [ "$file" -nt "$png_path" ]; } || { [ -f "$svg_path" ] && [ "$file" -nt "$svg_path" ]; }; then
echo "-> Generating images for $file"
mkdir -p "$output_dir"
# Add --no-sandbox and try disabling gpu explicitly for drawio CLI in xvfb
xvfb-run --auto-servernum drawio --no-sandbox --disable-gpu --export --format png --output "$png_path" "$file"
xvfb-run --auto-servernum drawio --no-sandbox --disable-gpu --export --format svg --output "$svg_path" "$file"
# Verify files were created (for debugging)
if [ -f "$png_path" ] && [ -f "$svg_path" ]; then
echo " Successfully generated: $png_path and $svg_path"
GENERATED_COUNT=$((GENERATED_COUNT + 1))
else
echo " ERROR: Failed to generate images for $file" >&2
# Consider failing the step: exit 1
fi
else
echo "-> Images for $file are up-to-date."
fi
done < <(find src/drawio -name "*.drawio" -print0) # Use process substitution
echo "Generated/Updated $GENERATED_COUNT drawio image sets."
# Set output flag if any images were generated
if [ "$GENERATED_COUNT" -gt 0 ]; then
echo "drawio_generated=true" >> $GITHUB_OUTPUT
else
echo "drawio_generated=false" >> $GITHUB_OUTPUT
fi
shell: bash # Explicitly use bash for process substitution
- name: Show Git Status for Images
# Run always to see the state before commit attempt
run: |
echo "--- Git Status for images directory ---"
git status --porcelain images || echo "No changes or untracked files in images directory."
echo "--- Listing images directory ---"
ls -R images || echo "Images folder does not exist or is empty."
- name: Commit and push generated images
# Use the outputs from the generation steps. Only proceed if something was potentially generated.
if: steps.generate_plantuml.outputs.plantuml_generated == 'true' || steps.generate_drawio.outputs.drawio_generated == 'true'
run: |
echo "Checking for changes in 'images' directory to commit..."
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# Stage ALL changes within the 'images' directory (new, modified, deleted)
git add images
# Check if there's anything staged within the 'images' pathspec
if git diff --staged --quiet -- images; then
echo "No staged changes detected in 'images' directory after 'git add'. Nothing to commit."
exit 0
fi
echo "Staged changes found. Committing..."
git commit -m "chore: Generate/update images from source files" -m "Generated by GitHub Action."
echo "Pushing changes..."
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}