7f1bf2f995
- render.py: frontmatter validation, h1 strip, pandoc conversion, banner/category injection, idempotent MediaWiki writes via mwclient - requirements.txt: python-frontmatter, mwclient, PyYAML - template_auto_generated.wikitext: paste into wiki as Template:Auto-generated - .gitea/workflows/publish-songs.yml: reusable workflow; job container python:3.12-slim installs pandoc via apt (no host-level pandoc needed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
98 lines
3.3 KiB
YAML
98 lines
3.3 KiB
YAML
on:
|
|
workflow_call:
|
|
inputs:
|
|
SOURCE_REF:
|
|
description: "Commit SHA that was pushed to ncmr-songs"
|
|
required: true
|
|
type: string
|
|
SOURCE_BASE_REF:
|
|
description: "Commit SHA before the push (all-zeros = first push)"
|
|
required: true
|
|
type: string
|
|
FULL_PUBLISH:
|
|
description: "Re-publish every file regardless of diff"
|
|
required: false
|
|
type: boolean
|
|
default: false
|
|
|
|
jobs:
|
|
publish:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: python:3.12-slim
|
|
|
|
steps:
|
|
- name: Install system deps
|
|
run: |
|
|
apt-get update -qq
|
|
apt-get install -y --no-install-recommends git pandoc ca-certificates
|
|
|
|
- name: Checkout ncmr-songs
|
|
env:
|
|
FAPAT: ${{ secrets.FAPAT }}
|
|
run: |
|
|
SERVER="${{ github.server_url }}"
|
|
PROTO="${SERVER%%://*}"
|
|
HOST="${SERVER#*://}"
|
|
AUTHED="${PROTO}://mikkeli:${FAPAT}@${HOST}"
|
|
git clone "${AUTHED}/mikkeli/ncmr-songs" ncmr-songs
|
|
git -C ncmr-songs checkout ${{ inputs.SOURCE_REF }}
|
|
|
|
- name: Checkout auto-wiki
|
|
env:
|
|
FAPAT: ${{ secrets.FAPAT }}
|
|
run: |
|
|
SERVER="${{ github.server_url }}"
|
|
PROTO="${SERVER%%://*}"
|
|
HOST="${SERVER#*://}"
|
|
AUTHED="${PROTO}://mikkeli:${FAPAT}@${HOST}"
|
|
git clone "${AUTHED}/mikkeli/novoyuuparosk-auto-wiki" auto-wiki
|
|
|
|
- name: Install Python deps
|
|
run: pip install --no-cache-dir -r auto-wiki/pipelines/songs/requirements.txt
|
|
|
|
- name: Detect changed files
|
|
id: diff
|
|
run: |
|
|
BASE="${{ inputs.SOURCE_BASE_REF }}"
|
|
HEAD="${{ inputs.SOURCE_REF }}"
|
|
# All-zeros base means first push — publish everything
|
|
if [ -z "$BASE" ] || echo "$BASE" | grep -qE '^0+$'; then
|
|
echo "mode=all" >> "$GITHUB_OUTPUT"
|
|
else
|
|
git -C ncmr-songs diff --name-only "$BASE" "$HEAD" -- '*.md' \
|
|
| grep -v '^wip/' \
|
|
| grep -v '^README\.md' \
|
|
> /tmp/changed.txt 2>/dev/null || true
|
|
echo "Changed files:"
|
|
cat /tmp/changed.txt
|
|
echo "mode=incremental" >> "$GITHUB_OUTPUT"
|
|
echo "files=$(tr '\n' ' ' < /tmp/changed.txt)" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Publish
|
|
env:
|
|
WIKI_API_URL: ${{ vars.WIKI_API_URL }}
|
|
WIKI_BASE_URL: ${{ vars.WIKI_BASE_URL }}
|
|
WIKI_BOT_USER: ${{ secrets.WIKI_BOT_USER }}
|
|
WIKI_BOT_PASSWORD: ${{ secrets.WIKI_BOT_PASSWORD }}
|
|
SOURCE_REF: ${{ inputs.SOURCE_REF }}
|
|
GITEA_REPO_URL: ${{ github.server_url }}/mikkeli/ncmr-songs
|
|
run: |
|
|
MODE="${{ steps.diff.outputs.mode }}"
|
|
if [ "$MODE" = "all" ] || [ "${{ inputs.FULL_PUBLISH }}" = "true" ]; then
|
|
python auto-wiki/pipelines/songs/render.py \
|
|
--source-dir ncmr-songs \
|
|
--all
|
|
else
|
|
FILES="${{ steps.diff.outputs.files }}"
|
|
if [ -z "$FILES" ]; then
|
|
echo "No changed .md files detected. Nothing to publish."
|
|
exit 0
|
|
fi
|
|
# shellcheck disable=SC2086
|
|
python auto-wiki/pipelines/songs/render.py \
|
|
--source-dir ncmr-songs \
|
|
--files $FILES
|
|
fi
|