ci: cleanup build dirs; add web start script; fix NEXT_PUBLIC_CONVEX_URL usage

This commit is contained in:
Esdras Renan 2025-10-16 11:18:56 -03:00
parent 4724255e79
commit c785094e4f
3 changed files with 84 additions and 7 deletions

View file

@ -234,13 +234,29 @@ jobs:
echo "Heartbeat HTTP=$HB"
if [ "$HB" != "200" ]; then echo "Heartbeat failed"; exit 1; fi
- name: Cleanup old build workdirs (keep last 3)
- name: Cleanup current build workdir
run: |
set -e
find "$HOME/apps" -maxdepth 1 -type d -name 'sistema.build.*' | sort -r | tail -n +4 | while read dir; do
if [ -n "${EFFECTIVE_APP_DIR:-}" ] && [ -d "$EFFECTIVE_APP_DIR" ]; then
echo "Removing current build dir: $EFFECTIVE_APP_DIR"
rm -rf "$EFFECTIVE_APP_DIR" || echo "Failed to remove $EFFECTIVE_APP_DIR (will try old dirs next)"
fi
- name: Cleanup old build workdirs (keep last 2)
run: |
set -e
ROOT="$HOME/apps"
KEEP=2
echo "Scanning $ROOT for old sistema.build.* dirs"
LIST=$(find "$ROOT" -maxdepth 1 -type d -name 'sistema.build.*' | sort -r || true)
echo "$LIST" | sed -n "1,${KEEP}p" | sed 's/^/Keeping: /' || true
echo "$LIST" | sed "1,${KEEP}d" | while read dir; do
[ -z "$dir" ] && continue
echo "Removing $dir"
sudo rm -rf "$dir"
done || true
rm -rf "$dir" || echo "Failed to remove $dir"
done
echo "Disk usage (top 10 under $ROOT):"
du -sh "$ROOT"/* 2>/dev/null | sort -rh | head -n 10 || true
- name: Restart web service with new code
run: |
@ -271,6 +287,15 @@ jobs:
echo "Using APP_DIR (fallback)=$FALLBACK_DIR"
echo "EFFECTIVE_APP_DIR=$FALLBACK_DIR" >> "$GITHUB_ENV"
- name: Validate secrets present (Convex)
env:
CONVEX_SELF_HOSTED_URL: ${{ secrets.CONVEX_SELF_HOSTED_URL }}
CONVEX_SELF_HOSTED_ADMIN_KEY: ${{ secrets.CONVEX_SELF_HOSTED_ADMIN_KEY }}
run: |
set -e
if [ -z "${CONVEX_SELF_HOSTED_URL:-}" ]; then echo "Missing secret: CONVEX_SELF_HOSTED_URL" >&2; exit 1; fi
if [ -z "${CONVEX_SELF_HOSTED_ADMIN_KEY:-}" ]; then echo "Missing secret: CONVEX_SELF_HOSTED_ADMIN_KEY" >&2; exit 1; fi
- name: Sync workspace to APP_DIR (preserving local env)
run: |
mkdir -p "$EFFECTIVE_APP_DIR"
@ -336,6 +361,27 @@ jobs:
-e CONVEX_SELF_HOSTED_ADMIN_KEY \
node:20-bullseye bash -lc "set -euo pipefail; unset CONVEX_DEPLOYMENT; corepack enable; corepack prepare pnpm@9 --activate; pnpm install --frozen-lockfile --prod=false; pnpm exec convex deploy"
- name: Cleanup current build workdir (convex)
run: |
set -e
if [ -n "${EFFECTIVE_APP_DIR:-}" ] && [ -d "$EFFECTIVE_APP_DIR" ]; then
echo "Removing current build dir: $EFFECTIVE_APP_DIR"
rm -rf "$EFFECTIVE_APP_DIR" || echo "Failed to remove $EFFECTIVE_APP_DIR"
fi
- name: Cleanup old convex build workdirs (keep last 2)
run: |
set -e
ROOT="$HOME/apps"
KEEP=2
LIST=$(find "$ROOT" -maxdepth 1 -type d -name 'sistema.build.*' | sort -r || true)
echo "$LIST" | sed -n "1,${KEEP}p" | sed 's/^/Keeping: /' || true
echo "$LIST" | sed "1,${KEEP}d" | while read dir; do
[ -z "$dir" ] && continue
echo "Removing $dir"
rm -rf "$dir" || echo "Failed to remove $dir"
done
desktop_release:
name: Desktop Release (Windows)
if: ${{ startsWith(github.ref, 'refs/tags/v') }}