Merge pull request 'Automatic cleanup' (#7) from feature/staging into main
All checks were successful
Build and Deploy / build (push) Successful in 6s
Build and Deploy / deploy (push) Successful in 13s

Reviewed-on: #7
This commit is contained in:
Sergei Poljanski 2025-12-26 14:18:45 +00:00
commit e2cd7ebee1
2 changed files with 37 additions and 0 deletions

View file

@ -0,0 +1,35 @@
name: Cleanup Staging
on:
delete:
branches:
- '**'
jobs:
cleanup:
if: github.event.ref_type == 'branch' && github.event.ref != 'main'
runs-on: arch-latest
steps:
- name: Remove staging environment
uses: appleboy/ssh-action@v1.2.3
env:
BRANCH_NAME: ${{ github.event.ref }}
with:
host: ${{ secrets.DEPLOY_IP }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
envs: BRANCH_NAME
script: |
BRANCH_SLUG=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]//g')
DEPLOY_DIR="/opt/czsk-${BRANCH_SLUG}"
CONTAINER_NAME="czsk-${BRANCH_SLUG}"
if [ -d "$DEPLOY_DIR" ]; then
cd $DEPLOY_DIR
docker compose down --rmi all 2>/dev/null || true
cd /
rm -rf $DEPLOY_DIR
echo "Cleaned up staging: ${BRANCH_SLUG}"
else
echo "No staging environment found for: ${BRANCH_SLUG}"
fi

View file

@ -12,3 +12,5 @@ Deployments are automatic on push via Forgejo Actions.
Branch names are sanitized to `a-z0-9` only (lowercase, symbols removed).
**Example:** `fix1/blabla` deploys to `fix1blabla.staging.czsk.it`
Staging environments are automatically removed when the branch is deleted.