Skip to content

Commit 4154c81

Browse files
committed
fix: test deploy
1 parent 6ce0ba0 commit 4154c81

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Deploy to self-hosted server
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: deploy-production
13+
cancel-in-progress: false
14+
15+
jobs:
16+
deploy:
17+
runs-on: ubuntu-latest
18+
environment: production
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- uses: actions/setup-node@v4
24+
with:
25+
node-version: 20
26+
cache: npm
27+
28+
- run: npm ci
29+
- run: npm run build
30+
31+
- name: Prepare SSH
32+
shell: bash
33+
run: |
34+
set -euo pipefail
35+
install -m 700 -d ~/.ssh
36+
printf '%s' "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/id_ed25519
37+
chmod 600 ~/.ssh/id_ed25519
38+
printf '%s' "${{ secrets.DEPLOY_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
39+
40+
- name: Upload and switch release
41+
shell: bash
42+
run: |
43+
set -euo pipefail
44+
release="${{ secrets.DEPLOY_PATH }}/releases/${GITHUB_SHA}"
45+
46+
rsync -az --delete \
47+
-e "ssh -i ~/.ssh/id_ed25519 -o BatchMode=yes -o StrictHostKeyChecking=yes" \
48+
dist/ \
49+
"${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${release}/"
50+
51+
ssh -i ~/.ssh/id_ed25519 -o BatchMode=yes -o StrictHostKeyChecking=yes \
52+
"${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \
53+
"ln -sfn '${release}' '${{ secrets.DEPLOY_PATH }}/current' && ls -dt '${{ secrets.DEPLOY_PATH }}/releases/'* | tail -n +6 | xargs -r rm -rf"

0 commit comments

Comments
 (0)