Update sync.sh
This commit is contained in:
44
lib/sync.sh
44
lib/sync.sh
@@ -131,7 +131,7 @@ ${BOT_TRAILER}: forward/${mono_branch}/$(date -u +%Y-%m-%dT%H:%M:%SZ)" >&2
|
|||||||
# ─── Reverse Sync: Subrepo → Monorepo ──────────────────────────────
|
# ─── Reverse Sync: Subrepo → Monorepo ──────────────────────────────
|
||||||
#
|
#
|
||||||
# Always creates a PR on the monorepo — never pushes directly.
|
# Always creates a PR on the monorepo — never pushes directly.
|
||||||
# Returns: skip | pr-created
|
# Returns: skip | pr-created | josh-rejected
|
||||||
|
|
||||||
reverse_sync() {
|
reverse_sync() {
|
||||||
local mono_branch="$SYNC_BRANCH_MONO"
|
local mono_branch="$SYNC_BRANCH_MONO"
|
||||||
@@ -170,45 +170,15 @@ reverse_sync() {
|
|||||||
log "INFO" "New human commits to sync:"
|
log "INFO" "New human commits to sync:"
|
||||||
echo "$human_commits" >&2
|
echo "$human_commits" >&2
|
||||||
|
|
||||||
# 4. Clone monorepo directly (not through josh — we need a real branch from main)
|
# 4. Push through josh to a staging branch
|
||||||
local mono_auth_url api_host_path subfolder
|
|
||||||
api_host_path=$(echo "$MONOREPO_API" | sed 's|https://||; s|/api/v1/repos/|/|')
|
|
||||||
mono_auth_url="https://${BOT_USER}:${GITEA_TOKEN}@${api_host_path}.git"
|
|
||||||
subfolder=$(echo "$JOSH_SYNC_TARGETS" | jq -r --arg n "$JOSH_SYNC_TARGET_NAME" \
|
|
||||||
'.[] | select(.name == $n) | .subfolder')
|
|
||||||
|
|
||||||
git clone "$mono_auth_url" \
|
|
||||||
--branch "$mono_branch" --single-branch \
|
|
||||||
"${work_dir}/monorepo" || die "Failed to clone monorepo"
|
|
||||||
|
|
||||||
cd "${work_dir}/monorepo" || exit
|
|
||||||
git config user.name "$BOT_NAME"
|
|
||||||
git config user.email "$BOT_EMAIL"
|
|
||||||
|
|
||||||
local ts
|
local ts
|
||||||
ts=$(date +%Y%m%d-%H%M%S)
|
ts=$(date +%Y%m%d-%H%M%S)
|
||||||
local staging_branch="auto-sync/subrepo-${subrepo_branch}-${ts}"
|
local staging_branch="auto-sync/subrepo-${subrepo_branch}-${ts}"
|
||||||
git checkout -B "$staging_branch" >&2
|
|
||||||
|
|
||||||
# 5. Rsync subrepo content into subfolder (--delete handles removals)
|
if git push -o "base=${mono_branch}" "$(josh_auth_url)" "HEAD:refs/heads/${staging_branch}"; then
|
||||||
mkdir -p "$subfolder"
|
log "INFO" "Pushed to staging branch via josh: ${staging_branch}"
|
||||||
rsync -a --delete --exclude='.git' "${work_dir}/subrepo/" "${subfolder}/"
|
|
||||||
git add "$subfolder"
|
|
||||||
|
|
||||||
if git diff --cached --quiet; then
|
|
||||||
log "INFO" "No tree changes after rsync — skip"
|
|
||||||
echo "skip"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
git commit -m "Sync from subrepo/${subrepo_branch} $(date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
||||||
|
|
||||||
${BOT_TRAILER}: reverse/${subrepo_branch}/$(date -u +%Y-%m-%dT%H:%M:%SZ)" >&2
|
|
||||||
|
|
||||||
# 6. Push branch and create PR on monorepo (NEVER direct push to main)
|
|
||||||
git push origin "$staging_branch" || die "Failed to push staging branch"
|
|
||||||
log "INFO" "Pushed staging branch: ${staging_branch}"
|
|
||||||
|
|
||||||
|
# 5. Create PR on monorepo (NEVER direct push)
|
||||||
local pr_body
|
local pr_body
|
||||||
pr_body="## Subrepo changes\n\nNew commits from subrepo \`${subrepo_branch}\`:\n\n\`\`\`\n${human_commits}\n\`\`\`\n\n**Review checklist:**\n- [ ] Changes scoped to synced subfolder\n- [ ] No leaked credentials or environment-specific config\n- [ ] CI passes"
|
pr_body="## Subrepo changes\n\nNew commits from subrepo \`${subrepo_branch}\`:\n\n\`\`\`\n${human_commits}\n\`\`\`\n\n**Review checklist:**\n- [ ] Changes scoped to synced subfolder\n- [ ] No leaked credentials or environment-specific config\n- [ ] CI passes"
|
||||||
|
|
||||||
@@ -220,6 +190,10 @@ ${BOT_TRAILER}: reverse/${subrepo_branch}/$(date -u +%Y-%m-%dT%H:%M:%SZ)" >&2
|
|||||||
|
|
||||||
log "INFO" "Reverse sync PR created on monorepo"
|
log "INFO" "Reverse sync PR created on monorepo"
|
||||||
echo "pr-created"
|
echo "pr-created"
|
||||||
|
else
|
||||||
|
log "ERROR" "Josh rejected push — check josh-proxy logs"
|
||||||
|
echo "josh-rejected"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# ─── Initial Import: Subrepo → Monorepo (first time) ───────────────
|
# ─── Initial Import: Subrepo → Monorepo (first time) ───────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user