Generate Images from PlantUML and drawio (Debug Edition) #25
Workflow file for this run
This file contains hidden or 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 Images from PlantUML and drawio | |
| on: | |
| push: | |
| paths: | |
| - 'src/plantuml/**' | |
| - 'src/drawio/**' | |
| branches: | |
| - main | |
| - github_action_test | |
| workflow_dispatch: | |
| inputs: | |
| regenerate_all: | |
| description: 'Regenerate all images (not just changed ones)' | |
| required: false | |
| default: false | |
| type: boolean | |
| env: | |
| OUTPUT_DIR: images | |
| PLANTUML_PREFIX: uml | |
| DRAWIO_PREFIX: diagram | |
| jobs: | |
| generate_images: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 # Needed for git diff HEAD~1 | |
| - name: Create output directory | |
| run: | | |
| mkdir -p ${{ env.OUTPUT_DIR }} | |
| echo "📁 Output directory: ${{ env.OUTPUT_DIR }}" | |
| echo "🔄 Regenerate all: ${{ github.event.inputs.regenerate_all || 'false' }}" | |
| - name: Debug - Check repository structure | |
| run: | | |
| echo "=== Repository structure ===" | |
| find . -name "*.puml" -o -name "*.plantuml" -o -name "*.drawio" -o -name "*.dio" | head -20 | |
| echo "=== src/plantuml contents ===" | |
| ls -la src/plantuml/ 2>/dev/null || echo "src/plantuml directory not found" | |
| echo "=== src/drawio contents ===" | |
| ls -la src/drawio/ 2>/dev/null || echo "src/drawio directory not found" | |
| - name: Set up JDK 11 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '11' | |
| - name: Download and setup PlantUML | |
| run: | | |
| wget https://github.com/plantuml/plantuml/releases/latest/download/plantuml.jar -O /tmp/plantuml.jar | |
| echo "PlantUML downloaded successfully" | |
| java -jar /tmp/plantuml.jar -version | |
| - name: Generate PlantUML images (incremental) | |
| continue-on-error: true | |
| run: | | |
| echo "=== Generating PlantUML images ===" | |
| output_abs=$(pwd)/${{ env.OUTPUT_DIR }} | |
| # Check if we should regenerate all or just changed files | |
| if [ "${{ github.event.inputs.regenerate_all }}" = "true" ]; then | |
| echo "🔄 FULL REGENERATION MODE - Processing all files" | |
| puml_files=$(find $(pwd)/src/plantuml -name "*.puml" -o -name "*.plantuml" 2>/dev/null) | |
| if [ -z "$puml_files" ]; then | |
| echo "❌ No PlantUML files found in src/plantuml/" | |
| exit 0 | |
| fi | |
| echo "Found PlantUML files:" | |
| echo "$puml_files" | |
| else | |
| echo "⚡ INCREMENTAL MODE - Processing only changed files" | |
| # Get list of changed .puml files in this commit | |
| changed_puml_files=$(git diff --name-only HEAD~1 HEAD | grep -E '\.(puml|plantuml)$' | grep '^src/plantuml/' || true) | |
| if [ -z "$changed_puml_files" ]; then | |
| echo "No PlantUML files changed in this commit" | |
| exit 0 | |
| fi | |
| echo "Changed PlantUML files:" | |
| echo "$changed_puml_files" | |
| puml_files="$changed_puml_files" | |
| fi | |
| for file in $puml_files; do | |
| # Convert relative path to absolute if needed | |
| if [[ "$file" != /* ]]; then | |
| file="$(pwd)/$file" | |
| fi | |
| # Only process if file still exists (not deleted) | |
| if [ -f "$file" ]; then | |
| echo "Processing: $file" | |
| base=$(basename "$file" | sed 's/\.[^.]*$//') | |
| # Test PlantUML syntax first | |
| echo "Testing syntax for: $file" | |
| java -jar /tmp/plantuml.jar -syntax "$file" || echo "Syntax check failed" | |
| # Generate PNG | |
| echo "Generating PNG for: $file" | |
| java -jar /tmp/plantuml.jar -v -tpng "$file" -o "$output_abs" 2>&1 | tee /tmp/plantuml.log | |
| if [ -f "$output_abs/${base}.png" ]; then | |
| mv "$output_abs/${base}.png" "$output_abs/${{ env.PLANTUML_PREFIX }}_${base}.png" | |
| echo "✅ Generated PNG: ${{ env.PLANTUML_PREFIX }}_${base}.png" | |
| else | |
| echo "❌ PNG not created for $file" | |
| cat /tmp/plantuml.log || true | |
| fi | |
| # Generate SVG | |
| echo "Generating SVG for: $file" | |
| java -jar /tmp/plantuml.jar -v -tsvg "$file" -o "$output_abs" 2>&1 | |
| if [ -f "$output_abs/${base}.svg" ]; then | |
| mv "$output_abs/${base}.svg" "$output_abs/${{ env.PLANTUML_PREFIX }}_${base}.svg" | |
| echo "✅ Generated SVG: ${{ env.PLANTUML_PREFIX }}_${base}.svg" | |
| else | |
| echo "❌ SVG not created for $file" | |
| fi | |
| else | |
| # File was deleted - remove corresponding images | |
| base=$(basename "$file" | sed 's/\.[^.]*$//') | |
| rm -f "$output_abs/${{ env.PLANTUML_PREFIX }}_${base}.png" | |
| rm -f "$output_abs/${{ env.PLANTUML_PREFIX }}_${base}.svg" | |
| echo "🗑️ Removed images for deleted file: $file" | |
| fi | |
| echo "--- Next file ---" | |
| done | |
| - name: Generate Draw.io images (incremental) | |
| continue-on-error: true | |
| run: | | |
| echo "=== Generating drawio images ===" | |
| # Check if we should regenerate all or just changed files | |
| if [ "${{ github.event.inputs.regenerate_all }}" = "true" ]; then | |
| echo "🔄 FULL REGENERATION MODE - Processing all files" | |
| drawio_files=$(find src/drawio -name "*.drawio" -o -name "*.dio" 2>/dev/null) | |
| if [ -z "$drawio_files" ]; then | |
| echo "No drawio files found in src/drawio/" | |
| exit 0 | |
| fi | |
| echo "Found drawio files:" | |
| echo "$drawio_files" | |
| else | |
| echo "⚡ INCREMENTAL MODE - Processing only changed files" | |
| # Get list of changed .drawio files in this commit | |
| changed_drawio_files=$(git diff --name-only HEAD~1 HEAD | grep -E '\.(drawio|dio)$' | grep '^src/drawio/' || true) | |
| if [ -z "$changed_drawio_files" ]; then | |
| echo "No drawio files changed in this commit" | |
| exit 0 | |
| fi | |
| echo "Changed drawio files:" | |
| echo "$changed_drawio_files" | |
| drawio_files="$changed_drawio_files" | |
| fi | |
| for file in $drawio_files; do | |
| if [ -f "$file" ]; then | |
| echo "Processing: $file" | |
| base=$(basename "$file" | sed 's/\.[^.]*$//') | |
| # Generate PNG | |
| docker run --rm \ | |
| -v $(pwd):/data \ | |
| rlespinasse/drawio-export:4.4.0 \ | |
| --format png \ | |
| --output "${{ env.OUTPUT_DIR }}" \ | |
| "$file" | |
| # Rename with prefix | |
| if [ -f "${{ env.OUTPUT_DIR }}/${base}.png" ]; then | |
| mv "${{ env.OUTPUT_DIR }}/${base}.png" "${{ env.OUTPUT_DIR }}/${{ env.DRAWIO_PREFIX }}_${base}.png" | |
| echo "✅ Generated PNG: ${{ env.DRAWIO_PREFIX }}_${base}.png" | |
| fi | |
| # Generate SVG | |
| docker run --rm \ | |
| -v $(pwd):/data \ | |
| rlespinasse/drawio-export:4.4.0 \ | |
| --format svg \ | |
| --output "${{ env.OUTPUT_DIR }}" \ | |
| "$file" | |
| # Rename with prefix | |
| if [ -f "${{ env.OUTPUT_DIR }}/${base}.svg" ]; then | |
| mv "${{ env.OUTPUT_DIR }}/${base}.svg" "${{ env.OUTPUT_DIR }}/${{ env.DRAWIO_PREFIX }}_${base}.svg" | |
| echo "✅ Generated SVG: ${{ env.DRAWIO_PREFIX }}_${base}.svg" | |
| fi | |
| else | |
| # File was deleted - remove corresponding images | |
| base=$(basename "$file" | sed 's/\.[^.]*$//') | |
| rm -f "${{ env.OUTPUT_DIR }}/${{ env.DRAWIO_PREFIX }}_${base}.png" | |
| rm -f "${{ env.OUTPUT_DIR }}/${{ env.DRAWIO_PREFIX }}_${base}.svg" | |
| echo "🗑️ Removed images for deleted file: $file" | |
| fi | |
| done | |
| - name: Show results | |
| run: | | |
| echo "=== Generated files ===" | |
| ls -la ${{ env.OUTPUT_DIR }}/ 2>/dev/null || echo "No images directory" | |
| echo "=== Git Status ===" | |
| git status | |
| - name: Commit generated images | |
| run: | | |
| git config --global user.name 'GitHub Actions' | |
| git config --global user.email 'actions@github.com' | |
| if [ -d "${{ env.OUTPUT_DIR }}" ] && [ "$(ls -A ${{ env.OUTPUT_DIR }})" ]; then | |
| git add ${{ env.OUTPUT_DIR }}/ | |
| # Count changes | |
| changed_count=$(git diff --staged --name-only | wc -l) | |
| if [ "$changed_count" -gt 0 ]; then | |
| if [ "${{ github.event.inputs.regenerate_all }}" = "true" ]; then | |
| git commit -m "🔄 Regenerate all images from PlantUML and drawio files" | |
| else | |
| git commit -m "⚡ Auto-update images for changed PlantUML/drawio files ($changed_count files)" | |
| fi | |
| git push | |
| echo "✅ $changed_count image files committed and pushed" | |
| else | |
| echo "No changes to commit" | |
| fi | |
| else | |
| echo "❌ No images to commit" | |
| fi |