-
Notifications
You must be signed in to change notification settings - Fork 19
167 lines (150 loc) · 5.4 KB
/
update.yml
File metadata and controls
167 lines (150 loc) · 5.4 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
name: Update docs.pingcap.com
on:
workflow_dispatch:
inputs:
repo:
description: "Source Repo"
required: true
type: choice
options:
- pingcap/docs
- pingcap/docs-cn
- pingcap/docs-dm
- pingcap/docs-tidb-operator
branch:
description: "Source branch"
type: string
required: true
full:
description: "Full update"
type: boolean
default: false
required: false
env:
EN_CLOUD_BRANCH: release-8.5
JA_CLOUD_BRANCH: i18n-ja-release-8.5
ZH_CLOUD_BRANCH: i18n-zh-release-8.5
concurrency: ${{ github.workflow }}-${{ inputs.repo }}-${{ inputs.branch }}
jobs:
build:
concurrency: update-${{ inputs.repo }}-${{ inputs.branch }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: "yarn"
- run: yarn
- name: Init git info
run: |
git status
git config user.name github-actions
git config user.email github-actions@github.com
- name: Update target folder by event input
if: ${{ !inputs.full }}
env:
GITHUB_AUTHORIZATION_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
# handle zh auto translated docs branch(only cloud)
if [ ${{ inputs.repo }} = "pingcap/docs" ] && [ ${{ inputs.branch }} = ${{ env.ZH_CLOUD_BRANCH }} ]
then
yarn download:tidb-cloud:zh --ref ${{ inputs.branch }}
exit 0
fi
# handle ja auto translated docs branch(tidb and cloud)
if [ ${{ inputs.repo }} = "pingcap/docs" ] && [ ${{ inputs.branch }} = ${{ env.JA_CLOUD_BRANCH }} ]
then
yarn download:tidb-cloud:ja --ref ${{ inputs.branch }}
yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }}
exit 0
fi
# handle tidb-cloud doc based on specified en doc branch
if [ ${{ inputs.repo }} = "pingcap/docs" ] && [ ${{ inputs.branch }} = ${{ env.EN_CLOUD_BRANCH }} ]
then
yarn download:tidb-cloud:en --ref ${{ inputs.branch }}
yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }}
exit 0
fi
# docs-dm and docs-tidb-operator need specify language
if [ ${{ inputs.repo }} = "pingcap/docs-dm" ] || [ ${{ inputs.repo }} = "pingcap/docs-tidb-operator" ]
then
yarn download ${{ inputs.repo }} en --ref ${{ inputs.branch }}
yarn download ${{ inputs.repo }} zh --ref ${{ inputs.branch }}
exit 0
fi
yarn download ${{ inputs.repo }} --ref ${{ inputs.branch }}
- name: Update all folder
if: ${{ inputs.full }}
env:
GITHUB_AUTHORIZATION_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
sudo rm -fr ./markdown-pages/*
yarn download:tidb:en:all
yarn download:tidb-cloud:en
yarn download:tidb:zh:all
yarn download:tidb:ja:all
yarn download:tidb-cloud:ja
yarn download:tidb-cloud:zh
yarn download:dm:all
yarn download:tidb-operator:all
- name: Sync tooltip terms
if: ${{ inputs.repo == 'pingcap/docs' && inputs.branch == 'master' }}
env:
GITHUB_AUTHORIZATION_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
TEMP_FILE=$(mktemp)
if curl \
--fail \
--silent \
--show-error \
--location \
--output "${TEMP_FILE}" \
-H "Accept: application/vnd.github.raw+json" \
-H "Authorization: token ${GITHUB_AUTHORIZATION_TOKEN}" \
"https://api.github.com/repos/${{ inputs.repo }}/contents/tooltip-terms.json?ref=${{ inputs.branch }}"
then
mv "${TEMP_FILE}" ./tooltip-terms.json
else
rm -f "${TEMP_FILE}"
echo "Skip syncing tooltip-terms.json because it does not exist on ${{ inputs.repo }}@${{ inputs.branch }}."
fi
- name: Git commit
run: |
git add markdown-pages
git add tooltip-terms.json 2>/dev/null || true
git fetch
git pull
if [[ -z $(git status -s) ]]
then
git status
else
git commit -m "update MD by dispatch event ${{ inputs.repo }} ${{ inputs.branch }}"
fi
- name: Git push
uses: nick-fields/retry@v2
with:
timeout_minutes: 3
max_attempts: 3
retry_on: error
command: |
git pull --rebase
git push
- name: Trigger preview
run: |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
https://api.github.com/repos/pingcap/docs-staging/actions/workflows/preview.yml/dispatches \
-d '{"ref":"main","inputs":{}}'
- name: Trigger website-docs
run: |
export CURRENT_SHA=$(git rev-parse HEAD)
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
https://api.github.com/repos/pingcap/website-docs/actions/workflows/production.yml/dispatches \
-d '{"ref":"master","inputs":{"hash": "$CURRENT_SHA", "fallback": "false"}}'