pulltime-storage / start.sh
github-actions[bot]
deploy-storage: ef32eba4 - 2026-07-09 13:49 UTC
b1d6098
Raw
History Blame Contribute Delete
1.25 kB
#!/usr/bin/env bash
set -euo pipefail
if [ -z "${GH_REPO_TOKEN:-}" ]; then
echo "GH_REPO_TOKEN secret missing. Configure it in Hugging Face Space Settings -> Variables and secrets." >&2
exit 1
fi
REPO_SLUG="${GH_REPO_SLUG:-shs3131/pulltime}"
REPO_REF="${GH_REPO_REF:-main}"
APP_SUBDIR="${GH_APP_SUBDIR:-server/storage-service}"
APP_DIR="/runtime/app"
mkdir -p /runtime
rm -rf "$APP_DIR"
git clone --depth 1 --branch "$REPO_REF" "https://x-access-token:${GH_REPO_TOKEN}@github.com/${REPO_SLUG}.git" "$APP_DIR"
# Resolve app directory safely even if GH_APP_SUBDIR is misconfigured.
APP_SUBDIR="${APP_SUBDIR#/}"
RESOLVED_SUBDIR=""
for candidate in "$APP_SUBDIR" "server/storage-service" "storage-service"; do
if [ -f "$APP_DIR/$candidate/package.json" ]; then
RESOLVED_SUBDIR="$candidate"
break
fi
done
if [ -z "$RESOLVED_SUBDIR" ]; then
echo "package.json not found. Checked: $APP_SUBDIR, server/storage-service, storage-service" >&2
exit 1
fi
cd "$APP_DIR/$RESOLVED_SUBDIR"
echo "Using app subdir: $RESOLVED_SUBDIR"
if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then
npm ci --omit=dev
else
echo "Lockfile not found, falling back to npm install --omit=dev"
npm install --omit=dev
fi
exec npm start