File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -60,38 +60,40 @@ jobs:
6060 sudo -n /usr/bin/systemctl restart downpatch.service
6161 EOF
6262
63- - name : Clean Releases
63+ - name : Clean Releases (server)
6464 shell : bash
6565 run : |
6666 set -euo pipefail
67+ ssh -p "${{ secrets.SSH_PORT }}" -i ~/.ssh/id_ed25519 "${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}" << 'EOF'
68+ set -euo pipefail
6769
6870 RELEASES_DIR="/var/www/downpatch/releases"
6971 CURRENT=""
70-
71- # If current doesn't exist, don't fail the script
72+
7273 if [ -e /var/www/downpatch/current ]; then
7374 CURRENT="$(readlink -f /var/www/downpatch/current || true)"
7475 fi
75-
76+
7677 cd "$RELEASES_DIR"
7778 [ "$(pwd -P)" = "$RELEASES_DIR" ] || exit 1
78-
79+
7980 mapfile -t dirs < <(find "$RELEASES_DIR" -mindepth 1 -maxdepth 1 -type d -printf '%T@ %p\n' | sort -nr | awk '{print $2}')
80-
81+
8182 KEEP=4
8283 kept=0
83-
84+
8485 for FULL in "${dirs[@]}"; do
85- # never delete the active release
8686 if [ -n "$CURRENT" ] && [ "$FULL" = "$CURRENT" ]; then
8787 continue
8888 fi
89-
89+
9090 kept=$((kept+1))
9191 if [ "$kept" -gt "$KEEP" ]; then
9292 echo "Deleting $FULL"
9393 rm -rf -- "$FULL"
9494 fi
9595 done
96+ EOF
97+
9698
9799
You can’t perform that action at this time.
0 commit comments