- sync-gov-portals-ct-7804-from-git.sh: default to pull --rebase after fetch; require clean monorepo/submodules; add --reset-hard for old mirror-to-origin behavior - gov-portals-git-pull-rebase.sh: operator script to integrate Gitea main + submodule pins; optional --submodules-latest to advance portal repos before pointer commit - Document Devin/multi-actor workflow in GOV_PORTALS_XOM_DEV_DEPLOYMENT.md; AGENTS pointer Co-authored-by: Cursor <cursoragent@cursor.com>
98 lines
3.4 KiB
Bash
98 lines
3.4 KiB
Bash
#!/usr/bin/env bash
|
|
# Rebase the Gov Portals monorepo (and submodule checkouts) onto Gitea before local
|
|
# commits or before sync-gov-portals-ct-7804-from-git.sh. Use when agents (e.g. Devin)
|
|
# push to Gitea and your clone is behind.
|
|
#
|
|
# From proxmox repo root:
|
|
# source scripts/lib/load-project-env.sh # optional; loads GITEA_TOKEN
|
|
# bash scripts/deployment/gov-portals-git-pull-rebase.sh
|
|
#
|
|
# Options:
|
|
# --submodules-latest After updating the parent, run `git pull --rebase origin main`
|
|
# inside each portal submodule (DBIS ICCC OMNL XOM). You must
|
|
# then commit submodule pointer bumps in the parent if you
|
|
# intend to ship those SHAs.
|
|
# --dry-run Print commands only
|
|
#
|
|
# Env:
|
|
# GOV_PORTALS_SOURCE Default: /home/intlc/projects/gov-portals-monorepo
|
|
# GOV_PORTALS_REF Default: main
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
# shellcheck disable=SC1090
|
|
[ -f "$PROJECT_ROOT/.env" ] && set +u && source "$PROJECT_ROOT/.env" 2>/dev/null || true && set -u
|
|
|
|
GOV_PORTALS_SOURCE="${GOV_PORTALS_SOURCE:-/home/intlc/projects/gov-portals-monorepo}"
|
|
GOV_PORTALS_REF="${GOV_PORTALS_REF:-main}"
|
|
SUBMODULES_LATEST=false
|
|
DRY_RUN=false
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--submodules-latest) SUBMODULES_LATEST=true ;;
|
|
--dry-run) DRY_RUN=true ;;
|
|
esac
|
|
done
|
|
|
|
die() { echo "ERROR: $*" >&2; exit 1; }
|
|
log() { echo "[$(date +%H:%M:%S)] $*"; }
|
|
|
|
[[ -d "$GOV_PORTALS_SOURCE/.git" ]] || die "Not a git repo: $GOV_PORTALS_SOURCE"
|
|
|
|
git_auth_args=()
|
|
if [[ -n "${GITEA_TOKEN:-}" ]]; then
|
|
git_auth_args=(-c "http.extraHeader=Authorization: token ${GITEA_TOKEN}")
|
|
fi
|
|
[[ ${#git_auth_args[@]} -gt 0 ]] || die "GITEA_TOKEN is unset. Add it to $PROJECT_ROOT/.env"
|
|
|
|
run() {
|
|
if [[ "$DRY_RUN" == "true" ]]; then
|
|
echo "DRY: $*"
|
|
else
|
|
eval "$@"
|
|
fi
|
|
}
|
|
|
|
ensure_on_branch() {
|
|
local repo="$1"
|
|
local ref="$2"
|
|
if ! git -C "$repo" symbolic-ref -q HEAD >/dev/null 2>&1; then
|
|
log "$repo: detached HEAD — checking out $ref"
|
|
run "git -C \"$repo\" checkout \"$ref\""
|
|
fi
|
|
}
|
|
|
|
log "Repo: $GOV_PORTALS_SOURCE (ref: $GOV_PORTALS_REF)"
|
|
ensure_on_branch "$GOV_PORTALS_SOURCE" "$GOV_PORTALS_REF"
|
|
|
|
dirty="$(git -C "$GOV_PORTALS_SOURCE" status --porcelain)"
|
|
[[ -z "$dirty" ]] || die "Working tree not clean in $GOV_PORTALS_SOURCE — commit or stash before rebasing."
|
|
|
|
for sub in DBIS ICCC OMNL XOM; do
|
|
d="$GOV_PORTALS_SOURCE/$sub"
|
|
[[ -d "$d/.git" ]] || continue
|
|
sd="$(git -C "$d" status --porcelain)"
|
|
[[ -z "$sd" ]] || die "Submodule $sub is dirty — commit or stash before rebasing."
|
|
done
|
|
|
|
run "git -C \"$GOV_PORTALS_SOURCE\" \"${git_auth_args[@]}\" fetch origin"
|
|
run "git -C \"$GOV_PORTALS_SOURCE\" pull --rebase origin \"$GOV_PORTALS_REF\""
|
|
run "git -C \"$GOV_PORTALS_SOURCE\" \"${git_auth_args[@]}\" submodule update --init --recursive"
|
|
|
|
if [[ "$SUBMODULES_LATEST" == "true" ]]; then
|
|
for sub in DBIS ICCC OMNL XOM; do
|
|
d="$GOV_PORTALS_SOURCE/$sub"
|
|
[[ -d "$d/.git" ]] || continue
|
|
log "Pull --rebase $sub"
|
|
ensure_on_branch "$d" "$GOV_PORTALS_REF"
|
|
run "git -C \"$d\" \"${git_auth_args[@]}\" fetch origin"
|
|
run "git -C \"$d\" pull --rebase origin \"$GOV_PORTALS_REF\""
|
|
done
|
|
log "Submodules are at latest origin/$GOV_PORTALS_REF. If parent shows modified submodules, commit pointer updates in the monorepo before sync."
|
|
fi
|
|
|
|
log "Done. HEAD: $(git -C "$GOV_PORTALS_SOURCE" log -1 --oneline)"
|