-
Notifications
You must be signed in to change notification settings - Fork 3
37 lines (29 loc) · 1.03 KB
/
cleanup-pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 }}
# 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/pr-$PR_NUMBER
# Stop and remove the container for this PR
docker ps -q --filter "name=pr-${PR_NUMBER}" | xargs -r docker stop
docker ps -aq --filter "name=pr-${PR_NUMBER}" | xargs -r docker rm
EOF
env:
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_DIR: ${{ secrets.DEPLOY_DIR }}