all flow commands working, extension compiled
This commit is contained in:
125
flow
125
flow
@ -6,58 +6,89 @@ source "flows/release"
|
||||
source "flows/rust"
|
||||
|
||||
# Vars
|
||||
DEPENDENCIES=(cargo git icu4c pkg-config)
|
||||
CARGO_DEPENDENCIES=(cargo-pgrx)
|
||||
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)
|
||||
GITEA_ORGANIZATION="cellular"
|
||||
GITEA_REPOSITORY="jspg"
|
||||
PACKAGE_NAME="jspg"
|
||||
|
||||
postgres-prepare() {
|
||||
echo -e "${BLUE}Checking PostgreSQL dependencies...${RESET}"
|
||||
if ! command -v pg_config &> /dev/null; then
|
||||
echo -e "❌ ${RED}pg_config: missing. Ensure PostgreSQL development headers are installed and pg_config is in your PATH.${RESET}"; \
|
||||
exit 1; \
|
||||
else
|
||||
echo -e "✅ ${GREEN}pg_config: installed${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
|
||||
echo -e "${GREEN}PostgreSQL dependencies met.${RESET}"
|
||||
}
|
||||
|
||||
build() {
|
||||
local version
|
||||
version=$(get-version)
|
||||
local version=$(get-version)
|
||||
echo -e "📦 ${CYAN}Building release v$version for $PACKAGE_NAME...${RESET}"
|
||||
|
||||
# Build with cargo pgrx install --release
|
||||
if ! cargo pgrx install --release; then
|
||||
echo -e "❌ ${RED}Build failed during cargo pgrx install.${RESET}" >&2
|
||||
return 1
|
||||
|
||||
# Define target directories
|
||||
local package_dir="./package"
|
||||
local package_source_base_dir="./target/release"
|
||||
|
||||
# Define the actual base paths where package command places files within out-dir
|
||||
local package_lib_search_path="${package_source_base_dir}/opt/homebrew/lib/postgresql@17"
|
||||
local package_share_search_path="${package_source_base_dir}/opt/homebrew/share/postgresql@17/extension"
|
||||
|
||||
# Clean previous package dirs
|
||||
rm -rf "${package_dir}"
|
||||
mkdir -p "${package_dir}"
|
||||
|
||||
# Use cargo pgrx package to build and stage artifacts (release is default)
|
||||
if ! cargo pgrx package --pg-config "${POSTGRES_CONFIG_PATH}" --out-dir "${package_source_base_dir}"; then
|
||||
echo -e "❌ ${RED}Build failed during cargo pgrx package.${RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create package directory
|
||||
mkdir -p "$PACKAGE_DIRECTORY"
|
||||
echo -e " ${CYAN}Copying artifacts from ${package_source_base_dir} subdirs to ${package_dir}${RESET}"
|
||||
|
||||
# Find and copy artifacts (adjust paths if needed)
|
||||
# Assuming standard output locations for pgrx
|
||||
local pgrx_target_dir="target/release"
|
||||
local sql_file="${pgrx_target_dir}/${PACKAGE_NAME}.sql"
|
||||
local so_file # Varies by OS/arch, find it
|
||||
so_file=$(find "${pgrx_target_dir}" -maxdepth 1 -name "lib${PACKAGE_NAME}*.so" -print -quit || find "${pgrx_target_dir}" -maxdepth 1 -name "${PACKAGE_NAME}*.dylib" -print -quit || find "${pgrx_target_dir}" -maxdepth 1 -name "${PACKAGE_NAME}*.dll" -print -quit)
|
||||
|
||||
if [ -z "$so_file" ] || [ ! -f "$so_file" ]; then
|
||||
echo -e "❌ ${RED}Could not find shared library (.so/.dylib/.dll) in ${pgrx_target_dir}${RESET}" >&2
|
||||
return 1
|
||||
fi
|
||||
if [ ! -f "$sql_file" ]; then
|
||||
echo -e "❌ ${RED}Could not find SQL file ($sql_file)${RESET}" >&2
|
||||
return 1
|
||||
# Find and copy the library
|
||||
local lib_path=$(find "${package_lib_search_path}" -name "${PACKAGE_NAME}.dylib" -print -quit)
|
||||
if [[ -n "$lib_path" ]]; then
|
||||
cp "$lib_path" "${package_dir}/"
|
||||
echo -e " ✨ ${GREEN}Copied library: $(basename "$lib_path")${RESET}"
|
||||
else
|
||||
echo -e "❌ ${RED}Could not find library (${PACKAGE_NAME}.dylib) in package source dir.${RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e " ${CYAN}Copying artifacts to $PACKAGE_DIRECTORY...${RESET}"
|
||||
cp "$so_file" "$PACKAGE_DIRECTORY/"
|
||||
cp "$sql_file" "$PACKAGE_DIRECTORY/"
|
||||
# Find and copy the control file
|
||||
local control_path=$(find "${package_share_search_path}" -name "${PACKAGE_NAME}.control" -print -quit)
|
||||
if [[ -n "$control_path" ]]; then
|
||||
cp "$control_path" "${package_dir}/"
|
||||
echo -e " ✨ ${GREEN}Copied control file: $(basename "$control_path")${RESET}"
|
||||
else
|
||||
echo -e "❌ ${RED}Could not find control file (${PACKAGE_NAME}.control) in package source dir.${RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "✨ ${GREEN}Build v$version complete. Artifacts ready in ./$PACKAGE_DIRECTORY/${RESET}"
|
||||
# Find and copy the SQL file
|
||||
local sql_file_pattern="${PACKAGE_NAME}--*.sql"
|
||||
local sql_path=$(find "${package_share_search_path}" -name "${sql_file_pattern}" -print -quit)
|
||||
if [[ -n "$sql_path" ]]; then
|
||||
cp "$sql_path" "${package_dir}/"
|
||||
echo -e " ✨ ${GREEN}Copied SQL file: $(basename "$sql_path")${RESET}"
|
||||
else
|
||||
echo -e "❌ ${RED}Could not find SQL file (${sql_file_pattern}) in package source dir.${RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "✨ ${GREEN}Package artifacts created in ${package_dir}${RESET}"
|
||||
}
|
||||
|
||||
install() {
|
||||
@ -67,12 +98,12 @@ install() {
|
||||
|
||||
test() {
|
||||
echo -e "🧪 ${CYAN}Running jspg tests...${RESET}"
|
||||
cargo pgrx test "$@" # Pass any extra args
|
||||
cargo pgrx test "pg${POSTGRES_VERSION}" "$@"
|
||||
}
|
||||
|
||||
clean() {
|
||||
echo -e "🧹 ${CYAN}Cleaning build artifacts...${RESET}"
|
||||
cargo pgrx clean
|
||||
cargo clean # Use standard cargo clean
|
||||
}
|
||||
|
||||
usage() {
|
||||
@ -86,13 +117,13 @@ usage() {
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
prepare) base prepare; cargo-prepare; postgres-prepare;;
|
||||
install) install "${@:2}";;
|
||||
test) test "${@:2}";;
|
||||
prepare) base prepare; cargo-prepare; pgrx-prepare;;
|
||||
build) build;;
|
||||
install) install;;
|
||||
reinstall) reinstall;;
|
||||
test) test;;
|
||||
package) package;;
|
||||
release) create-release;;
|
||||
clean) clean;;
|
||||
build) build;;
|
||||
tag) tag;; # From release flow
|
||||
package) package;; # From release flow
|
||||
release) release;;
|
||||
*) base "$@";; # Handles base update and unknown commands via base-usage
|
||||
*) base "$@";;
|
||||
esac
|
||||
Reference in New Issue
Block a user