Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/maint/update_docs.py
6165 views
1
#!/usr/bin/env python3
2
# Copyright 2021 The Emscripten Authors. All rights reserved.
3
# Emscripten is available under two separate licenses, the MIT license and the
4
# University of Illinois/NCSA Open Source License. Both these licenses can be
5
# found in the LICENSE file.
6
7
"""Builds the emscripten website from source and creates a new commit & branch
8
in the emscripten-site repository containing the changes."""
9
10
import os
11
import subprocess
12
import sys
13
14
script_dir = os.path.dirname(os.path.abspath(__file__))
15
root_dir = os.path.dirname(os.path.dirname(script_dir))
16
site_dir = os.path.join(root_dir, 'site')
17
18
message_template = '''\
19
Automatic update of the emscripten website
20
21
This is an automated change generated by `tools/maint/update_docs.py` in the emscripten repo.
22
23
The change was generated at git revision https://github.com/emscripten-core/emscripten/commit/%s
24
'''
25
26
27
def is_git_clean(dirname):
28
return subprocess.check_output(['git', 'status', '-uno', '--porcelain'], text=True, cwd=dirname).strip() == ''
29
30
31
def get_changed_files(dirname):
32
files_changed = subprocess.check_output(['git', 'status', '-uno', '--porcelain'], text=True, cwd=dirname).splitlines()
33
return [line[3:].strip() for line in files_changed]
34
35
36
def main(args):
37
if args:
38
site_out = args[0]
39
else:
40
site_out = os.path.join(root_dir, 'site', 'emscripten-site')
41
42
assert os.path.isdir(site_out)
43
print(f'Updating docs in: {site_out}')
44
if not is_git_clean(site_out):
45
print(f'{site_out}: tree is not clean')
46
return 1
47
if not is_git_clean(root_dir):
48
print(f'{root_dir}: tree is not clean')
49
return 1
50
51
# Ensure the -site checkout is up-to-date
52
subprocess.check_call(['git', 'fetch', 'origin'], cwd=site_out)
53
subprocess.check_call(['git', 'checkout', 'origin/gh-pages'], cwd=site_out)
54
55
# Build and install the docs
56
subprocess.check_call(['make', 'install', f'EMSCRIPTEN_SITE={site_out}'], cwd=site_dir)
57
58
files_changed = get_changed_files(site_out)
59
if not files_changed:
60
print('docs are up-to-date; no changes found')
61
return 0
62
63
# Create a new branch and commit the changes.
64
subprocess.check_call(['git', 'checkout', '-b', 'update'], cwd=site_out)
65
subprocess.check_call(['git', 'add', '.'], cwd=site_out)
66
hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], text=True, cwd=root_dir).strip()
67
message = message_template % hash
68
subprocess.run(['git', 'commit', '-F', '-'], input=message, text=True, cwd=site_out)
69
return 2
70
71
72
if __name__ == '__main__':
73
sys.exit(main(sys.argv[1:]))
74
75