Skip to content

Commit ba7902e

Browse files
authored
Add files via upload
1 parent fe57632 commit ba7902e

2 files changed

Lines changed: 353 additions & 0 deletions

File tree

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
name: Deploy versioned docs to GitHub Pages
2+
3+
# ============================================================================
4+
# Trigger:
5+
# - Tag-Push im Format v* (z. B. v1.0.0, v2.1.3)
6+
# - Manuell via workflow_dispatch (optional Tag-Eingabe)
7+
# - Push auf main → wird als "dev"-Version publiziert
8+
# ============================================================================
9+
on:
10+
push:
11+
tags:
12+
- "v*"
13+
branches:
14+
- main
15+
workflow_dispatch:
16+
inputs:
17+
version_label:
18+
description: "Version label (z. B. v1.2.3 oder dev). Leer = aus Tag/Branch ableiten."
19+
required: false
20+
21+
concurrency:
22+
group: deploy-versioned-pages
23+
cancel-in-progress: false # Kein Abbruch – ältere Versionen sollen erhalten bleiben
24+
25+
permissions:
26+
contents: write # Für Push auf gh-pages Branch
27+
28+
jobs:
29+
build-and-publish:
30+
runs-on: ubuntu-latest
31+
steps:
32+
# ── 1. Checkout ────────────────────────────────────────────────────────
33+
- uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0
36+
37+
# ── 2. Tools installieren ──────────────────────────────────────────────
38+
- name: Install Asciidoctor & tools
39+
run: |
40+
sudo apt-get update
41+
sudo apt-get install -y asciidoctor jq rsync
42+
43+
# ── 3. Versions-Label bestimmen ────────────────────────────────────────
44+
- name: Determine version label
45+
id: version
46+
run: |
47+
if [ -n "${{ github.event.inputs.version_label }}" ]; then
48+
VERSION="${{ github.event.inputs.version_label }}"
49+
elif [[ "$GITHUB_REF" == refs/tags/v* ]]; then
50+
VERSION="${GITHUB_REF_NAME}"
51+
else
52+
VERSION="dev"
53+
fi
54+
echo "label=${VERSION}" >> "$GITHUB_OUTPUT"
55+
echo "📌 Publishing version: ${VERSION}"
56+
57+
# ── 4. Site bauen (gleiche Logik wie deploy-pages.yml) ─────────────────
58+
- name: Build HTML pages
59+
run: |
60+
mkdir -p _site
61+
62+
# --- Dynamische index.adoc ---
63+
printf '%s\n' \
64+
'= App des Versicherten' \
65+
':toc: left' \
66+
':toclevels: 3' \
67+
':imagesdir: images' \
68+
'' \
69+
'include::docs/app_overview.adoc[leveloffset=+1]' \
70+
'' \
71+
'== Module' \
72+
> _generated_index.adoc
73+
74+
for module_dir in modules/*/; do
75+
module_name="$(basename "$module_dir")"
76+
overview_file="${module_dir}docs/overview.adoc"
77+
if [ -f "$overview_file" ]; then
78+
icon_file="_site/images/module_${module_name}.svg"
79+
mkdir -p _site/images
80+
text_len=${#module_name}
81+
width=$(( text_len * 10 + 24 ))
82+
half=$(( width / 2 ))
83+
printf '<svg xmlns="http://www.w3.org/2000/svg" width="%d" height="28" viewBox="0 0 %d 28">\n' "$width" "$width" > "$icon_file"
84+
printf ' <rect width="%d" height="28" rx="6" fill="#0b6abf"/>\n' "$width" >> "$icon_file"
85+
printf ' <text x="%d" y="18" font-family="Arial, Helvetica, sans-serif" font-size="13" font-weight="bold" fill="#fff" text-anchor="middle">%s</text>\n' "$half" "$module_name" >> "$icon_file"
86+
printf '</svg>\n' >> "$icon_file"
87+
echo "" >> _generated_index.adoc
88+
echo "image:module_${module_name}.svg[link=modules/${module_name}/docs/overview.html,title=${module_name}]" >> _generated_index.adoc
89+
fi
90+
done
91+
92+
asciidoctor -b html5 -o _site/index.html _generated_index.adoc
93+
94+
mkdir -p _site/docs
95+
for f in docs/*.adoc; do
96+
[ -f "$f" ] || continue
97+
asciidoctor -b html5 -a imagesdir=../images \
98+
-o "_site/docs/$(basename "${f%.adoc}.html")" "$f"
99+
done
100+
101+
find modules -name "*.adoc" -path "*/docs/*" | while read f; do
102+
outpath="_site/${f%.adoc}.html"
103+
mkdir -p "$(dirname "$outpath")"
104+
asciidoctor -b html5 -o "$outpath" "$f"
105+
done
106+
107+
if [ -d "images" ]; then
108+
mkdir -p _site/images
109+
cp -r images/* _site/images/ 2>/dev/null || true
110+
fi
111+
112+
find modules -type d -name "images" | while read imgdir; do
113+
mkdir -p "_site/$imgdir"
114+
cp -r "$imgdir"/* "_site/$imgdir"/ 2>/dev/null || true
115+
done
116+
117+
rm -f _generated_index.adoc
118+
119+
# ── 5. Links korrigieren (.adoc → .html) ──────────────────────────────
120+
- name: Fix internal links
121+
run: |
122+
find _site -name "*.html" -exec sed -i \
123+
-e 's/\.adoc"/\.html"/g' \
124+
-e "s/\.adoc'/\.html'/g" \
125+
-e 's/\.adoc#/\.html#/g' \
126+
-e 's/\.adoc<\/a>/\.html<\/a>/g' \
127+
{} +
128+
129+
# ── 6. Docinfo injizieren ──────────────────────────────────────────────
130+
- name: Inject docinfo
131+
run: |
132+
if [ -f docinfo.html ]; then
133+
for htmlfile in $(find _site -name "*.html"); do
134+
awk -v docinfo="docinfo.html" '
135+
/<\/head>/ {
136+
while ((getline line < docinfo) > 0) print line
137+
close(docinfo)
138+
}
139+
{ print }
140+
' "$htmlfile" > "${htmlfile}.tmp" && mv "${htmlfile}.tmp" "$htmlfile"
141+
done
142+
fi
143+
144+
# ── 7. gh-pages Branch auschecken / initialisieren ─────────────────────
145+
- name: Prepare gh-pages branch
146+
run: |
147+
VERSION="${{ steps.version.outputs.label }}"
148+
git config user.name "github-actions[bot]"
149+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
150+
151+
# gh-pages Branch klonen (oder neu anlegen)
152+
rm -rf .gh-pages
153+
if git ls-remote --exit-code --heads origin gh-pages >/dev/null 2>&1; then
154+
git clone --single-branch --branch gh-pages \
155+
"https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" \
156+
.gh-pages
157+
else
158+
mkdir .gh-pages
159+
cd .gh-pages
160+
git init -b gh-pages
161+
git remote add origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
162+
cd ..
163+
fi
164+
165+
# Version in Unterordner kopieren
166+
mkdir -p ".gh-pages/${VERSION}"
167+
rsync -a --delete _site/ ".gh-pages/${VERSION}/"
168+
169+
# ── 8. versions.json aktualisieren ─────────────────────────────────────
170+
- name: Update versions.json and root redirect
171+
run: |
172+
VERSION="${{ steps.version.outputs.label }}"
173+
cd .gh-pages
174+
175+
# versions.json anlegen falls nicht vorhanden
176+
if [ ! -f versions.json ]; then
177+
echo '[]' > versions.json
178+
fi
179+
180+
# Version hinzufügen (Duplikate vermeiden), sortieren
181+
# Release-Tags (v*) kommen zuerst (absteigend), dann "dev" am Ende
182+
jq --arg v "$VERSION" '
183+
[ .[] | select(.id != $v) ] + [{"id": $v}]
184+
| sort_by(
185+
if .id == "dev" then "zzz"
186+
elif (.id | startswith("v")) then .id
187+
else "yyy" + .id
188+
end
189+
)
190+
| reverse
191+
| if (map(select(.id == "dev")) | length) > 0
192+
then (map(select(.id != "dev"))) + (map(select(.id == "dev")))
193+
else .
194+
end
195+
' versions.json > versions.tmp && mv versions.tmp versions.json
196+
197+
echo "📋 versions.json:"
198+
cat versions.json
199+
200+
# Neueste stabile Version ermitteln (erster Eintrag der nicht "dev" ist)
201+
LATEST=$(jq -r '[.[] | select(.id != "dev")][0].id // "dev"' versions.json)
202+
echo "📌 Latest: ${LATEST}"
203+
204+
# Root index.html als Redirect auf die neueste Version
205+
cat > index.html <<REDIRECT_EOF
206+
<!DOCTYPE html>
207+
<html lang="de">
208+
<head>
209+
<meta charset="utf-8">
210+
<meta http-equiv="refresh" content="0; url=./${LATEST}/index.html">
211+
<title>Weiterleitung…</title>
212+
</head>
213+
<body>
214+
<p><a href="./${LATEST}/index.html">Weiter zur aktuellen Version (${LATEST})</a></p>
215+
</body>
216+
</html>
217+
REDIRECT_EOF
218+
219+
# .nojekyll damit GitHub Pages keine Jekyll-Verarbeitung macht
220+
touch .nojekyll
221+
222+
# ── 9. Commit & Push auf gh-pages ──────────────────────────────────────
223+
- name: Commit and push to gh-pages
224+
env:
225+
GIT_AUTHOR_NAME: github-actions[bot]
226+
GIT_AUTHOR_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
227+
GIT_COMMITTER_NAME: github-actions[bot]
228+
GIT_COMMITTER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
229+
run: |
230+
VERSION="${{ steps.version.outputs.label }}"
231+
cd .gh-pages
232+
# Identity im Ziel-Repo explizit setzen, damit git commit immer funktioniert.
233+
git config user.name "github-actions[bot]"
234+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
235+
git add -A
236+
git diff --cached --quiet && echo "Keine Änderungen." && exit 0
237+
git commit -m "docs: publish version ${VERSION}"
238+
git push origin gh-pages
239+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Generate images
2+
3+
# Trigger on pushes that change diagram source files, or manually via workflow_dispatch
4+
on:
5+
push:
6+
branches:
7+
- '**'
8+
paths:
9+
- '**.drawio'
10+
- '**.puml'
11+
workflow_dispatch:
12+
13+
# Prevent concurrent runs on the same branch to avoid commit conflicts
14+
concurrency:
15+
group: generate-images-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
# ---------------------------------------------------------------
20+
# Single job that discovers changed directories and generates
21+
# all images sequentially, then commits everything in one go.
22+
# This avoids commit conflicts that arise when parallel matrix
23+
# jobs each try to push to the same branch.
24+
# ---------------------------------------------------------------
25+
generate:
26+
runs-on: ubuntu-latest
27+
steps:
28+
# Fetch the repo with full history (needed for drawio-export-action
29+
# change detection and for diffing against the previous commit)
30+
- uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
34+
# --- Discover which image_src directories are affected ---
35+
- name: Discover changed image_src directories
36+
id: discover
37+
run: |
38+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
39+
# Manual trigger: find ALL image_src dirs that contain .puml / .drawio files
40+
puml_dirs=$(find . -name "*.puml" -path "*/image_src/*" \
41+
| xargs -I{} dirname {} | sed 's|^\./||' | sort -u)
42+
drawio_dirs=$(find . -name "*.drawio" -path "*/image_src/*" \
43+
| xargs -I{} dirname {} | sed 's|^\./||' | sort -u)
44+
else
45+
# Push trigger: only pick image_src dirs where files actually changed
46+
puml_dirs=$(git diff --name-only HEAD~1 HEAD -- '*.puml' \
47+
| xargs -I{} dirname {} | sort -u | grep 'image_src' || true)
48+
drawio_dirs=$(git diff --name-only HEAD~1 HEAD -- '*.drawio' \
49+
| xargs -I{} dirname {} | sort -u | grep 'image_src' || true)
50+
fi
51+
52+
# Store results as multi-line outputs
53+
{
54+
echo "puml_dirs<<EOF"
55+
echo "$puml_dirs"
56+
echo "EOF"
57+
} >> "$GITHUB_OUTPUT"
58+
{
59+
echo "drawio_dirs<<EOF"
60+
echo "$drawio_dirs"
61+
echo "EOF"
62+
} >> "$GITHUB_OUTPUT"
63+
64+
# --- Generate PlantUML images for each affected directory ---
65+
- name: Generate PlantUML diagrams
66+
if: steps.discover.outputs.puml_dirs != ''
67+
run: |
68+
echo "${{ steps.discover.outputs.puml_dirs }}" | while read srcdir; do
69+
[ -z "$srcdir" ] && continue
70+
71+
# Derive the sibling images/ folder from the image_src/ folder
72+
outdir=$(echo "$srcdir" | sed 's|image_src$|images|')
73+
74+
echo "::group::Processing PlantUML in $srcdir -> $outdir"
75+
76+
# Ensure the target images/ directory exists
77+
mkdir -p "$outdir"
78+
79+
echo "Source files:"
80+
ls -la "$srcdir"/*.puml
81+
82+
echo "::endgroup::"
83+
done
84+
85+
# Run PlantUML via Docker to render all discovered .puml files to PNG.
86+
# -o ../images sets the output path relative to each source file,
87+
# so image_src/*.puml outputs to the sibling images/ folder.
88+
# (A relative path is required because the Docker container mounts
89+
# the workspace at a different path than ${{ github.workspace }}.)
90+
# We process all .puml files across all image_src directories in one call.
91+
- name: Run PlantUML
92+
if: steps.discover.outputs.puml_dirs != ''
93+
uses: holowinski/plantuml-github-action@1.2025.4
94+
with:
95+
args: -v -tpng -o ../images **/image_src/*.puml
96+
97+
# --- Export Draw.io images for each affected directory ---
98+
# The drawio-export-action must be called per directory since
99+
# it accepts a single path input.
100+
- name: Export drawio files to PNG
101+
if: steps.discover.outputs.drawio_dirs != ''
102+
uses: rlespinasse/drawio-export-action@v2
103+
with:
104+
format: png
105+
output: ../images
106+
remove-page-suffix: true
107+
transparent: true
108+
action-mode: all
109+
110+
# --- Commit all generated images in a single commit ---
111+
- name: Commit generated images
112+
uses: stefanzweifel/git-auto-commit-action@v5
113+
with:
114+
commit_message: "docs: generate diagram images"

0 commit comments

Comments
 (0)