Fix Forgejo CI mirror auth that produced Bad hostname URLs.

Use Basic auth headers and treat an empty FORGEJO_USER secret as oauth2 so pushes no longer build https://@host.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
pepaskopec-blip 2026-09-23 10:43:37 +02:00
commit 1f7748fc10

View file

@ -281,9 +281,16 @@ jobs:
echo "No FORGEJO_TOKEN; skipping Forgejo builds publish." echo "No FORGEJO_TOKEN; skipping Forgejo builds publish."
exit 0 exit 0
fi fi
user="${FORGEJO_USER:-oauth2}" # Trim and fall back: an empty FORGEJO_USER secret is still "set", so
git push -f \ # ${VAR:-oauth2} would keep "" and produce https://:token@host which
"https://${user}:${FORGEJO_TOKEN}@git.dvorakmortonxd.dev/edu/maturita.c.git" \ # libcurl rejects as "Bad hostname". Prefer Basic auth over URL userinfo
# so tokens with @/: never break the URL either.
token="$(printf '%s' "$FORGEJO_TOKEN" | tr -d '\r\n')"
user="$(printf '%s' "${FORGEJO_USER:-}" | tr -d '\r\n')"
user="${user:-oauth2}"
basic="$(printf '%s:%s' "$user" "$token" | base64 -w0)"
git -c "http.extraHeader=Authorization: Basic ${basic}" push -f \
"https://git.dvorakmortonxd.dev/skopcaak/maturita.c.git" \
HEAD:refs/heads/builds HEAD:refs/heads/builds
forgejo-main: forgejo-main:
@ -299,11 +306,14 @@ jobs:
FORGEJO_USER: ${{ secrets.FORGEJO_USER }} FORGEJO_USER: ${{ secrets.FORGEJO_USER }}
run: | run: |
set -euo pipefail set -euo pipefail
if [ -z "${FORGEJO_TOKEN:-}" ]; then token="$(printf '%s' "${FORGEJO_TOKEN:-}" | tr -d '\r\n')"
if [ -z "$token" ]; then
echo "No FORGEJO_TOKEN; skipping Forgejo main mirror." echo "No FORGEJO_TOKEN; skipping Forgejo main mirror."
exit 0 exit 0
fi fi
user="${FORGEJO_USER:-oauth2}" user="$(printf '%s' "${FORGEJO_USER:-}" | tr -d '\r\n')"
git push \ user="${user:-oauth2}"
"https://${user}:${FORGEJO_TOKEN}@git.dvorakmortonxd.dev/edu/maturita.c.git" \ basic="$(printf '%s:%s' "$user" "$token" | base64 -w0)"
git -c "http.extraHeader=Authorization: Basic ${basic}" push \
"https://git.dvorakmortonxd.dev/skopcaak/maturita.c.git" \
HEAD:refs/heads/main HEAD:refs/heads/main