mirror of
https://github.com/Jeuners/logbuch.git
synced 2026-09-09 15:02:32 +02:00
Struktur, erster Artikel, Publish-Workflow
This commit is contained in:
commit
fe9cc8f492
5 changed files with 312 additions and 0 deletions
90
.github/workflows/publish.yml
vendored
Normal file
90
.github/workflows/publish.yml
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
name: publish
|
||||
|
||||
# Jeder neue Artikel unter artikel/ wird zu:
|
||||
# - einem Release (taggt den Artikel, erzeugt automatisch einen Atom-Feed-Eintrag)
|
||||
# - einer Discussion in der Kategorie Announcements (der Kommentarthread)
|
||||
#
|
||||
# Veroeffentlichen ist damit: git push.
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- 'artikel/**'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
discussions: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Neue Artikel veroeffentlichen
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
BEFORE: ${{ github.event.before }}
|
||||
AFTER: ${{ github.sha }}
|
||||
CATEGORY: ${{ vars.DISCUSSION_CATEGORY || 'Announcements' }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
# Erster Push oder Force-Push: BEFORE ist unbrauchbar, dann alles nehmen.
|
||||
if git cat-file -e "${BEFORE}^{commit}" 2>/dev/null; then
|
||||
FILES="$(git diff --name-only --diff-filter=A "${BEFORE}" "${AFTER}" -- artikel | grep '\.md$' || true)"
|
||||
else
|
||||
FILES="$(git ls-files -- artikel | grep '\.md$' || true)"
|
||||
fi
|
||||
|
||||
if [ -z "${FILES}" ]; then
|
||||
echo "Keine neuen Artikel in diesem Push."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Gefunden:"
|
||||
echo "${FILES}"
|
||||
|
||||
while IFS= read -r file; do
|
||||
[ -n "$file" ] || continue
|
||||
[ -f "$file" ] || continue
|
||||
|
||||
slug="$(basename "$file" .md)"
|
||||
|
||||
# Vorlagen und Entwuerfe (fuehrender Unterstrich) werden nicht veroeffentlicht.
|
||||
case "$slug" in
|
||||
_*) echo "Vorlage/Entwurf ${file}, uebersprungen."; continue ;;
|
||||
esac
|
||||
|
||||
tag="artikel/${slug}"
|
||||
|
||||
if gh release view "$tag" >/dev/null 2>&1; then
|
||||
echo "Release ${tag} existiert bereits, uebersprungen."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Titel aus dem Frontmatter, sonst aus der ersten H1, sonst der Slug.
|
||||
title="$(sed -n 's/^title:[[:space:]]*//p' "$file" | head -n1 | sed 's/^"//; s/"$//')"
|
||||
if [ -z "$title" ]; then
|
||||
title="$(sed -n 's/^# //p' "$file" | head -n1)"
|
||||
fi
|
||||
[ -n "$title" ] || title="$slug"
|
||||
|
||||
# Frontmatter aus den Release-Notes entfernen.
|
||||
body="$(mktemp)"
|
||||
awk '
|
||||
NR==1 && $0=="---" { fm=1; next }
|
||||
fm==1 && $0=="---" { fm=0; next }
|
||||
fm!=1 { print }
|
||||
' "$file" > "$body"
|
||||
|
||||
echo "Veroeffentliche: ${title} -> ${tag}"
|
||||
gh release create "$tag" \
|
||||
--title "$title" \
|
||||
--notes-file "$body" \
|
||||
--discussion-category "$CATEGORY"
|
||||
|
||||
done <<< "${FILES}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue