Files
golfgame/.gitea/workflows/deploy-staging.yml
adlee-was-taken 612eccf03b
All checks were successful
Build & Deploy Staging / build-and-deploy (release) Successful in 28s
fix(ci): force-update tags on deploy fetch
git fetch origin won't replace a tag that already exists locally pointing
at a different commit. When v3.3.5 was force-moved on origin after a
first failed CI run, the staging runner kept the stale tag cached and
re-checked-out the old commit — the compose-env-wiring fix was never
actually applied and the container booted without LEADERBOARD_INCLUDE_TEST_DEFAULT.

--tags --force makes the behaviour safe for moved tags.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 14:02:06 -04:00

54 lines
1.8 KiB
YAML

name: Build & Deploy Staging
on:
release:
types: [published]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Build, push, and deploy to staging
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.STAGING_HOST }}
username: root
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
set -e
TAG="${{ github.ref_name }}"
IMAGE="git.adlee.work/alee/golfgame"
cd /opt/golfgame
# Pull latest code and checkout the release tag. `--tags --force`
# so that a tag moved on origin (e.g. hotfix on top of an existing
# version) actually updates locally instead of silently reusing a
# stale cached tag position.
git fetch origin --tags --force
git checkout "$TAG"
# Build the image
docker build -t "$IMAGE:$TAG" -t "$IMAGE:latest" -t golfgame-app:latest .
# Push to Gitea container registry
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.adlee.work -u "${{ secrets.REGISTRY_USER }}" --password-stdin
docker push "$IMAGE:$TAG"
docker push "$IMAGE:latest"
# Restart app (no --build, image already tagged)
docker compose -f docker-compose.staging.yml up -d app
# Wait for healthy
echo "Waiting for health check..."
for i in $(seq 1 30); do
if docker compose -f docker-compose.staging.yml ps app | grep -q "healthy"; then
echo "Staging deploy successful — $TAG"
exit 0
fi
sleep 2
done
echo "WARNING: app not healthy after 60s"
docker compose -f docker-compose.staging.yml logs --tail=20 app
exit 1