-
Notifications
You must be signed in to change notification settings - Fork 4
248 lines (209 loc) · 9.41 KB
/
automatic_image_genration.yml
File metadata and controls
248 lines (209 loc) · 9.41 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
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