forked from pingcap/website-docs
-
Notifications
You must be signed in to change notification settings - Fork 2
205 lines (174 loc) · 8.2 KB
/
update.yml
File metadata and controls
205 lines (174 loc) · 8.2 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: Incremental build website docs triggered by push events
on: repository_dispatch
jobs:
build:
name: Retrieve docs and deploy the website
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# if there's a action without sha1, it will write a cahce
# in linux-gatsby-cache-2- and will be used everytime latter action being dispatched
- name: Bailout
if: ${{ !github.event.client_payload.sha }}
run: exit 1
# https://github.com/gatsbyjs/gatsby/issues/11406
- name: Increase file watchers
if: ${{ !env.ACT }}
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
# make sure there is only one workflow running
- name: Turnstyle
if: ${{ !env.ACT }}
uses: softprops/turnstyle@v1
- name: Set known_hosts
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' }}
id: known-hosts
run: |
echo "::set-output name=HK::$(ssh-keyscan -H ${{ secrets.HK_HOST }})"
- name: Install SSH Key
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' }}
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: |
${{ steps.known-hosts.outputs.HK }}
- uses: actions/setup-node@v4
if: ${{ !env.ACT }}
with:
node-version: '16'
cache: 'yarn'
- name: Install yarn (ACT)
# Since actions/setup-node currently errors out when run locally, here is a manual installation
if: ${{ env.ACT }}
run: |
echo "node version:"
node -v
echo "npm version:"
npm -v
npm install -g yarn
- name: Install deps
run: yarn
# - name: Restore docs
# uses: actions/cache@v2
# id: docs-cache
# with:
# path: markdown-pages
# key: ${{ runner.os }}-docs-cache-4-${{ github.event.client_payload.sha }} # You can inc the version number to force cache rebuild
# restore-keys: |
# ${{ runner.os }}-docs-cache-4-
# if download_type is full, download all docs
- name: Download all docs
# if: github.event.client_payload.download_type == 'full'
env:
GITHUB_AUTHORIZATION_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
yarn run download:ee:zh:all
- name: Download specific docs
if: github.event.client_payload.download_type == 'partial'
env:
GITHUB_AUTHORIZATION_TOKEN: ${{ secrets.GH_TOKEN }}
run: eval "${{ github.event.client_payload.command }}"
# incremental: get the base commit from cache for furthur use
- name: Get base commit cache
if: github.event.client_payload.download_type != 'full'
id: cache-commit
run: |
REPO=$(cut -d"/" -f2 <<< "${{ github.event.client_payload.repo }}")
HASH=${{ github.workspace }}/markdown-pages/$REPO-${{ github.event.client_payload.ref }}.hash
BASE=""
if [ -f "$HASH" ]; then
BASE=$(cat $HASH)
fi
echo "get base hash: $BASE"
echo "::set-output name=path::$HASH"
echo "::set-output name=base::$BASE"
# incremental: download changed files
- name: Sync docs
if: steps.cache-commit.outputs.base != ''
env:
GITHUB_AUTHORIZATION_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
ACT=${{ env.ACT }}
[[ "${ACT:-false}" = "true" ]] && dryRun="true" || dryRun="false"
yarn sync ${{ github.event.client_payload.repo }} --ref ${{ github.event.client_payload.ref }} ${{ steps.cache-commit.outputs.base }} ${{ github.event.client_payload.sha }} --dry-run $dryRun
# - name: Restore gatsby cache
# uses: actions/cache@v2
# id: gatsby-cache
# with:
# path: |
# .cache
# public
# key: ${{ runner.os }}-gatsby-cache-3-${{ github.event.client_payload.sha }} # You can inc the version number to force cache rebuild
# restore-keys: |
# ${{ runner.os }}-gatsby-cache-3-
# - name: Build website
# env:
# CI: true
# GATSBY_ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
# GATSBY_ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
# run: |
# yarn build --verbose
# mv public/sitemap/sitemap-0.xml public/sitemap.xml
# ---- STAGING ONLY --
- name: Put everything to HK-staging
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'staging' }}
run: |
rsync -avz --delete -e 'ssh -o StrictHostKeyChecking=no' ./ "root@${{ secrets.HK_HOST }}:/root/website-docs/"
- name: Mod scripts on HK-staging
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'staging' }}
run: |
ssh -o "StrictHostKeyChecking no" root@${{ secrets.HK_HOST }} "chmod a+x /root/website-docs/*.sh"
- name: Restart Service on HK-staging
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'staging' }}
run: |
ssh -o "StrictHostKeyChecking no" root@${{ secrets.HK_HOST }} "service website-docs restart"
- name: Print Service Status on HK-staging
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'staging' }}
run: |
ssh -o "StrictHostKeyChecking no" root@${{ secrets.HK_HOST }} "service website-docs status"
# ---- PRODUCTION ONLY --
- name: Build website in prod
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'prod' }}
run: |
yarn build --verbose
yarn cache clean --all
- name: Put everything to HK-prod
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'prod' }}
run: |
rsync -avz --delete -e 'ssh -o StrictHostKeyChecking=no' ./ "root@${{ secrets.HK_HOST }}:/root/website-docs-prod/"
- name: Mod scripts on HK-prod
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'prod' }}
run: |
ssh -o "StrictHostKeyChecking no" root@${{ secrets.HK_HOST }} "chmod a+x /root/website-docs-prod/*.sh"
- name: Restart Service on HK-prod
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'prod' }}
run: |
ssh -o "StrictHostKeyChecking no" root@${{ secrets.HK_HOST }} "service website-docs-prod restart"
- name: Print Service Status on HK-prod
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'prod' }}
run: |
ssh -o "StrictHostKeyChecking no" root@${{ secrets.HK_HOST }} "service website-docs-prod status"
- name: Update current commit sha to cache
if: github.event.client_payload.download_type != 'full'
run: |
echo ${{ github.event.client_payload.sha }} > ${{ steps.cache-commit.outputs.path }}
# if does full building, store latest commit sha of all docs repo
- name: Update all commit hashes
if: github.event.client_payload.download_type == 'full'
run: |
bash ./scripts/get-latest-commits.sh ${{ secrets.GH_TOKEN }}
notify-feishu-on-failure:
name: Notify Feishu on Failure
runs-on: ubuntu-latest
needs: build
if: failure()
steps:
- name: Send notification to Feishu on failure
run: |
curl -X POST ${{ secrets.FEISHU_CI_BOT_WEBHOOK_URL }} \
-H 'Content-Type: application/json' \
-d '{
"msg_type": "text",
"content": {
"text": "🚨 GitHub Action 失败通知:官网文档部署失败!\n- 仓库: ${{ github.repository }}\n- 分支: ${{ github.ref }}\n- 工作流: ${{ github.workflow }}\n- 触发人: ${{ github.actor }}\n- 查看日志: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
}'