-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ feat(PlantUML) generate images gh action
- Loading branch information
1 parent
21f0eae
commit 78ea4e9
Showing
5 changed files
with
84 additions
and
10 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Generate and Insert PlantUML SVG | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
[ main ] | ||
|
||
jobs: | ||
generate-and-insert: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'adopt-openjdk' | ||
java-version: '11' | ||
|
||
- name: Install PlantUML | ||
run: | | ||
mkdir -p ~/.local/bin | ||
wget https://sourceforge.net/projects/plantuml/files/plantuml.jar/download -O ~/.local/bin/plantuml.jar | ||
chmod +x ~/.local/bin/plantuml.jar | ||
- name: Generate SVG and update Markdown files | ||
run: | | ||
# Create directories for diagrams | ||
mkdir -p diagrams | ||
# Process each markdown file | ||
for file in $(find . -name '*.md'); do | ||
# Create a temporary file for updated content | ||
temp_file="updated_$(basename "$file")" | ||
# Read the file line by line | ||
while IFS= read -r line; do | ||
if [[ "$line" =~ ^@startuml ]]; then | ||
# Extract the PlantUML diagram block | ||
diagram="" | ||
while IFS= read -r diagram_line && [[ ! "$diagram_line" =~ ^@enduml ]]; do | ||
diagram+="$diagram_line\n" | ||
done | ||
# Generate the SVG | ||
svg_file="diagrams/$(basename "$file" .md)_diagram.svg" | ||
echo "$diagram" | java -jar ~/.local/bin/plantuml.jar -tsvg -pipe > "$svg_file" | ||
# Insert SVG image link into temporary file | ||
echo "![Diagram]($svg_file)" >> "$temp_file" | ||
echo "" >> "$temp_file" # Add a blank line after the image link | ||
# Add the PlantUML block to the temporary file | ||
echo "$line" >> "$temp_file" | ||
while IFS= read -r diagram_line && [[ ! "$diagram_line" =~ ^@enduml ]]; do | ||
echo "$diagram_line" >> "$temp_file" | ||
done | ||
echo "$diagram_line" >> "$temp_file" # Add the @enduml line | ||
else | ||
# Copy other lines to the temporary file | ||
echo "$line" >> "$temp_file" | ||
fi | ||
done < "$file" | ||
# Move updated file to the original location | ||
mv "$temp_file" "$file" | ||
done | ||
- name: Commit changes | ||
run: | | ||
git config --global user.name "github-actions" | ||
git config --global user.email "[email protected]" | ||
git add . | ||
git commit -m "Add PlantUML diagrams as SVG images in markdown files" | ||
git push | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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
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
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