#!/bin/bash # Promote tested edge package artifacts into stable without overwriting set -e BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..") source "$BUILD_ROOT/helpers/message-helpers.sh" source "$BUILD_ROOT/helpers/paths.sh" DRY_RUN=false SYNC_REMOTE="" SKIP_PROD_CHECK=false PACKAGE="" while [[ $# -gt 0 ]]; do case $1 in --arch) ARCH="$2" update_arch_paths shift 2 ;; --package) PACKAGE="$2" shift 2 ;; --dry-run) DRY_RUN=true shift ;; --sync-remote) SYNC_REMOTE="$2" shift 2 ;; --skip-prod-check) SKIP_PROD_CHECK=true shift ;; -h | --help) echo "Usage: $0 [OPTIONS]" echo "" echo "Options:" echo " --arch Target architecture (x86_64 or aarch64, default: x86_64)" echo " --package Migrate only the specified package" echo " --dry-run Preview migration and cleanup without changing files" echo " --sync-remote Rclone remote for sync (default: pkgs.omarchy.org:omarchy-pkgs)" echo " --skip-prod-check Skip production environment check during sync" echo " -h, --help Show this help message" echo "" echo "What it does:" echo " 1) Rsync tested package artifacts from edge -> stable (without overwriting existing files)" echo " 2) Run stable cleanup (keep 2 versions)" echo " 3) Update stable repository database" echo " 4) Sync stable repository to remote (prompts for confirmation)" exit 0 ;; *) print_error "Unknown option: $1" exit 1 ;; esac done SOURCE_DIR="$BUILD_ROOT/pkgs.omarchy.org/edge/$ARCH" TARGET_DIR="$BUILD_ROOT/pkgs.omarchy.org/stable/$ARCH" print_header "Promote Edge Artifacts to Stable" print_info "Architecture: $ARCH" print_info "Source: $SOURCE_DIR" print_info "Target: $TARGET_DIR" if [[ ! -d "$SOURCE_DIR" ]]; then print_error "Source directory not found: $SOURCE_DIR" exit 1 fi # Version segment starts with a digit (same assumption as bin/clean-repo), # so omarchy-nvim doesn't also match omarchy-nvim-extras PACKAGE_GLOB="*" if [[ -n "$PACKAGE" ]]; then print_info "Package: $PACKAGE" PACKAGE_GLOB="$PACKAGE-[0-9]*" if ! compgen -G "$SOURCE_DIR/$PACKAGE_GLOB.pkg.tar.*" >/dev/null; then print_error "No artifacts matching $PACKAGE_GLOB.pkg.tar.* found in $SOURCE_DIR" exit 1 fi fi mkdir -p "$TARGET_DIR" if [[ "$DRY_RUN" == true ]]; then print_warning "DRY RUN MODE - No changes will be made" fi print_info "Syncing package files from edge to stable (ignore existing)..." RSYNC_FLAGS="-av --ignore-existing --include=*/ --include=$PACKAGE_GLOB.pkg.tar.* --exclude=*" if [[ "$DRY_RUN" == true ]]; then RSYNC_FLAGS="$RSYNC_FLAGS -n" fi # shellcheck disable=SC2086 rsync $RSYNC_FLAGS "$SOURCE_DIR/" "$TARGET_DIR/" print_info "Cleaning stable repository..." if [[ "$DRY_RUN" == true ]]; then "$BUILD_ROOT/bin/repo" clean --mirror stable --arch "$ARCH" --dry-run print_info "Skipping database update in dry run mode" else "$BUILD_ROOT/bin/repo" clean --mirror stable --arch "$ARCH" print_info "Updating stable repository database..." "$BUILD_ROOT/bin/repo" update --mirror stable --arch "$ARCH" fi if [[ "$DRY_RUN" != true ]]; then echo "" print_info "Syncing stable repository to remote..." SYNC_ARGS=("--mirror" "stable" "--arch" "$ARCH") if [[ -n "$SYNC_REMOTE" ]]; then SYNC_ARGS+=("--remote" "$SYNC_REMOTE") fi if [[ "$SKIP_PROD_CHECK" == true ]]; then SYNC_ARGS+=("--skip-prod-check") fi "$BUILD_ROOT/bin/sync-repo" "${SYNC_ARGS[@]}" || { print_error "Sync failed" exit 1 } fi print_success "Migration workflow complete"