mirror of
git://f0xx.org/android_cast
synced 2026-07-29 04:18:09 +03:00
gitea sync
This commit is contained in:
@@ -365,6 +365,53 @@ Rejects on `master` / `next`: branch delete, non-fast-forward (force-push). Othe
|
|||||||
|
|
||||||
`gitea_polish_project.sh` runs branch protection automatically unless `GITEA_SKIP_BRANCH_PROTECT=1`.
|
`gitea_polish_project.sh` runs branch protection automatically unless `GITEA_SKIP_BRANCH_PROTECT=1`.
|
||||||
|
|
||||||
|
Apply the same Gitea rules to other AndroidCast repos:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
GITEA_REPO=url-shortener GITEA_PROTECT_BRANCHES="next master" \
|
||||||
|
sudo ./examples/crash_reporter/backend/scripts/gitea/gitea_protect_branches.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
(Branches that do not exist yet are skipped when using `gitea_attach_url_shortener.sh`.)
|
||||||
|
|
||||||
|
## url-shortener (first-party submodule mirror)
|
||||||
|
|
||||||
|
The url-shortener service lives in its **own** canonical repo
|
||||||
|
`git://f0xx.org/androidcast_project/url-shortener` (submodule `backend/url-shortener`).
|
||||||
|
It is **not** mirrored by `gitea_mirror_submodules.sh` (local `f0xx.org` URLs are skipped).
|
||||||
|
|
||||||
|
**One command on BE** (org + pull mirror + default `next` + protect `master`/`next` when present):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./examples/crash_reporter/backend/scripts/gitea/gitea_attach_url_shortener.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
This reuses `gitea_attach_remote.sh`, `gitea_set_default_branch.sh`, and `gitea_protect_branches.sh` — no duplicate mirror logic.
|
||||||
|
|
||||||
|
| Step | What |
|
||||||
|
|------|------|
|
||||||
|
| Org | Ensures **AndroidCast** + **Owners** (`admin`, `foxx`) |
|
||||||
|
| Transfer | `admin/url-shortener` or `androidcast_project/url-shortener` → `AndroidCast/url-shortener` if present |
|
||||||
|
| Mirror | Pull from `git://f0xx.org/androidcast_project/url-shortener` (`GITEA_PRIVATE=false` — team-visible under public org) |
|
||||||
|
| Default branch | `next` |
|
||||||
|
| Protection | `next` and `master` only (skips branches not on canonical remote yet) |
|
||||||
|
|
||||||
|
Clone URL:
|
||||||
|
|
||||||
|
`https://apps.f0xx.org/app/androidcast_project/git/AndroidCast/url-shortener.git`
|
||||||
|
|
||||||
|
**FE canonical hook** (primary enforcement for `git push` to `git://f0xx.org/...`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp examples/git/hooks/pre-receive.android_cast.example \
|
||||||
|
/path/to/url-shortener.git/hooks/pre-receive
|
||||||
|
chmod +x /path/to/url-shortener.git/hooks/pre-receive
|
||||||
|
```
|
||||||
|
|
||||||
|
Ensure `app.ini` `[migrations]` allows **`f0xx.org`** (in addition to `10.7.0.10` for the main repo).
|
||||||
|
|
||||||
|
`gitea_polish_project.sh` calls `gitea_attach_url_shortener.sh` automatically when the mirror is missing.
|
||||||
|
|
||||||
## Polish (finish line — safe BE run)
|
## Polish (finish line — safe BE run)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
121
examples/crash_reporter/backend/scripts/gitea/gitea_attach_url_shortener.sh
Executable file
121
examples/crash_reporter/backend/scripts/gitea/gitea_attach_url_shortener.sh
Executable file
@@ -0,0 +1,121 @@
|
|||||||
|
#!/bin/ash
|
||||||
|
#
|
||||||
|
# Import url-shortener into the AndroidCast Gitea org (pull mirror, team-visible, protected branches).
|
||||||
|
# Thin orchestrator — reuses gitea_attach_remote.sh, gitea_set_default_branch.sh,
|
||||||
|
# gitea_protect_branches.sh (same rules as android_cast).
|
||||||
|
#
|
||||||
|
# Canonical remote: git://f0xx.org/androidcast_project/url-shortener
|
||||||
|
# Gitea UI: …/git/AndroidCast/url-shortener
|
||||||
|
#
|
||||||
|
# Usage (Alpine BE as root):
|
||||||
|
# sudo ./gitea_attach_url_shortener.sh
|
||||||
|
#
|
||||||
|
# Override:
|
||||||
|
# GITEA_MIRROR_URL=git://f0xx.org/androidcast_project/url-shortener sudo ./gitea_attach_url_shortener.sh
|
||||||
|
#
|
||||||
|
# Prerequisites: app.ini [migrations] must allow f0xx.org (see scripts/gitea/README.md).
|
||||||
|
#
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
# shellcheck source=gitea_ini.sh
|
||||||
|
. "$SCRIPT_DIR/gitea_ini.sh"
|
||||||
|
# shellcheck source=gitea_mirror_lib.sh
|
||||||
|
. "$SCRIPT_DIR/gitea_mirror_lib.sh"
|
||||||
|
# shellcheck source=gitea_org_lib.sh
|
||||||
|
. "$SCRIPT_DIR/gitea_org_lib.sh"
|
||||||
|
|
||||||
|
GITEA_ORG="${GITEA_ORG:-AndroidCast}"
|
||||||
|
GITEA_OWNER="${GITEA_OWNER:-$GITEA_ORG}"
|
||||||
|
GITEA_REPO="${GITEA_REPO:-url-shortener}"
|
||||||
|
GITEA_MIRROR_URL="${GITEA_MIRROR_URL:-git://f0xx.org/androidcast_project/url-shortener}"
|
||||||
|
GITEA_DEFAULT_BRANCH="${GITEA_DEFAULT_BRANCH:-next}"
|
||||||
|
GITEA_MIRROR_INTERVAL="${GITEA_MIRROR_INTERVAL:-10m}"
|
||||||
|
GITEA_PRIVATE="${GITEA_PRIVATE:-false}"
|
||||||
|
# Personal or legacy owners to re-home under AndroidCast (space-separated).
|
||||||
|
GITEA_TRANSFER_SOURCES="${GITEA_TRANSFER_SOURCES:-admin androidcast_project}"
|
||||||
|
|
||||||
|
log() { printf '[gitea-url-shortener] %s\n' "$*"; }
|
||||||
|
warn() { printf '[gitea-url-shortener] WARN: %s\n' "$*" >&2; }
|
||||||
|
|
||||||
|
case "${1:-}" in
|
||||||
|
-h|--help|help)
|
||||||
|
sed -n '2,18p' "$0"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
gitea_load_config || exit 1
|
||||||
|
gitea_ensure_cli_access || exit 1
|
||||||
|
|
||||||
|
log "=== $GITEA_REPO → $GITEA_OWNER/$GITEA_REPO ==="
|
||||||
|
log "mirror: $GITEA_MIRROR_URL"
|
||||||
|
log "public: ${GITEA_ROOT_URL%/}/$GITEA_OWNER/$GITEA_REPO"
|
||||||
|
|
||||||
|
# 1) Org + Owners team (admin, foxx) — repos under the org are team-visible.
|
||||||
|
gitea_org_ensure_androidcast "$GITEA_ORG" || warn "org setup incomplete"
|
||||||
|
|
||||||
|
# 2) Transfer if mirror was created under a personal/legacy account.
|
||||||
|
for _from in $GITEA_TRANSFER_SOURCES; do
|
||||||
|
[ "$_from" = "$GITEA_OWNER" ] && continue
|
||||||
|
if gitea_repo_exists_api "$_from" "$GITEA_REPO"; then
|
||||||
|
log "transfer $_from/$GITEA_REPO → $GITEA_OWNER/$GITEA_REPO"
|
||||||
|
gitea_transfer_repo_api "$_from" "$GITEA_REPO" "$GITEA_OWNER" \
|
||||||
|
&& log " transferred" \
|
||||||
|
|| warn " transfer failed"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# 3) Pull mirror (attach when missing).
|
||||||
|
if gitea_repo_exists_api "$GITEA_OWNER" "$GITEA_REPO"; then
|
||||||
|
log "repo exists — trigger mirror sync"
|
||||||
|
gitea_sync_mirror_api "$GITEA_OWNER" "$GITEA_REPO" || warn "mirror sync API failed — try gitea_sync_mirror.sh"
|
||||||
|
else
|
||||||
|
log "attach pull mirror via gitea_attach_remote.sh ..."
|
||||||
|
GITEA_OWNER="$GITEA_OWNER" GITEA_REPO="$GITEA_REPO" \
|
||||||
|
GITEA_MIRROR_URL="$GITEA_MIRROR_URL" \
|
||||||
|
GITEA_MIRROR_INTERVAL="$GITEA_MIRROR_INTERVAL" \
|
||||||
|
GITEA_PRIVATE="$GITEA_PRIVATE" \
|
||||||
|
sh "$SCRIPT_DIR/gitea_attach_remote.sh" "$GITEA_MIRROR_URL" || exit 1
|
||||||
|
gitea_sync_mirror_api "$GITEA_OWNER" "$GITEA_REPO" || warn "initial sync pending — check [migrations] / git daemon"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 4) Default branch next (integration; master when release branch exists).
|
||||||
|
GITEA_OWNER="$GITEA_OWNER" GITEA_REPO_NAMES="$GITEA_REPO" \
|
||||||
|
GITEA_DEFAULT_BRANCH="$GITEA_DEFAULT_BRANCH" \
|
||||||
|
sh "$SCRIPT_DIR/gitea_set_default_branch.sh" || warn "default branch set failed (sync mirror first)"
|
||||||
|
|
||||||
|
# 5) Branch protection — master + next when present on canonical remote (GIT_FLOW §7).
|
||||||
|
_branches=""
|
||||||
|
for _b in next master; do
|
||||||
|
if gitea_git_remote_has_branch "$GITEA_MIRROR_URL" "$_b"; then
|
||||||
|
_branches="$_branches $_b"
|
||||||
|
else
|
||||||
|
log "skip Gitea protection for $_b (not on $GITEA_MIRROR_URL yet)"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
_branches="$(echo "$_branches" | sed 's/^ //')"
|
||||||
|
if [ -n "$_branches" ]; then
|
||||||
|
GITEA_OWNER="$GITEA_OWNER" GITEA_REPO="$GITEA_REPO" \
|
||||||
|
GITEA_PROTECT_BRANCHES="$_branches" \
|
||||||
|
sh "$SCRIPT_DIR/gitea_protect_branches.sh" || warn "branch protection failed — run manually"
|
||||||
|
else
|
||||||
|
warn "no branches to protect — mirror may be empty"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
|
||||||
|
url-shortener on Gitea:
|
||||||
|
• ${GITEA_ROOT_URL%/}/$GITEA_OWNER/$GITEA_REPO
|
||||||
|
• Org repo (private=$GITEA_PRIVATE) — visible to AndroidCast org members; Owners: $GITEA_ORG_OWNERS
|
||||||
|
• Default branch: $GITEA_DEFAULT_BRANCH
|
||||||
|
• Gitea protected branches:${_branches:+ }${_branches:- (none yet)}
|
||||||
|
|
||||||
|
Canonical FE git (optional pre-receive hook — same as android_cast):
|
||||||
|
cp examples/git/hooks/pre-receive.android_cast.example \\
|
||||||
|
/path/to/url-shortener.git/hooks/pre-receive
|
||||||
|
chmod +x /path/to/url-shortener.git/hooks/pre-receive
|
||||||
|
|
||||||
|
Re-sync: sudo ./gitea_sync_mirror.sh url-shortener
|
||||||
|
|
||||||
|
EOF
|
||||||
@@ -290,6 +290,14 @@ gitea_mirror_set_interval_api() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# True if branch exists on any git remote URL (canonical FE git, upstream, etc.).
|
||||||
|
gitea_git_remote_has_branch() {
|
||||||
|
_url="$1"
|
||||||
|
_branch="$2"
|
||||||
|
command -v git >/dev/null 2>&1 || return 1
|
||||||
|
git ls-remote "$_url" "refs/heads/$_branch" 2>/dev/null | grep -q .
|
||||||
|
}
|
||||||
|
|
||||||
# True if commit SHA is reachable on the mirror (after sync).
|
# True if commit SHA is reachable on the mirror (after sync).
|
||||||
gitea_mirror_has_commit() {
|
gitea_mirror_has_commit() {
|
||||||
_owner="$1"
|
_owner="$1"
|
||||||
|
|||||||
@@ -101,6 +101,16 @@ sync_all_mirrors() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ensure_url_shortener_mirror() {
|
||||||
|
gitea_repo_exists_api "$GITEA_ORG" url-shortener && {
|
||||||
|
log "url-shortener mirror present under $GITEA_ORG"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
log "url-shortener missing — running gitea_attach_url_shortener.sh ..."
|
||||||
|
sh "$SCRIPT_DIR/gitea_attach_url_shortener.sh" \
|
||||||
|
|| warn "url-shortener attach failed — run: sudo ./gitea_attach_url_shortener.sh"
|
||||||
|
}
|
||||||
|
|
||||||
mirror_submodules_if_missing() {
|
mirror_submodules_if_missing() {
|
||||||
_checkout="${1:-}"
|
_checkout="${1:-}"
|
||||||
_repo_dir=""
|
_repo_dir=""
|
||||||
@@ -194,6 +204,9 @@ sync_all_mirrors
|
|||||||
# 5) Submodules
|
# 5) Submodules
|
||||||
mirror_submodules_if_missing "$_checkout"
|
mirror_submodules_if_missing "$_checkout"
|
||||||
|
|
||||||
|
# 5b) First-party submodule url-shortener (local git:// — not gitea_mirror_submodules)
|
||||||
|
ensure_url_shortener_mirror
|
||||||
|
|
||||||
# 6) Default branch
|
# 6) Default branch
|
||||||
if command -v "$SCRIPT_DIR/gitea_set_default_branch.sh" >/dev/null 2>&1; then
|
if command -v "$SCRIPT_DIR/gitea_set_default_branch.sh" >/dev/null 2>&1; then
|
||||||
GITEA_OWNER="$GITEA_ORG" GITEA_DEFAULT_BRANCH="$GITEA_DEFAULT_BRANCH" \
|
GITEA_OWNER="$GITEA_ORG" GITEA_DEFAULT_BRANCH="$GITEA_DEFAULT_BRANCH" \
|
||||||
@@ -211,7 +224,7 @@ cat <<EOF
|
|||||||
|
|
||||||
UI checklist:
|
UI checklist:
|
||||||
• foxx/admin: open ${GITEA_ROOT_URL%/}/$GITEA_ORG (org page — not only "Your repositories")
|
• foxx/admin: open ${GITEA_ROOT_URL%/}/$GITEA_ORG (org page — not only "Your repositories")
|
||||||
• Expect: android_cast, libvpx, opus, speex under $GITEA_ORG
|
• Expect: android_cast, url-shortener, libvpx, opus, speex under $GITEA_ORG
|
||||||
• If android_cast still stale: sudo ./gitea_diagnose_mirror_sync.sh
|
• If android_cast still stale: sudo ./gitea_diagnose_mirror_sync.sh
|
||||||
• Branch protection: master/next on Gitea; install FE hook:
|
• Branch protection: master/next on Gitea; install FE hook:
|
||||||
examples/git/hooks/pre-receive.android_cast.example
|
examples/git/hooks/pre-receive.android_cast.example
|
||||||
|
|||||||
Reference in New Issue
Block a user