refactor: Improve genome submodule setup flow

This commit is contained in:
Matteo Cherubini 2026-05-09 11:34:21 +02:00
parent 8d984e2511
commit 01769021fa

View file

@ -2,7 +2,6 @@
# =============================================================================
# scripts/setup-genomes.sh
# Iterates through the GENOMES registry to provision remote and local repos.
# Handles git-crypt initialization and submodule linking.
# =============================================================================
set -euo pipefail
@ -15,48 +14,44 @@ source "providers/${PROVIDER}.sh"
step "Processing Genome Registry"
for entry in "${GENOMES[@]}"; do
# Parse name and description from the array
IFS='|' read -r GENOME_NAME GENOME_DESC <<< "$entry"
export GENOME_NAME GENOME_DESC
info "Processing: ${GENOME_NAME}..."
# 1. Remote Provisioning (Idempotent: skips if exists)
# 1. Remote Creation (Idempotent)
provider_create_repo "${GENOME_NAME}" "${GENOME_DESC}" "true"
SSH_URL=$(provider_ssh_url "${GENOME_NAME}")
GENOME_PATH="${WORK_DIR}/${MASTER_REPO}/${GENOME_NAME}"
if [ ! -d "${GENOME_PATH}" ]; then
info "Creating local directory and initializing scaffold..."
mkdir -p "${GENOME_PATH}"
cd "${GENOME_PATH}"
git init
cd "${WORK_DIR}/${MASTER_REPO}"
info "Linking ${GENOME_NAME} as a submodule..."
# IMPORTANT: Initialize git-crypt BEFORE creating sensitive files
# FIX BUG 1: Adding the submodule clones the empty remote repository
git submodule add "${SSH_URL}" "${GENOME_NAME}"
cd "${GENOME_NAME}"
# IMPORTANT: Initialize git-crypt BEFORE creating any files
gcrypt_init
# Create directory structure and apply templates
scaffold_genome "."
install_precommit_hook "."
# Initial commit and push to remote
# Initial genome push
git add .
git commit -m "feat: initial scaffold for ${GENOME_NAME}"
SSH_URL=$(provider_ssh_url "${GENOME_NAME}")
git remote add origin "${SSH_URL}"
git commit -m "feat: initial scaffold and git-crypt init for ${GENOME_NAME}"
git push -u origin main
# Export the AES key for the user to back up
# Key export and instructions (Fix Obs B)
gcrypt_export_key "${GENOME_NAME}"
gcrypt_print_key_instructions "${GENOME_NAME}"
# 2. Link as submodule in the Master repository
# Return to master to consolidate the submodule addition
cd "${WORK_DIR}/${MASTER_REPO}"
info "Linking ${GENOME_NAME} as a submodule..."
git submodule add "${SSH_URL}" "${GENOME_NAME}"
git add .gitmodules "${GENOME_NAME}"
git commit -m "feat: link submodule ${GENOME_NAME}"
else
warn "Genome directory '${GENOME_NAME}' already exists. Skipping local setup."
fi
done
success "Genome provisioning completed."