|
| 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 | +
|
0 commit comments