#!/bin/bash # Flows source ./flows/base source ./flows/git source ./flows/packaging source ./flows/rust # Vars POSTGRES_VERSION="17" POSTGRES_CONFIG_PATH="/opt/homebrew/opt/postgresql@${POSTGRES_VERSION}/bin/pg_config" DEPENDENCIES=(cargo git icu4c pkg-config "postgresql@${POSTGRES_VERSION}") CARGO_DEPENDENCIES=(cargo-pgrx==0.14.0) PACKAGE_NAME="jspg" GITEA_ORGANIZATION="cellular" GITEA_REPOSITORY="jspg" env() { # Check if GITEA_TOKEN is set if [ -z "$GITEA_TOKEN" ]; then # If not set, try to get it from kubectl GITEA_TOKEN=$(kubectl get secret -n cellular gitea-git -o jsonpath='{.data.token}' | base64 --decode) if [ -z "$GITEA_TOKEN" ]; then echo -e "โŒ ${RED}GITEA_TOKEN is not set and couldn't be retrieved from kubectl${RESET}" >&2 exit 1 fi export GITEA_TOKEN fi echo -e "๐Ÿ’ฐ ${GREEN}Environment variables set${RESET}" } pgrx-prepare() { echo -e "${BLUE}Initializing pgrx...${RESET}" # Explicitly point to the postgresql@${POSTGRES_VERSION} pg_config, don't rely on 'which' local POSTGRES_CONFIG_PATH="/opt/homebrew/opt/postgresql@${POSTGRES_VERSION}/bin/pg_config" if [ ! -x "$POSTGRES_CONFIG_PATH" ]; then echo -e "${RED}Error: pg_config not found or not executable at $POSTGRES_CONFIG_PATH.${RESET}" echo -e "${YELLOW}Ensure postgresql@${POSTGRES_VERSION} is installed correctly via Homebrew.${RESET}" exit 1 fi if cargo pgrx init --pg"$POSTGRES_VERSION"="$POSTGRES_CONFIG_PATH"; then echo -e "${GREEN}pgrx initialized successfully.${RESET}" else echo -e "${RED}Failed to initialize pgrx. Check PostgreSQL development packages are installed and $POSTGRES_CONFIG_PATH is valid.${RESET}" exit 1 fi } build() { local version version=$(get-version) || return 1 local package_dir="./package" local tarball_name="${GITEA_REPOSITORY}.tar.gz" local tarball_path="${package_dir}/${tarball_name}" echo -e "๐Ÿ“ฆ Creating source tarball v$version for ${GITEA_REPOSITORY} in $package_dir..." # Clean previous package dir rm -rf "${package_dir}" mkdir -p "${package_dir}" # Create the source tarball excluding specified patterns echo -e " ${CYAN}Creating tarball: ${tarball_path}${RESET}" if tar --exclude='.git*' --exclude='./target' --exclude='./package' -czf "${tarball_path}" .; then echo -e "โœจ ${GREEN}Successfully created source tarball: ${tarball_path}${RESET}" else echo -e "โŒ ${RED}Failed to create source tarball.${RESET}" >&2 return 1 fi } install() { local version version=$(get-version) || return 1 echo -e "๐Ÿ”ง ${CYAN}Building and installing PGRX extension v$version into local PostgreSQL...${RESET}" # Run the pgrx install command # It implicitly uses --release unless --debug is passed # It finds pg_config or you can add flags like --pg-config if needed if ! cargo pgrx install "$@"; then # Pass any extra args like --debug echo -e "โŒ ${RED}cargo pgrx install command failed.${RESET}" >&2 return 1 fi echo -e "โœจ ${GREEN}PGRX extension v$version successfully built and installed.${RESET}" } test() { echo -e "๐Ÿงช ${CYAN}Running jspg tests...${RESET}" cargo pgrx test "pg${POSTGRES_VERSION}" "$@" } clean() { echo -e "๐Ÿงน ${CYAN}Cleaning build artifacts...${RESET}" cargo clean # Use standard cargo clean } jspg-usage() { echo -e " ${CYAN}JSPG Commands:${RESET}" echo -e " prepare Check OS, Cargo, and PGRX dependencies." echo -e " install [opts] Run prepare, then build and install the extension locally." echo -e " reinstall [opts] Run prepare, clean, then build and install the extension locally." echo -e " test [opts] Run pgrx integration tests." echo -e " clean Remove pgrx build artifacts." echo -e " build Build release artifacts into ./package/ (called by release)." echo -e " tag Tag the current version (called by release)." echo -e " package Upload artifacts from ./package/ (called by release)." echo -e " release Perform a full release (increments patch, builds, tags, pushes, packages)." } jspg-flow() { case "$1" in prepare) base prepare; cargo-prepare; pgrx-prepare; return 0;; build) build; return 0;; install) base prepare; cargo-prepare; pgrx-prepare; install "$@"; return 0;; reinstall) base prepare; cargo-prepare; pgrx-prepare; install "$@"; return 0;; test) test; return 0;; package) env; package; return 0;; release) env; release; return 0;; clean) clean; return 0;; *) return 1 ;; esac } register-flow "jspg-flow" "jspg-usage" dispatch "$@"