fix(ci): auto-detect gitea repo owner for sync
This commit is contained in:
parent
ee6d7edfd0
commit
4cd6eeba63
1 changed files with 27 additions and 1 deletions
28
.github/workflows/sync-to-gitea.yml
vendored
28
.github/workflows/sync-to-gitea.yml
vendored
|
|
@ -20,12 +20,38 @@ jobs:
|
||||||
env:
|
env:
|
||||||
GITEA_USERNAME: Admin
|
GITEA_USERNAME: Admin
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_SECRET }}
|
GITEA_TOKEN: ${{ secrets.GITEA_SECRET }}
|
||||||
|
GITEA_HOST: ci.nxtgauge.com
|
||||||
|
GITEA_OWNER: ${{ vars.GITEA_OWNER }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
echo "Syncing ${{ github.event.repository.name }}:main → Gitea main"
|
echo "Syncing ${{ github.event.repository.name }}:main → Gitea main"
|
||||||
echo "Commit: $(git rev-parse HEAD)"
|
echo "Commit: $(git rev-parse HEAD)"
|
||||||
|
|
||||||
git remote add gitea "https://${GITEA_USERNAME}:${GITEA_TOKEN}@ci.nxtgauge.com/Admin/${{ github.event.repository.name }}.git"
|
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 "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 fetch gitea main || true
|
||||||
git push gitea HEAD:main --force-with-lease=refs/heads/main
|
git push gitea HEAD:main --force-with-lease=refs/heads/main
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue