chore(content): bump submodule #34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 (server) | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| ssh -p "${{ secrets.SSH_PORT }}" -i ~/.ssh/id_ed25519 "${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}" << 'EOF' | |
| set -euo pipefail | |
| RELEASES_DIR="/var/www/downpatch/releases" | |
| CURRENT="" | |
| if [ -e /var/www/downpatch/current ]; then | |
| CURRENT="$(readlink -f /var/www/downpatch/current || true)" | |
| fi | |
| cd "$RELEASES_DIR" | |
| [ "$(pwd -P)" = "$RELEASES_DIR" ] || exit 1 | |
| mapfile -t dirs < <(find "$RELEASES_DIR" -mindepth 1 -maxdepth 1 -type d -printf '%T@ %p\n' | sort -nr | awk '{print $2}') | |
| KEEP=4 | |
| kept=0 | |
| for FULL in "${dirs[@]}"; do | |
| if [ -n "$CURRENT" ] && [ "$FULL" = "$CURRENT" ]; then | |
| continue | |
| fi | |
| kept=$((kept+1)) | |
| if [ "$kept" -gt "$KEEP" ]; then | |
| echo "Deleting $FULL" | |
| rm -rf -- "$FULL" | |
| fi | |
| done | |
| EOF | |