Files
jspg/flow

98 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# Flows
source "flows/base"
source "flows/release"
source "flows/rust"
# Vars
DEPENDENCIES=(cargo git icu4c pkg-config)
CARGO_DEPENDENCIES=(cargo-pgrx)
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}"; \
fi
echo -e "${GREEN}PostgreSQL dependencies met.${RESET}"
}
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() {
echo -e "🔧 ${CYAN}Installing jspg extension (dev build)...${RESET}"
cargo pgrx install "$@" # Pass any extra args like --debug
}
test() {
echo -e "🧪 ${CYAN}Running jspg tests...${RESET}"
cargo pgrx test "$@" # Pass any extra args
}
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)."
}
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