Skip to content

Commit a3c63f8

Browse files
authored
Create build-and-deploy.yml
1 parent 15a4d70 commit a3c63f8

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Deploy downpatch.com
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
workflow_dispatch: {}
7+
8+
concurrency:
9+
group: downpatch-deploy
10+
cancel-in-progress: true
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Setup .NET
20+
uses: actions/setup-dotnet@v4
21+
with:
22+
dotnet-version: "10.0.x"
23+
24+
- name: Restore
25+
run: dotnet restore ./downpatch.csproj
26+
27+
- name: Publish
28+
run: dotnet publish ./downpatch.csproj -c Release -o ./out --no-restore
29+
30+
- name: Configure SSH
31+
shell: bash
32+
run: |
33+
set -euo pipefail
34+
mkdir -p ~/.ssh
35+
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
36+
chmod 600 ~/.ssh/id_ed25519
37+
ssh-keyscan -p "${{ secrets.SSH_PORT }}" "${{ secrets.SSH_HOST }}" >> ~/.ssh/known_hosts
38+
39+
- name: Upload release via rsync
40+
shell: bash
41+
run: |
42+
set -euo pipefail
43+
RELEASE="${{ github.sha }}"
44+
rsync -az --delete \
45+
-e "ssh -p ${{ secrets.SSH_PORT }} -i ~/.ssh/id_ed25519" \
46+
./out/ "${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/var/www/downpatch/releases/${RELEASE}/"
47+
48+
- name: Activate release + restart service
49+
shell: bash
50+
run: |
51+
set -euo pipefail
52+
RELEASE="${{ github.sha }}"
53+
ssh -p "${{ secrets.SSH_PORT }}" -i ~/.ssh/id_ed25519 "${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}" bash -lc " \
54+
set -euo pipefail; \
55+
ln -sfn /var/www/downpatch/releases/${RELEASE} /var/www/downpatch/current; \
56+
sudo /bin/systemctl restart downpatch.service; \
57+
sudo /bin/systemctl status downpatch.service --no-pager \
58+
"

0 commit comments

Comments
 (0)