Skip to content

Wording change and pipeline update to clear old releases #20

Wording change and pipeline update to clear old releases

Wording change and pipeline update to clear old releases #20

name: Deploy downpatch.com
on:
push:
branches: ["main"]
workflow_dispatch: {}
concurrency:
group: downpatch-deploy
cancel-in-progress: true
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "10.0.x"
- name: Restore
run: dotnet restore ./downpatch.csproj
- name: Publish
run: dotnet publish ./downpatch.csproj -c Release -o ./out -r linux-x64 --self-contained true /p:PublishSingleFile=false
- name: Configure SSH
shell: bash
run: |
set -euo pipefail
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -p "${{ secrets.SSH_PORT }}" "${{ secrets.SSH_HOST }}" >> ~/.ssh/known_hosts
- name: Upload release via rsync
shell: bash
run: |
set -euo pipefail
RELEASE="${{ github.sha }}"
rsync -az --delete \
-e "ssh -p ${{ secrets.SSH_PORT }} -i ~/.ssh/id_ed25519" \
./out/ "${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/var/www/downpatch/releases/${RELEASE}/"
- name: Activate release + restart service
shell: bash
run: |
set -euo pipefail
RELEASE="${{ github.sha }}"
ssh -p "${{ secrets.SSH_PORT }}" -i ~/.ssh/id_ed25519 "${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}" << EOF
set -euo pipefail
ln -sfn "/var/www/downpatch/releases/${RELEASE}" /var/www/downpatch/current
sudo -n /usr/bin/systemctl restart downpatch.service
EOF
- name: Clean Releases
shell: bash
run: |
set -euo pipefail
RELEASES_DIR="/var/www/downpatch/releases"
CURRENT="$(readlink -f /var/www/downpatch/current)"
cd "$RELEASES_DIR"
[ "$(pwd -P)" = "$RELEASES_DIR" ] || exit 1
COUNT=0
ls -1dt */ | while read -r dir; do
FULL="$(readlink -f "$dir")"
# never delete the active release
[ "$FULL" = "$CURRENT" ] && continue
COUNT=$((COUNT+1))
if [ "$COUNT" -gt 4 ]; then
echo "Deleting $FULL"
rm -rf -- "$FULL"
fi
done