#!/usr/bin/env bash # Publishes docs/wiki/ to the Gitea wiki (Khaemhat.wiki.git), the same job as .gitea/workflows/wiki.yml. # The wiki becomes an exact copy of docs/wiki/: pages removed here are removed there. # # Environment: GITEA_URL (https://gitea.encke-hake.ts.net), GITEA_OWNER (BalboSoft); GITEA_TOKEN is optional (without # it git uses the credentials already configured on this machine). WIKI_REMOTE overrides the whole URL. set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$root" gitea_url="${GITEA_URL:-https://gitea.encke-hake.ts.net}" remote="${WIKI_REMOTE:-${gitea_url%/}/${GITEA_OWNER:-BalboSoft}/Khaemhat.wiki.git}" sha="$(git rev-parse --short HEAD)" auth=() if [[ -n "${GITEA_TOKEN:-}" ]]; then auth=(-c "http.extraheader=Authorization: basic $(printf 'x-access-token:%s' "$GITEA_TOKEN" | base64 -w0)") fi work="$(mktemp -d)" trap 'rm -rf "$work"' EXIT git "${auth[@]}" clone -q --depth 1 "$remote" "$work/wiki" find "$work/wiki" -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} + cp -R docs/wiki/. "$work/wiki/" cd "$work/wiki" git add -A if git diff --cached --quiet; then echo "Wiki giĆ  allineata a docs/wiki ($sha)." exit 0 fi git -c user.name="${GIT_AUTHOR_NAME:-Khaemhat wiki}" -c user.email="${GIT_AUTHOR_EMAIL:-wiki@khaemhat.invalid}" \ commit -q -m "docs(wiki): sync from $sha" git "${auth[@]}" push -q origin HEAD echo "Wiki pubblicata da docs/wiki ($sha): $(git diff --stat HEAD~1 | tail -n 1)"