nxtgauge-ai-assistant/.github/workflows/sync-to-gitea.yml
Workflow config file is invalid. Please check your config file: yaml: line 53: could not find expected ':'
2026-04-30 19:59:50 +02:00

91 lines
2.6 KiB
YAML

name: sync-to-gitea
on:
push:
branches:
- main
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Push to Gitea main
env:
GITEA_USERNAME: Admin
GITEA_TOKEN: ${{ secrets.GITEA_SECRET }}
GITEA_HOST: ci.nxtgauge.com
GITEA_OWNER: ${{ vars.GITEA_OWNER }}
run: |
set -euo pipefail
echo "Syncing ${{ github.event.repository.name }}:main → Gitea main"
echo "Commit: $(git rev-parse HEAD)"
if [ -z "${GITEA_TOKEN:-}" ]; then
echo "Missing GITEA_SECRET"
exit 1
fi
REPO_NAME="${{ github.event.repository.name }}"
CANDIDATE_OWNERS="${GITEA_OWNER:-} Admin ${{ github.repository_owner }}"
TARGET_URL=""
for owner in $CANDIDATE_OWNERS; do
[ -n "$owner" ] || continue
candidate_url="https://${GITEA_USERNAME}:${GITEA_TOKEN}@${GITEA_HOST}/${owner}/${REPO_NAME}.git"
if git ls-remote "$candidate_url" >/dev/null 2>&1; then
TARGET_URL="$candidate_url"
echo "Using Gitea target owner: $owner"
break
fi
done
if [ -z "$TARGET_URL" ]; then
echo "Owner guess failed; searching accessible repos via Gitea API"
API_URL="https://${GITEA_HOST}/api/v1/repos/search?q=${REPO_NAME}&limit=100"
TARGET_URL="$(python3 - <<'PY'
import json
import os
import urllib.request
req = urllib.request.Request(
os.environ["API_URL"],
headers={"Authorization": f"token {os.environ['GITEA_TOKEN']}"},
)
with urllib.request.urlopen(req, timeout=20) as resp:
payload = json.loads(resp.read().decode("utf-8"))
repo_name = os.environ["REPO_NAME"].lower()
username = os.environ["GITEA_USERNAME"]
host = os.environ["GITEA_HOST"]
token = os.environ["GITEA_TOKEN"]
for repo in payload.get("data", []):
full_name = str(repo.get("full_name", ""))
if full_name.lower().endswith("/" + repo_name):
print(f"https://{username}:{token}@{host}/{full_name}.git")
break
PY
)"
if [ -n "$TARGET_URL" ]; then
echo "Resolved Gitea target via API"
fi
fi
if [ -z "$TARGET_URL" ]; then
echo "Could not access target repo on Gitea for owners: $CANDIDATE_OWNERS"
exit 1
fi
git remote add gitea "$TARGET_URL"
git fetch gitea main || true
git push gitea HEAD:main --force-with-lease=refs/heads/main
echo "Sync complete!"