-
Notifications
You must be signed in to change notification settings - Fork 92
185 lines (174 loc) · 6.89 KB
/
deploy.yaml
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
name: Publish docs via GitHub Pages
env:
ACTIONTEST: 3.5.0
# branch name, like master, 2.4
on:
push:
branches: # hard code branch name
- v3.5.0
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1 # Not fetch all commits/branches
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
- name : prepare
run: pip install -r requirements.txt
- name: Set matrix
id: set-matrix
run: |
import yaml, os, json
with open('./database_edition.yml', 'r') as file:
mkdocs = yaml.safe_load(file)
database_edition = mkdocs.get('database_edition', '')
print(f"database_edition: {database_edition}") # Print the variable for debugging
matrix = []
if database_edition == 'both':
matrix = ['enterprise', 'community']
elif database_edition in ['enterprise', 'community']:
matrix = [database_edition]
matrix_str = json.dumps(matrix) # Convert the list to a JSON-formatted string
with open(os.environ['GITHUB_OUTPUT'], 'a') as file:
file.write(f"matrix={matrix_str}\n")
shell: python
deploy:
needs: prepare
runs-on: ubuntu-latest
strategy:
max-parallel: 1 # in case push conflict
matrix:
database_edition: ${{fromJson(needs.prepare.outputs.matrix)}}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1 # fetch all commits/branches
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
- name : prepare
run: sh ./prepare.sh
# if 'both', set each file 'community' and 'enterprise' separately.
- name: Update database_edition.yml
run: |
import yaml
with open('./database_edition.yml', 'r') as file:
content = yaml.safe_load(file)
content['database_edition'] = f"${{ matrix.database_edition }}"
with open('./database_edition.yml', 'w') as file:
yaml.dump(content, file)
shell: python
- name: Git Config
run: git config user.name whitewum && git config user.email min.wu@vesoft.com
- name: save tmp files
run: |
cp -f *versions.json /tmp/ # f"${{ matrix.database_edition }}"_versions.json
ls /tmp/ -ltr
- name: mike
run: |
python ./scripts/conditional_render.py
python ./scripts/conditional_yml.py
python ./scripts/conditional_pdf.py
git fetch origin gh-pages --depth=1 # fix mike's CI update
mike deploy ${{ env.ACTIONTEST }} -p --rebase
mike list
- name: show git branch
run: |
git branch
git checkout .
git checkout gh-pages
- name: replace version.json
run: |
import yaml, json
new_content = {"version": "${{ env.ACTIONTEST }}", "title": "${{ env.ACTIONTEST }}", "aliases": []}
# the only place read from /tmp/
filename = "/tmp/" + f"${{ matrix.database_edition }}" + "_versions.json"
with open(filename, 'r') as infile:
json_data = json.load(infile)
found = False
for item in json_data:
if item['version'] == new_content['version']: # in case duplicate master branch
found = True
break
if not found:
json_data.append(new_content)
json_data = sorted(json_data, key=lambda x: x['version'], reverse=True)
with open('./versions.json', 'w') as outfile:
json.dump(json_data, outfile, indent=2)
shell: python
- name: Compress
run: |
if [ "${{ matrix.database_edition }}" = "enterprise" ]; then
tar -vczf ent-docs.tar.gz ${{ env.ACTIONTEST }} versions.json *.html
else
tar -vczf nebula-docs.tar.gz ${{ env.ACTIONTEST }} versions.json *.html
fi
- name: Set source file
id: set-source-file
run: |
if [ "${{ matrix.database_edition }}" = "enterprise" ]; then
echo "source_file=ent-docs.tar.gz" >> $GITHUB_OUTPUT
else
echo "source_file=nebula-docs.tar.gz" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Transfer
# uses: garygrossgarten/github-action-scp@release
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER_NAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
source: ${{ steps.set-source-file.outputs.source_file }}
target: /usr/web
- name: UnCompress
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER_NAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script: |
if [ "${{ matrix.database_edition }}" = "enterprise" ]; then
mkdir -p /usr/web/ent-docs/
tar -xzf /usr/web/ent-docs.tar.gz -C /usr/web/ent-docs/
mkdir -p /usr/web/ent-docs/site/pdf/
#cp -f /usr/web/ent-docs/${{ env.ACTIONTEST }}/pdf/yueshu-cn.pdf /usr/web/ent-docs/site/pdf/NebulaGraph-book.pdf
else
mkdir -p /usr/web/nebula-docs/
tar -xzf /usr/web/nebula-docs.tar.gz -C /usr/web/nebula-docs/
mkdir -p /usr/web/nebula-docs/site/pdf/
#cp -f /usr/web/nebula-docs/${{ env.ACTIONTEST }}/pdf/NebulaGraph-CN.pdf /usr/web/nebula-docs/site/pdf/NebulaGraph-book.pdf
fi
- name: Set OSS parameters
id: set-oss-params
run: |
if [ "${{ matrix.database_edition }}" = "enterprise" ]; then
echo "bucket=yueshu-graph" >> $GITHUB_OUTPUT
echo "asset_path=${{ env.ACTIONTEST }}/pdf/yueshu-cn.pdf" >> $GITHUB_OUTPUT
echo "target_path=general/yueshu-doc/${{ env.ACTIONTEST }}" >> $GITHUB_OUTPUT
else
echo "bucket=docs-cn" >> $GITHUB_OUTPUT
echo "asset_path=${{ env.ACTIONTEST }}/pdf/NebulaGraph-CN.pdf" >> $GITHUB_OUTPUT
echo "target_path=pdf/${{ env.ACTIONTEST }}" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Upload to OSS
uses: vesoft-inc/upload-oss@master
with:
key-id: ${{ secrets.OSS_ID }}
key-secret: ${{ secrets.OSS_SECRET }}
endpoint: ${{ secrets.OSS_ENDPOINT }}
bucket: ${{ steps.set-oss-params.outputs.bucket }}
asset-path: ${{ steps.set-oss-params.outputs.asset_path }}
target-path: ${{ steps.set-oss-params.outputs.target_path }}