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