Repository navigation
111 lines (93 loc) · 3.31 KB
/
Copy pathdeploy.yml
File metadata and controls
111 lines (93 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Deploy
on:
push:
tags: ['colspan@*']
workflow_dispatch:
concurrency:
group: deploy-production
cancel-in-progress: false
permissions:
contents: read
env:
# The server restricts deploy-card to the app directory with rrsync, which
# resolves this path relative to that directory
APP_DIR: /
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4
with:
version: 10
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm build
env:
VITE_APP_BASE_PATH: /app/
- name: Настроить SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
echo "${{ secrets.DEPLOY_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
- name: Загрузить приложение
run: |
rsync -az --delete-after --delay-updates dist/ \
"${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:$APP_DIR/"
- name: Проверить деплой
run: |
for attempt in $(seq 1 5); do
if curl --fail --silent --show-error --location \
--connect-timeout 5 --max-time 20 \
--header 'Cache-Control: no-cache' \
"https://colspan.dev/app/?deploy=$GITHUB_SHA" \
--output /dev/null; then
assets_ok=true
while IFS= read -r asset; do
if ! curl --fail --silent --show-error --location \
--connect-timeout 5 --max-time 20 \
--header 'Cache-Control: no-cache' \
"https://colspan.dev${asset}?deploy=$GITHUB_SHA" \
--output /dev/null; then
assets_ok=false
break
fi
done < <(grep -oE '(src|href)="[^"]+"' dist/index.html \
| cut -d '"' -f 2)
if [ "$assets_ok" = true ]; then
echo "Приложение и его ресурсы доступны"
exit 0
fi
fi
echo "Попытка $attempt завершилась ошибкой"
sleep 2
done
echo "Приложение или его ресурсы недоступны после деплоя"
exit 1
release:
name: Create Draft Release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
needs: deploy
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Создать draft release
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh release view "$GITHUB_REF_NAME" \
--repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "Release $GITHUB_REF_NAME уже существует"
exit 0
fi
gh release create "$GITHUB_REF_NAME" \
--repo "$GITHUB_REPOSITORY" \
--title "$GITHUB_REF_NAME" \
--draft \
--generate-notes