bilhej/.forgejo/workflows/deploy.yml
Joakim Mörling d078b9e125
All checks were successful
CI / Lint, type check, unit tests, coverage (push) Successful in 1m49s
CI / E2E browser tests (push) Successful in 46s
fix: overwrite existing git tag on deploy retry
The deploy workflow failed when re-running with the same version tag
because Git rejects pushing a tag that already exists on the remote.

- Delete local tag first (ignore if missing)
- Delete remote tag first (ignore if missing)
- Create and push the tag fresh

This makes deploys idempotent: retrying a failed deploy with the same
version (e.g., v0.1.0) will succeed by moving the tag to the current
commit. For a new deploy, the delete commands silently do nothing.
2026-05-20 12:28:16 +02:00

89 lines
3.2 KiB
YAML

name: Deploy to Production
on:
workflow_dispatch:
inputs:
version:
description: 'Version tag (e.g., v0.1.0)'
required: true
default: 'v0.1.0'
jobs:
deploy:
name: Build and deploy
runs-on: ubuntu-latest
steps:
- name: Checkout repository
run: |
git init
git remote add origin https://x-access-token:${FORGEJO_TOKEN}@srvr.nu/git/jocke/bilhej.git
git fetch --depth 1 origin ${GITHUB_SHA}
git checkout FETCH_HEAD
- name: Tag version
run: |
git tag -d ${{ github.event.inputs.version }} 2>/dev/null || true
git push origin --delete ${{ github.event.inputs.version }} 2>/dev/null || true
git tag ${{ github.event.inputs.version }}
git push origin ${{ github.event.inputs.version }}
- name: Write production .env
run: |
cat > .env << 'EOF'
POSTGRES_DB=${{ secrets.POSTGRES_DB }}
POSTGRES_USER=${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}
JWT_SECRET=${{ secrets.JWT_SECRET }}
STRIPE_SECRET_KEY=${{ secrets.STRIPE_SECRET_KEY }}
STRIPE_WEBHOOK_SECRET=${{ secrets.STRIPE_WEBHOOK_SECRET }}
STRIPE_PRICE_ID=${{ secrets.STRIPE_PRICE_ID }}
SWISH_NUMBER=${{ secrets.SWISH_NUMBER }}
EOF
- name: Build and start production stack
run: |
docker compose -f docker-compose.prod.yml up --build -d
- name: Wait for services
run: sleep 20
- name: Health check — backend API
run: |
for i in 1 2 3 4 5; do
if docker run --rm --network bilhej_default curlimages/curl:8.5.0 \
-sf http://bilhej-backend-prod:8080/api/vehicles/ZZZ999; then
echo "Backend is healthy"
exit 0
fi
echo "Attempt $i failed, retrying in 5s..."
sleep 5
done
echo "Backend health check failed"
exit 1
- name: Health check — frontend
run: |
for i in 1 2 3 4 5; do
if docker run --rm --network bilhej_default curlimages/curl:8.5.0 \
-sf http://bilhej-frontend-prod/ | grep -qi "bilhej\|Bilhej\|BilHej"; then
echo "Frontend is serving"
exit 0
fi
echo "Attempt $i failed, retrying in 5s..."
sleep 5
done
echo "Frontend health check failed"
exit 1
- name: Print deploy status
run: |
echo ""
echo "═══════════════════════════════════════════════════"
echo " Deployed ${{ github.event.inputs.version }} to production"
echo "═══════════════════════════════════════════════════"
echo ""
docker compose -f docker-compose.prod.yml ps
echo ""
echo "Containers running. Update nginx config on srvr.nu"
echo "to point bilhej.se to the frontend container."
echo ""