Skip to content

refactor: recipe structure #8

refactor: recipe structure

refactor: recipe structure #8

Workflow file for this run

name: Cleanup Deployed PR Server
on:
pull_request:
types: [closed]
jobs:
cleanup-server:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Stop and Remove Container
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
REPO_NAME=$(echo "${{ github.repository }}" | cut -d'/' -f2)
# SSH into server to stop and remove the container
ssh -o StrictHostKeyChecking=no $DEPLOY_USER@$DEPLOY_HOST <<EOF
# rm -rf the directory
rm -rf $DEPLOY_DIR/${REPO_NAME}-pr-$PR_NUMBER
# Stop and remove the container for this PR
docker ps -q --filter "name=${REPO_NAME}-pr-${PR_NUMBER}" | xargs -r docker stop
docker ps -aq --filter "name=${REPO_NAME}-pr-${PR_NUMBER}" | xargs -r docker rm
docker images "${REPO_NAME}-pr-${PR_NUMBER}*" -q | xargs -r docker rmi -f
EOF
env:
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_DIR: ${{ secrets.DEPLOY_DIR }}