144 lines
4.9 KiB
Bash
Executable File
144 lines
4.9 KiB
Bash
Executable File
#!/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"
|
|
|
|
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=$(get-version)
|
|
echo -e "📦 ${CYAN}Preparing source package v$version for $PACKAGE_NAME...${RESET}"
|
|
|
|
local package_dir="./package"
|
|
|
|
# Clean previous package dir
|
|
rm -rf "${package_dir}"
|
|
mkdir -p "${package_dir}"
|
|
|
|
# Copy necessary source files
|
|
echo -e " ${CYAN}Copying source files to ${package_dir}${RESET}"
|
|
cp -R src "${package_dir}/"
|
|
cp Cargo.toml "${package_dir}/"
|
|
cp Cargo.lock "${package_dir}/"
|
|
cp jspg.control "${package_dir}/"
|
|
|
|
# Verify files copied
|
|
if [ ! -d "${package_dir}/src" ] || [ ! -f "${package_dir}/Cargo.toml" ] || [ ! -f "${package_dir}/Cargo.lock" ] || [ ! -f "${package_dir}/jspg.control" ]; then
|
|
echo -e "❌ ${RED}Failed to copy all source files to ${package_dir}.${RESET}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "✨ ${GREEN}Source package prepared in ${package_dir}${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 "pg${POSTGRES_VERSION}" "$@"
|
|
}
|
|
|
|
clean() {
|
|
echo -e "🧹 ${CYAN}Cleaning build artifacts...${RESET}"
|
|
cargo clean # Use standard cargo clean
|
|
}
|
|
|
|
# Override base package function to create and upload a source tarball
|
|
package() {
|
|
local version
|
|
version=$(get-version) || return 1
|
|
local package_dir="./package"
|
|
local tarball_name="${GITEA_REPOSITORY}-src-v${version}.tar.gz"
|
|
local tarball_path="${package_dir}/${tarball_name}"
|
|
|
|
echo -e "📦 ${CYAN}Creating source tarball ${tarball_name}...${RESET}"
|
|
|
|
# Ensure the package directory exists and has content
|
|
if [ ! -d "$package_dir" ] || [ -z "$(ls -A "$package_dir")" ]; then
|
|
echo -e "❌ ${RED}Source files not found in $package_dir. Run 'flow build' first.${RESET}" >&2
|
|
return 1
|
|
fi
|
|
|
|
# Create the tarball from the contents of the package directory
|
|
if tar -czf "${tarball_path}" -C "${package_dir}" .; then
|
|
echo -e "✨ ${GREEN}Created source tarball: ${tarball_path}${RESET}"
|
|
else
|
|
echo -e "❌ ${RED}Failed to create tarball.${RESET}" >&2
|
|
return 1
|
|
fi
|
|
|
|
echo -e "📤 ${CYAN}Uploading ${tarball_name} to Gitea...${RESET}"
|
|
if curl -X PUT \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
"$GITEA_API_URL/packages/$GITEA_ORGANIZATION/generic/$GITEA_REPOSITORY/$version/$tarball_name" \
|
|
-H "Content-Type: application/gzip" \
|
|
-T "${tarball_path}" \
|
|
-f > /dev/null; then
|
|
echo -e "✨ ${GREEN}Successfully uploaded ${tarball_name}${RESET}"
|
|
else
|
|
echo -e "❌ ${RED}Failed to upload ${tarball_name}${RESET}" >&2
|
|
# Clean up tarball on failure? Maybe not, user might want it.
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
jspg-usage() {
|
|
echo -e " ${CYAN}JSPG Commands:${RESET}"
|
|
echo -e " prepare Check OS, Cargo, and PGRX dependencies."
|
|
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)."
|
|
}
|
|
|
|
jspg-flow() {
|
|
case "$1" in
|
|
prepare) base prepare; cargo-prepare; pgrx-prepare; return 0;;
|
|
build) build; return 0;;
|
|
install) install; return 0;;
|
|
reinstall) reinstall; return 0;;
|
|
test) test; return 0;;
|
|
package) package; return 0;;
|
|
release) release; return 0;;
|
|
clean) clean; return 0;;
|
|
*) return 1 ;;
|
|
esac
|
|
}
|
|
|
|
register-flow "jspg-flow" "jspg-usage"
|
|
dispatch "$@" |