Path: blob/main/tools/maint/update_website.py
14365 views
#!/usr/bin/env python31# Copyright 2021 The Emscripten Authors. All rights reserved.2# Emscripten is available under two separate licenses, the MIT license and the3# University of Illinois/NCSA Open Source License. Both these licenses can be4# found in the LICENSE file.56"""Build and publish the emscripten website.78This script builds the emscripten website from source and creates a9new commit & branch in the emscripten-site repository containing any10changes.11"""1213import os14import subprocess15import sys1617script_dir = os.path.dirname(os.path.abspath(__file__))18root_dir = os.path.dirname(os.path.dirname(script_dir))19site_dir = os.path.join(root_dir, 'site')2021message_template = '''\22Automatic update of the emscripten website2324This is an automated change generated by `tools/maint/update_website.py` in the emscripten repo.2526The change was generated at git revision https://github.com/emscripten-core/emscripten/commit/%s27'''282930def is_git_clean(dirname):31return not subprocess.check_output(['git', 'status', '-uno', '--porcelain'], text=True, cwd=dirname).strip()323334def get_changed_files(dirname):35files_changed = subprocess.check_output(['git', 'status', '-uno', '--porcelain'], text=True, cwd=dirname).splitlines()36return [line[3:].strip() for line in files_changed]373839def main(args):40if args:41site_out = args[0]42else:43site_out = os.path.join(root_dir, 'site', 'emscripten-site')4445assert os.path.isdir(site_out)46print(f'Updating docs in: {site_out}')47if not is_git_clean(site_out):48print(f'{site_out}: tree is not clean')49return 150if not is_git_clean(root_dir):51print(f'{root_dir}: tree is not clean')52return 15354# Ensure the -site checkout is up-to-date55subprocess.check_call(['git', 'fetch', 'origin'], cwd=site_out)56subprocess.check_call(['git', 'checkout', 'origin/gh-pages'], cwd=site_out)5758# Build and install the docs59subprocess.check_call(['make', 'install', f'EMSCRIPTEN_SITE={site_out}'], cwd=site_dir)6061files_changed = get_changed_files(site_out)62if not files_changed:63print('docs are up-to-date; no changes found')64return 06566# Create a new branch and commit the changes.67subprocess.check_call(['git', 'checkout', '-b', 'update'], cwd=site_out)68subprocess.check_call(['git', 'add', '.'], cwd=site_out)69hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], text=True, cwd=root_dir).strip()70message = message_template % hash71subprocess.run(['git', 'commit', '-F', '-'], input=message, text=True, cwd=site_out)72return 2737475if __name__ == '__main__':76sys.exit(main(sys.argv[1:]))777879