-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: auto releasing doc version (#2586)
Add doc_version parameter in mkdocs.yml and a script to use the parameter. When releasing a new doc version, you only need to modify the `database_edition` and `doc_version` parameters, and update the macro values.
- Loading branch information
1 parent
75dda86
commit 1e5b0cc
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import re | ||
|
||
def replace_line(file_path, search_text, new_line): | ||
with open(file_path, 'r', encoding='utf-8') as f: | ||
file_content = f.read() | ||
new_content = re.sub(search_text, new_line, file_content) | ||
|
||
with open(file_path, 'w', encoding='utf-8') as f: | ||
f.write(new_content) | ||
|
||
def update_github_actions(doc_version): | ||
if doc_version == 'master': | ||
replace_line('.github/workflows/deploy.yaml', r'branches:\s+-.*', f'branches:\n - {doc_version}') | ||
replace_line('.github/workflows/deploy.yaml', r'mike deploy .* -p --rebase\n mike set-default .* -p --rebase', f'mike deploy {doc_version} -p --rebase') | ||
replace_line('.github/workflows/deploy.yaml', r'tar -vczf nebula-docs.tar.gz.*', f'tar -vczf nebula-docs.tar.gz {doc_version} versions.json *.html') | ||
replace_line('.github/workflows/deploy.yaml', r'cp -f /usr/web/nebula-docs/.*/pdf/NebulaGraph-CN.pdf', f'cp -f /usr/web/nebula-docs/{doc_version}/pdf/NebulaGraph-CN.pdf') | ||
else: | ||
replace_line('.github/workflows/deploy.yaml', r'branches:\s+-.*', f'branches:\n - v{doc_version}') | ||
replace_line('.github/workflows/deploy.yaml', r'mike deploy .* -p --rebase', f'mike deploy {doc_version} -p --rebase\n mike set-default {doc_version} -p --rebase') | ||
replace_line('.github/workflows/deploy.yaml', r'tar -vczf nebula-docs.tar.gz.*', f'tar -vczf nebula-docs.tar.gz {doc_version} versions.json *.html') | ||
replace_line('.github/workflows/deploy.yaml', r'cp -f /usr/web/nebula-docs/.*/pdf/NebulaGraph-CN.pdf', f'cp -f /usr/web/nebula-docs/{doc_version}/pdf/NebulaGraph-CN.pdf') | ||
|
||
def update_mkdocs_yml(doc_version): | ||
if doc_version == 'master': | ||
replace_line('./mkdocs.yml', r'cover_subtitle:.*', f'cover_subtitle: {doc_version}') | ||
replace_line('./mkdocs.yml', r'https://github.com/vesoft-inc/nebula-docs-cn/edit/.*/docs-2.0/', f'https://github.com/vesoft-inc/nebula-docs-cn/edit/{doc_version}/docs-2.0/') | ||
else: | ||
replace_line('./mkdocs.yml', r'cover_subtitle:.*', f'cover_subtitle: v{doc_version}') | ||
replace_line('./mkdocs.yml', r'https://github.com/vesoft-inc/nebula-docs-cn/edit/.*/docs-2.0/', f'https://github.com/vesoft-inc/nebula-docs-cn/edit/v{doc_version}/docs-2.0/') | ||
|
||
if __name__ == "__main__": | ||
with open('./mkdocs.yml', 'r', encoding='utf-8') as f: | ||
file_content = f.read() | ||
doc_version_match = re.search(r'doc_version:.*', file_content) | ||
if doc_version_match: | ||
doc_version = doc_version_match.group().split(':')[1].strip() | ||
if not isinstance(doc_version, str): | ||
raise TypeError("The value of doc_version should be a string") | ||
else: | ||
raise Exception("The value of doc_version is not found in mkdocs.yml") | ||
update_github_actions(doc_version) | ||
update_mkdocs_yml(doc_version) |