-
Notifications
You must be signed in to change notification settings - Fork 11
168 lines (134 loc) · 5.15 KB
/
Copy pathdeploy.yml
File metadata and controls
168 lines (134 loc) · 5.15 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Deploy X
on:
push:
branches:
- main
concurrency:
group: deploy-x-main
# Never cancel a deploy mid-flight: the switch step below empties the live
# `index` dir before moving the new build in, so a cancelled run can leave
# the server serving nothing.
cancel-in-progress: false
permissions:
contents: read
jobs:
build:
if: github.repository == 'antdv-next/x'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v7
# Same toolchain as CI, so a green PR exercises the exact path used here.
- name: Setup Vite+
uses: voidzero-dev/setup-vp@v1
with:
cache: true
- name: Install dependencies
run: vp install --frozen-lockfile
- name: Build site
run: |
vp run docs:build
rm -rf dist
cp -r packages/docs/dist dist
- name: Upload site artifact
uses: actions/upload-artifact@v7
with:
name: site-dist
path: dist
deploy:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
actions: read
steps:
- name: Download site artifact
uses: actions/download-artifact@v8
with:
name: site-dist
path: dist
- name: Inspect downloaded site artifact
run: ls -R dist
# Third-party actions that receive deploy credentials are pinned to a
# commit SHA — a mutable tag would let an upstream compromise read them.
- name: Scp dir to server
uses: appleboy/scp-action@ff85246acaad7bdce478db94a363cd2bf7c90345 # v1
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USERNAME }}
password: ${{ secrets.DEPLOY_PASSWORD }}
port: ${{ secrets.DEPLOY_PORT }}
source: dist
target: ${{ secrets.DEPLOY_TARGET_PATH }}
- name: Switch current site
uses: appleboy/ssh-action@0ff4204d59e8e51228ff73bce53f80d53301dee2 # v1
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USERNAME }}
password: ${{ secrets.DEPLOY_PASSWORD }}
port: ${{ secrets.DEPLOY_PORT }}
script: |
set -eu
TARGET="${{ secrets.DEPLOY_TARGET_PATH }}"
mkdir -p "$TARGET/index" "$TARGET/index.bak"
if [ -d "$TARGET/index" ] && [ -n "$(find "$TARGET/index" -mindepth 1 -maxdepth 1 2>/dev/null)" ]; then
find "$TARGET/index.bak" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
find "$TARGET/index" -mindepth 1 -maxdepth 1 -exec mv {} "$TARGET/index.bak"/ \;
fi
if [ ! -d "$TARGET/dist" ] || [ -z "$(find "$TARGET/dist" -mindepth 1 -maxdepth 1 2>/dev/null)" ]; then
echo "No dist files uploaded; abort."
exit 1
fi
find "$TARGET/index" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
find "$TARGET/dist" -mindepth 1 -maxdepth 1 -exec mv {} "$TARGET/index"/ \;
- name: Deployment completed
run: echo "Deployment to server completed successfully."
deploy-cn:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
actions: read
steps:
- name: Download site artifact
uses: actions/download-artifact@v8
with:
name: site-dist
path: dist
- name: Inspect downloaded site artifact
run: ls -R dist
- name: Scp dir to CN server
uses: appleboy/scp-action@ff85246acaad7bdce478db94a363cd2bf7c90345 # v1
with:
host: ${{ secrets.DEPLOY_HOST_CN }}
username: ${{ secrets.DEPLOY_USERNAME_CN }}
password: ${{ secrets.DEPLOY_PASSWORD_CN }}
port: ${{ secrets.DEPLOY_PORT_CN }}
source: dist
target: ${{ secrets.DEPLOY_TARGET_PATH_CN }}
- name: Switch current site on CN server
uses: appleboy/ssh-action@0ff4204d59e8e51228ff73bce53f80d53301dee2 # v1
with:
host: ${{ secrets.DEPLOY_HOST_CN }}
username: ${{ secrets.DEPLOY_USERNAME_CN }}
password: ${{ secrets.DEPLOY_PASSWORD_CN }}
port: ${{ secrets.DEPLOY_PORT_CN }}
script: |
set -eu
TARGET="${{ secrets.DEPLOY_TARGET_PATH_CN }}"
mkdir -p "$TARGET/index" "$TARGET/index.bak"
if [ -d "$TARGET/index" ] && [ -n "$(find "$TARGET/index" -mindepth 1 -maxdepth 1 2>/dev/null)" ]; then
find "$TARGET/index.bak" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
find "$TARGET/index" -mindepth 1 -maxdepth 1 -exec mv {} "$TARGET/index.bak"/ \;
fi
if [ ! -d "$TARGET/dist" ] || [ -z "$(find "$TARGET/dist" -mindepth 1 -maxdepth 1 2>/dev/null)" ]; then
echo "No dist files uploaded; abort."
exit 1
fi
find "$TARGET/index" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
find "$TARGET/dist" -mindepth 1 -maxdepth 1 -exec mv {} "$TARGET/index"/ \;
- name: Deployment completed on CN server
run: echo "Deployment to CN server completed successfully."