123 lines
4.2 KiB
Bash
Executable File
123 lines
4.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Flows
|
|
source "flows/base"
|
|
source "flows/release"
|
|
|
|
# Vars
|
|
# pg_config is tricky as it's not always just a command but needs PATH setup
|
|
# We check for it specifically in the prepare function.
|
|
DEPENDENCIES=(cargo git icu4c pkg-config)
|
|
CARGO_DEPENDENCIES=(cargo-pgrx)
|
|
GITEA_ORGANIZATION="cellular"
|
|
GITEA_REPOSITORY="jspg"
|
|
PACKAGE_NAME="jspg"
|
|
|
|
cargo-prepare() {
|
|
echo -e "${BLUE}Checking Cargo dependencies...${RESET}"
|
|
for DEP in "${CARGO_DEPENDENCIES[@]}"; do \
|
|
if ! command -v "${DEP}" &> /dev/null; then \
|
|
echo -e "${YELLOW}Attempting to install ${DEP} via cargo...${RESET}"; \
|
|
if cargo install "${DEP}"; then
|
|
echo -e "✅ ${GREEN}${DEP}: installed via cargo${RESET}"; \
|
|
else
|
|
echo -e "❌ ${RED}${DEP}: failed to install via cargo${RESET}"; \
|
|
exit 1; \
|
|
fi
|
|
else \
|
|
echo -e "✅ ${GREEN}${DEP}: installed${RESET}"; \
|
|
fi \
|
|
done
|
|
echo -e "${GREEN}All Cargo dependencies met.${RESET}"
|
|
}
|
|
|
|
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}"; \
|
|
fi
|
|
echo -e "${GREEN}PostgreSQL dependencies met.${RESET}"
|
|
}
|
|
|
|
# Build function (used by release flow)
|
|
# Creates release artifacts in ./package/
|
|
build() {
|
|
local version
|
|
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
|
|
fi
|
|
|
|
# Create package directory
|
|
mkdir -p "$PACKAGE_DIRECTORY"
|
|
|
|
# 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
|
|
fi
|
|
|
|
echo -e " ${CYAN}Copying artifacts to $PACKAGE_DIRECTORY...${RESET}"
|
|
cp "$so_file" "$PACKAGE_DIRECTORY/"
|
|
cp "$sql_file" "$PACKAGE_DIRECTORY/"
|
|
|
|
echo -e "✨ ${GREEN}Build v$version complete. Artifacts ready in ./$PACKAGE_DIRECTORY/${RESET}"
|
|
}
|
|
|
|
# Install for development (non-release)
|
|
install() {
|
|
echo -e "🔧 ${CYAN}Installing jspg extension (dev build)...${RESET}"
|
|
cargo pgrx install "$@" # Pass any extra args like --debug
|
|
}
|
|
|
|
# Run tests
|
|
test() {
|
|
echo -e "🧪 ${CYAN}Running jspg tests...${RESET}"
|
|
cargo pgrx test "$@" # Pass any extra args
|
|
}
|
|
|
|
# Clean build artifacts
|
|
clean() {
|
|
echo -e "🧹 ${CYAN}Cleaning build artifacts...${RESET}"
|
|
cargo pgrx clean
|
|
}
|
|
|
|
usage() {
|
|
echo -e " install [opts] Build and install the extension locally (dev)."
|
|
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)."
|
|
}
|
|
|
|
# --- Command Dispatcher ---
|
|
case "$1" in
|
|
prepare) base prepare; cargo-prepare; postgres-prepare;;
|
|
install) install "${@:2}";;
|
|
test) test "${@:2}";;
|
|
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
|
|
esac |